2014-12-04

Vim でコメントの継続をやめるには

Vim: can I disable continuation of comments to the next line? - Super User」に出ていた質問。

'formatoptions' を変更する(:set formatoptions-=cro などとする)とよいとの回答だが、.vimrc にこれを設定してもうまくいかない。

これは Vim が特定の syntax (c, python, ruby ...) を検出したときに読み込む .vim ファイルで 'formatoptions' を変更しているからである。

例えば ftplugin/c.vim では setlocal fo-=t fo+=croql (fo は formatoptions の省略形)となっている。よって常に formatoptions-=cro としたければ ~/.vim/after/ftplugin/c.vim を作成して、その中で setlocal formatoptions-=cro とする必要がある。