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 this is happening, but I am unable to find an exact solution.
Alt-j inserts a blank line below the current line. Alt-k inserts a blank line above the current line.
If you want a new line at the top of the current line then press CTRL + SHIFT + ENTER. If you want a new line at the bottom of the current line then press CTRL+ ENTER.
vim-multiline-comment.md For commenting a block of text is almost the same: First, go to the first line you want to comment, press Ctrl``V , and select until the last line. Second, press Shift``I``#``Esc (then give it a second), and it will insert a # character on all selected lines.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With