Is there a way to bind the sequence of commands

:Tabularize /\/\/
:Tabularize /;

in that order to the command :Command?

EDIT: I attempted the solution and it failed:

function! LineUp()
  normal :cabbrev Command Tabularize/\/\/<CR>:Tabularize /;<CR>

command! -nargs=0 -complete=buffer -range LineUp call LineUp()

The problem is that I can't get it to act on the visual selection.

2 Answers 2


Sure, try:

:cabbrev Command Tabularize/\/\/<CR>:Tabularize /;<CR>
  • I attempted to use this in a solution above but ran into a problem. Thanks for your answer. Jun 14, 2017 at 16:01
  • This also doesn't seem to work when ran without any selection on the whole file. Perhaps the <CR>'s aren't being registered as proper returns? Jun 14, 2017 at 18:00

You can use the following code:

function! CombinedTabularize() range
    execute a:firstline . ',' . a:lastline . 'Tabularize /\/\/'
    execute a:firstline . ',' . a:lastline . 'Tabularize /;'

command! -range CT <line1>,<line2>call CombinedTabularize()

The function CombinedTabularize() takes a range thanks to the range option. When using this option the lines in the range are available with a:firstline and a:lastline.

The command CT also takes a range and pass the selected lines to the function with <line1> and <line2>.

The execute commands are used to concatenate the lines of the range and the Tabularize calls.

About the code you tried to use here are the different problems:

  • Your command uses the range option but doesn't pass the lines to the function.
  • Your function doesn't use the range neither
  • Your function execute normal :cabbrev which creates a new command line abbreviation but doesn't execute it

You might be interested in the following help topics:

  • :h func-range
  • :h command-range

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.