2

I want to select some lines in visual mode, and enter a custom command :Ex<CR> so that:

'<,'>!expand -t4

is run to expand all tabs in selected range. How to define the Ex command?

I have tried things like:

command! -range Ex !expand -t4

but that command just hangs, it seems that the range was not forwarded.

3

Ranges are not forwarded automatically, you need to use <line1> and <line2> for that:

command! -range Ex <line1>,<line2>!expand -t4

You should read the manuals of :help :command about -range and <line1>. Basically:

  • if Ex is called with a range, <line1> and <line2> expand to that range

  • otherwise, the default value of range is used. Without any default specified, <line1> and <line2> both expand to the current line.

    You could also use: -range=% to act on the entire file by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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