4

I found that when I am using Vim to compose git commit messages (which I have been doing for a very long time now) that there are occasionally some quirks.

For example today I wrote a commit message that began with the word "do".

This actually forces the second line to be indented for me. Likely because do is often a keyword that initiates a do...while loop.

How can I make modifications to syntax definitions to remove this behavior?

When I am in this situation, the formatoptions is set to caq1njwtl. However, I don't think that this is relevant because I don't really care about having my message auto-wrapped, I just want it to not apply any indentation.

  • I think the correct answer is almost certainly an autocommand based on the gitcommit filetype. I'll post it if I can come up with one myself. – Steven Lu Feb 9 '15 at 2:19
  • Hmm, I can't reproduce your issue? I set the formatoptions to caq1njwtl, do git commit, and hit i (for insert mode), type do and hit enter ... Am I doing it right? ... I can't get the gitcommit filetype to apply auto-indent no matter what I do ... There isn't even an indent/git*.vim file on my system? – Martin Tournoij Feb 9 '15 at 2:22
  • 2
    While you're typing a commit message, if you try typing :set ft? and hitting enter, what is the output? – Doorknob Feb 9 '15 at 2:24
  • It's gitcommit. I solved it. Posting answer now. – Steven Lu Feb 9 '15 at 7:35
  • @Carpetsmoker Yeah, my .vimrc is 1703 lines and 52K in size at present. I'm not surprised at all that this isn't reproduced with vanilla vim. – Steven Lu Feb 9 '15 at 7:59
6

Here is how I solved the problem, by adding to my .vimrc:

autocmd FileType gitcommit set nosmartindent | set formatoptions-=t

This removes the option that causes the lines to auto-wrap (which is another tweak I also made -- take out the last part including the | if you do not want to change this).

The take-away here is that nosmartindent is the trick to addressing any undesired auto indentation behaviors.

  • 1
    smartindent is something you only want to enable in C, and maybe a few languages with a syntax that's very similar... I think it's a leftover from before Vim had indent files for different languages. – Martin Tournoij Feb 9 '15 at 7:52
  • Yeah maybe I will test with smartindent removed from my configuration and enabling it only for specific C-style filetypes (and javascript, etc). I already have an autocmd for Python that disables it as well, which was put in place for reasons quickly becoming obvious. – Steven Lu Feb 9 '15 at 8:01
  • Even without filetype-specific indent scripts, 'cindent' has replaced the functionality of 'smartindent'. – jamessan Feb 10 '15 at 4:53

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.