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

vim

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?

Best Answer

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