Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting a new line below a comment in vim?

Tags:

vim

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.

like image 943
Brandon Mercer Avatar asked Oct 19 '13 02:10

Brandon Mercer


People also ask

How do I add a line under Vim?

Alt-j inserts a blank line below the current line. Alt-k inserts a blank line above the current line.

How do we make a new line under 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.

How do I comment multiple lines in vi?

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.


1 Answers

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.

like image 141
Ben Klein Avatar answered Sep 19 '22 05:09

Ben Klein