Most of the time I'd like noexpandtab on because our corporate formatting uses tabs instead of spaces, so in my .vimrc I have this:

" Set tab width stuff
set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4

What is annoying though is when I am writing my git commit messages and tabs come in, I'd like those to be spaces. I know I could just do :set expandtab when I'm writing a commit message but it seems annoying to do every time. Surely there is a better way?

For what it's worth I'm running vim through git bash in Git for Windows.

  • 4
    What's the value of :set ft? when you write a commit message? If it's git related, you can then write a specific autocmd FileType event that sets your expandtab option.
    – VanLaser
    Oct 9 '15 at 22:02
  • 2
    @VanLaser :set ft gives filetype=gitcommit, I'll look into autocmd, I'm not familiar with it. Oct 9 '15 at 22:39
  • Put set expandtab in a file after/ftplugin/gitcommit.vim. Oct 10 '15 at 5:38

First possibility

Add the following line to your .vimrc:

autocmd FileType gitcommit setlocal expandtab

Second possibility

Create a file ~/.vim/after/ftplugin/gitcommit.vim

and in there put:

:setlocal expandtab

See the faq:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.