Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Vim, if I'm typing a comment in a code file, and I hit enter, it automatically makes the newline a comment, too.

For instance, in a Ruby file:

# I manually typed the pound at the start of this line and hit enter.
# This line formatted itself this way automatically.

Generally, this is what I want, but not always. How can I temporarily turn off this auto-commenting behavior?

share|improve this question
By temporarily, do you want a a command that does it a single time, or set some option that will last for a few commands until you turn it back on? Possible cross site duplicate:… – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Jan 22 '14 at 9:34
How ever thought that this was a cool feature to add to vim should have their fingers broken. – Red Cricket Dec 18 '15 at 8:13
up vote 39 down vote accepted

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

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.
share|improve this answer
Thank you so much! This behavior was bothering me-- I came from unix vi to Linux vim. For googlers: For permanent use, see also… and enter this line into /etc/vimrc:autocmd BufNewFile,BufRead * setlocal formatoptions-=cro – bgStack15 Jul 23 '14 at 14:20

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

:help 'paste'
:help 'pastetoggle'

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

share|improve this answer
:set paste to turn it on and :set nopaste to turn it off – User May 23 '14 at 1:55
alternatively you can use :set paste! to toggle it TRUE and FALSE – Felipe Alvarez Jun 24 '14 at 3:37

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

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

Try this:

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .