Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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: stackoverflow.com/questions/4896003/… –  Ciro Santilli Jan 22 at 9:34

2 Answers 2

up vote 18 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
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.
...
share|improve this answer
2  
Thank you so much! This behavior was bothering me-- I came from unix vi to Linux vim. For googlers: For permanent use, see also stackoverflow.com/questions/6076592/… and enter this line into /etc/vimrc:autocmd BufNewFile,BufRead * setlocal formatoptions-=cro –  bgStack Jul 23 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 at 1:55
    
alternatively you can use :set paste! to toggle it TRUE and FALSE –  Felipe Alvarez Jun 24 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.