Can I disable continuation of comments to the next line in Vim?

I think you're looking for

:set formatoptions-=cro

From :help fo-table:

You can use the 'formatoptions' option  to influence how Vim formats text.
'formatoptions' is a string that can contain any of the letters below.  The
default setting is "tcq".  You can separate the option letters with commas for
readability.

letter  meaning when present in 'formatoptions'

t       Auto-wrap text using textwidth
c       Auto-wrap comments using textwidth, inserting the current comment
        leader automatically.
r       Automatically insert the current comment leader after hitting
        <Enter> in Insert mode.
o       Automatically insert the current comment leader after hitting 'o' or
        'O' in Normal mode.
...

Temporarily setting the 'paste' option may do what you want, but it also disables a lot of other Vim features:

Use :set paste to turn it on and :set nopaste to turn it off. Alternatively, you can use :set paste! to toggle it.

See also:

:help 'paste'
:help 'pastetoggle'

(Those commands are typed with the single-quotes.)


I enter non-formatted plain new lines with <CR>.

When I want to continue typing the next line in the commented block I just use the O key as usual.

Try this:

nnoremap <silent> <cr> :set paste<cr>o<esc>:set nopaste<cr>

Tags:

Vim