So, I started using NeoVim a little while ago and discovered a rather annoying quirk when using C++-style single-line comments //
in source code of any language.
Specifically, when you create a new line after a line which starts with //
, either by pressing enter in Insert Mode or by pressing o
in Normal Mode, the newly created line will also be pre-formatted to begin with //
So for
//A single line comment
creating a line after it will produce
//A single line comment
//
with the cursor beginning Insert Mode after the second //
So far as I can tell, this applies to all languages that support single-line comments. It's rather annoying since the whole point of a single-line comment is that they're, well, a single line. This is likely just some new default option in NeoVim or something to do with the syntax files NeoVim uses compared to OG Vim but, regardless, how do I disable this "feature" so that creating a new line after a single-line comment won't automatically be prefixed with an unwanted //
.
Essentially, when I press o
in Normal Mode or press enter in Insert Mode on the following line:
//A single line comment
I should end up with:
//A single line comment
autocmd! BufEnter * set fo-=r fo-=o
(Note the formatting is actually rather specific for using autocmd this way; omitting the exclamation mark or putting spaces before or after the-=
causes problems.)