Wednesday, March 13, 2013

new VIM version autocomment fix

I compiled the most recent version of VIM.  It has an annoying behavior

if I start a comment in insert mode and press enter in insert mode, the next line is automatically a comment too.

This means cutting and pasting from outside vim will fail at the first comment.  I guess it's useful for long comments, but mostly it's an annoyance.

However, by piecing together stuff from a few web pages and vim doc you can easily fix this.

You need to change your format options

you can do this from inside vim with set formatoptions. you can see your current formatoptions with :setlocal

So briefly:

To turn off, you need to disable the q option in formatoptions 
:setlocal find your format options then in your .vimrc au FileType * set formatoptions= after the =, put your format options without the q 
see http://vimdoc.sourceforge.net/htmldoc/change.html#format-comments for more details


* after FileType can be a language... so c, perl, ruby, python, etc.  

Thanks to http://www.kevinslonka.com/index.php?section=1&blog=179&page=1 for getting me started.  The comments have several clever fixes, including a compromise to stop commenting if the commented line ends with a space, but I haven't gotten that working myself.  You can also fix just the pasting with :set paste, if you prefer.



No comments:

Post a Comment