Does VIM support comments in command-line mode?

I have tried the most popular variants including .VIMRC comments but neither worked:

:echo "hello" // echo usage
:echo "hello" /* echo usage */
:echo "hello" "echo usage

Or do the comments in this mode just don't fit in the VIM paradigm?

Update: It seems there is a problem with the commands that end with ". Because all the others work, e.g. copying a buffer content:

:let @a=@0 " buffer copying

There must be some escaping. The suggested solution with |" seems to work for

:echo "hello" |" echo usage

but doesn't work for user-defined commands (those that are defined in .vimrc and whose names start with a capital letter) e.g.

:SearchHyphenation " user-defined
  • 1
    Try this: :echo "hello" |" echo usage.
    – user938271
    Jan 26, 2020 at 22:49
  • @user938271 Thank you. Seems to work. "echo" is the output and the part starting with |" is ignored. However it doesn't work with user-defined commands (those whose names should start with a capital letter)
    – ka3ak
    Jan 27, 2020 at 18:16
  • It works if the command was defined with the -bar attribute; otherwise with :exe: 0x0.st/irhy.txt
    – user938271
    Jan 27, 2020 at 18:42

1 Answer 1


Vimscript does have comments and they're started by the " character.

They always work at the beginning of the line:

" echo usage
echo "hello"

They sometimes work inline, but not always. It depends on the command.

See :help :comment, which says:

" after a command causes the rest of the line to be ignored. This can be used to add comments. [...]

It is not possible to add a comment to a shell command [...] and a few others (mainly commands that expect expressions) that see the " as part of their argument:

  • :argdo
  • :autocmd
  • [...]
  • :echo (and the like)
  • 1
    Ok. I see it now. It's not possible to append a comment to such a command.
    – ka3ak
    Jan 27, 2020 at 18:31

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.