1

The docs say:

:autocmd adds to the list of autocommands regardless of whether they are already present. When your .vimrc file is sourced twice, the autocommands will appear twice. To avoid this, define your autocommands in a group, so that you can easily clear them:

    augroup vimrc
      autocmd!      " Remove all vimrc autocommands
      au BufNewFile,BufRead *.html so <sfile>:h/html.vim
    augroup END

But when I put that in my .vimrc, I get an error when it's sourced:

E216: No such group or event: " Remove all vimrc autocommands

And it appears not to work. My autocommands run multiple times when I re-source .vimrc.

If I remove the comment, it seems fine. So is there a bug with autocmd! trying to parse comments? Or did I miss something?

3

You're correct that you cannot put a comment on the same line as that command, but it's not really a bug. That's just how VimScript works: you can't put a comment in a place where it will be parsed as an argument. (See :help :quote and the COMMENTS section of :help 41.10.)

On the other hand, it's not great that the documentation specifically recommends code that doesn't work, and also :help :quote states that "This is mentioned where the command is explained", which does not appear to be true in this case, so you could maybe raise those points as an issue with the Vim dev team.

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.