What is the syntax for inserting a comment or comments into the vimrc file?
Having trouble finding this on vim documentation online.
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 community
*: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.
The reason it's there is because
vimrc is nothing but a sequence of command-line commands. Pretty much everything that applies to command-line mode works in
Example of whole-line comment in
" show tab line always set showtabline=2
You can use
" at the start of the line:
" A comment set foo=bar
You can also do this after commands, to ignore the rest of the line:
set foo=bar " A comment
However, you need to be careful when adding comments after commands. In mappings and
:! commands it's downright impossible:
inoremap a b " Map a to b won't work. The "comment" is seen as part of the command. The same applies when running shell commands with
:!ls " a comment
In some other cases it may also cause unexpected behaviour. For example
normal! p " A comment will have the space between the
" inserted, and the comment part may also be evaluated if Vim guesses it as part of a command.
Another problem is adding comments in when running multiple commands, which is something I often do in autocommands. For example this won't work:
autocmd Filetype go \ echom "A message" \ " echo a message \| echom "A second message"
As far as I know, there is no sane way to get this to work :-/
There are probably other caveats; I chose to not remember them and only use
" at the start of a line :-)