Tutorial :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 automatically set spell on when editing that file. something on the lines

if ( filename has a word COMMIT)

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


This line works for me:

autocmd FileType gitcommit setlocal spell  


au BufNewFile,BufRead COMMIT_EDITMSG setlocal spell


autocmd BufNewFile,BufRead COMMIT_EDITMSG set spell

in ~/.vimrc will do it


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.


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/ftplugins/gitcommit.vim for example)

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »