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?

link|improve this question

62% accept rate
feedback

2 Answers

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.
...
link|improve this answer
feedback

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.)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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