Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

:Tabularize with no args reuses the last pattern

The docs are updated to document this feature.  Calling :Tabularize with
arguments and no previous pattern prints an error message and does
nothing.  This works with both patterns and named commands.
Suggested by nocash - http://github.com/godlygeek/tabular/pull/2
commit b7b4d8791a50013b56c2d68b6c5708c808203b54 1 parent 4b543cd
@godlygeek authored
Showing with 23 additions and 8 deletions.
  1. +3 −1 doc/Tabular.txt
  2. +20 −7 plugin/Tabular.vim
View
4 doc/Tabular.txt
@@ -72,7 +72,9 @@ to be acted upon. You can always override this by specifying a range, though.
The second thing you should notice is that you'll almost certainly be able to
abbreviate :Tabularize to :Tab - using this form in mappings and scripts is
discouraged as it will make conflicts with other scripts more likely, but for
-interactive use it's a nice timesaver.
+interactive use it's a nice timesaver. Another convenience feature is that
+running :Tabularize without providing a new pattern will cause it to reuse the
+last pattern it was called with.
So, anyway, now the commas line up. Splitting the lines on commas, Tabular
realized that 'Some short phrase' would need to be padded with spaces to match
View
27 plugin/Tabular.vim
@@ -235,14 +235,27 @@ endfunction
"
" Align text, either using the given pattern, or the command associated with
" the given name.
-com! -nargs=+ -range -complete=customlist,<SID>CompleteTabularizeCommand
+com! -nargs=* -range -complete=customlist,<SID>CompleteTabularizeCommand
\ Tabularize <line1>,<line2>call Tabularize(<q-args>)
function! Tabularize(command) range
+ if empty(a:command)
+ if !exists("s:last_tabularize_command")
+ echohl ErrorMsg
+ echomsg "Tabularize hasn't been called yet; no pattern/command to reuse!"
+ echohl None
+ return
+ endif
+ else
+ let s:last_tabularize_command = a:command
+ endif
+
+ let command = s:last_tabularize_command
+
let range = a:firstline . ',' . a:lastline
try
- let [ pattern, format ] = s:ParsePattern(a:command)
+ let [ pattern, format ] = s:ParsePattern(command)
if !empty(pattern)
let cmd = "tabular#TabularizeStrings(a:lines, " . string(pattern)
@@ -255,12 +268,12 @@ function! Tabularize(command) range
exe range . 'call tabular#PipeRange(pattern, cmd)'
else
- if exists('b:TabularCommands') && has_key(b:TabularCommands, a:command)
- let command = b:TabularCommands[a:command]
- elseif has_key(s:TabularCommands, a:command)
- let command = s:TabularCommands[a:command]
+ if exists('b:TabularCommands') && has_key(b:TabularCommands, command)
+ let command = b:TabularCommands[command]
+ elseif has_key(s:TabularCommands, command)
+ let command = s:TabularCommands[command]
else
- throw "Unrecognized command " . string(a:command)
+ throw "Unrecognized command " . string(command)
endif
exe range . command
Please sign in to comment.
Something went wrong with that request. Please try again.