While inserting a new line below a comment in vim, the result tends to insert a \"
at the start of the new line. It\'s probably a simple solution or reason why
If you’re editing a file of the vim
filetype, Vim might by default insert the comment character (in Vimscript, this would be "
) at the beginning of each new line you enter after a comment. As already mentioned, this is a result of Vim’s formatoptions
setting.
To turn this behavior off in the current file, run
:set formatoptions-=ro
To turn it off by default, add this to your ~/.vimrc
:
set formatoptions-=ro
To turn it off for Vimscript files, add this to your ~/.vimrc
:
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal formatoptions-=ro
augroup END
r
and o
are options which can be given to formatoptions
. For the full list of possible options, run :help fo-table
.
I think this should work, regardless of your formatoptions
settings.
inoremap <CR> <CR><C-U>
This behaviour is governed by the formatoptions variable.
Use :h formatoptions
to find out more.
The following article might also be helpful: Disable automatic comment insertion.
what command are you using to insert below?
If you use the standard "o" keystroke while in Navigation mode, it should insert a new line immediately below whatever the cursor is on, and automatically place you into Insert mode, without inserting an extra "
Similarly an uppercase "O" will insert a new line above whatever line the cursor is on, and place you in insert mode.