开发者

VIM set spell in file .git/COMMIT_EDITMSG

I want to "set spell" automatically when i am editing the commit text in git. From the % I see that it is writing to a filename called .git/COMMIT_EDITMSG. How do I update my .vimrc to开发者_JAVA百科 automatically set spell on when editing that file. something on the lines

if ( filename has a word COMMIT)

set spell

fi


This line works for me:

autocmd FileType gitcommit setlocal spell


Ordinarily you could do this using an autocmd (au BufNewFile,BufRead COMMIT_EDITMSG setlocal spell) but recent versions of vim already have a filetype assigned for git commit messages, so what you can do instead is create a file ~/.vim/ftplugin/gitcommit.vim and put this in it:

if exists("b:did_ftplugin")
  finish
endif

let b:did_ftplugin = 1 " Don't load twice in one buffer

setlocal spell

and make sure that you have filetype plugin on in your .vimrc. It's a little more work getting going but it makes it easier to add tweaks in the future. :)


au BufNewFile,BufRead COMMIT_EDITMSG setlocal spell


autocmd BufNewFile,BufRead COMMIT_EDITMSG set spell

in ~/.vimrc will do it


A handy way to do this cleanly is with a vim filetype plugin.

This will allow you to place file type dependant configurations/mappings in a seperate file (see my .vim/ftplugin/gitcommit.vim for example)

To do so, create a file at ~/.vim/ftplugin/gitcommit.vim and place your custom configurations there.


You can add 'set spell' to your .vimrc file to make Vim automatically spell check all documents including your git commit messages. Vim is smart enough to spell check comments and strings while ignoring your source code.

Depending on your colorscheme, this can be annoying though to see variable names in your comments and strings highlighted as misspelled words.

See this stackoverflow question for more details on spell checking.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜