I've tried the following syntax:
:echo 123 " comment
but it failed with E15 and E114 errors.
Is there any way to put the inline comment right after the command, so it can be ignored?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityThe problem with this is, echo
is expecting an expression. You can read what an expression is at :h expression
in great detail. In short this means, :echo
expects either a variable or a string (which is either single quoted or double quoted).
Now look at your command, you are echoing the number 123 and start with a double-quoted string. However, "forgot" the closing quotation marks, so Vim is complaining.
A workaround is, to actually start an empty command, e.g. this works:
:echo 1234 | " put your comment here
from :h :echo
(note the last line):
:ec :echo
:ec[ho] {expr1} .. Echoes each {expr1}, with a space in between. The
first {expr1} starts on a new line.
Also see :comment.
Use "\n" to start a new line. Use "\r" to move the
cursor to the first column.
Uses the highlighting set by the :echohl command.
Cannot be followed by a comment.
Also potentially of interest, from :h comment
(note the last paragraph):
:quote :comment
'"' at the start of a line causes the whole line to be ignored. '"'
after a command causes the rest of the line to be ignored. This can be used
to add comments. Example:
:set ai "set 'autoindent' option
It is not possible to add a comment to a shell command ":!cmd" or to the
":map" command and a few others, because they see the '"' as part of their
argument. This is mentioned where the command is explained.