Assuming I have defined 2 commands in .vimrc


I can run them in command-line mode:

:exec "'<,'>MultipleEmptyLinesToOne" | exec "'<,'>RemoveExcessiveSpaces"

However this method doesn't support auto-completion while typing the commands.

I know that I can create a new user-defined command that runs them in a sequence:

command! -range RemoveExcessiveSpaces2 exec "'<,'>MultipleEmptyLinesToOne" | exec "'<,'>RemoveExcessiveSpaces"

but it would be still great to know whether I can type (chain) any user-defined commands in command-line mode and have auto-completion at the same time.

  • 1
    What I would do here is to enter in Ex mode (with Q), type the first command, <ENTER>, then the second, <ENTER> again, and then get out with visual. That way, you'll have autocompletion for the 2 commands
    – Zorzi
    Apr 26, 2020 at 20:49
  • 3
    I'm not aware of a builtin to chain them with ranges, but using -bar will let you chain them with |
    – D. Ben Knoble
    Apr 26, 2020 at 20:52
  • 3
    Does this answer your question? Autocmd treat user defined command differently?. I believe the same solution should work in your case.
    – filbranden
    Apr 26, 2020 at 21:39
  • @Zorzi gQ is even nicer imo
    – D. Ben Knoble
    Apr 27, 2020 at 13:15
  • Another answer to this question unix.stackexchange.com/questions/144568/…
    – ka3ak
    May 9, 2020 at 16:24


Browse other questions tagged or ask your own question.