3

I use Vim as my core editor for Git.

I've noticed that, whenever Git fires up Vim following a git commit (and assuming Vim's syntax option is enabled), some Vim settings other than my own are applied. In particular, my commit messages get highlighted in a way that I haven't defined anywhere (see below); I use the zenburn color scheme, but that's irrelevant to my question.

enter image description here

Note, for instance, how the branch name on line 5 is highlighted in a color that is different from that of the rest of the comments.

Additionally, settings that promote the official Git formatting guidelines (see this) are also applied:

  • Vim screams at any visible character past the 50th column on line 1, or if the second line is not blank;
  • Vim's textwidth is set to 72.

enter image description here

Don't get me wrong; I find those Vim settings very useful for writing commit messages. My questions are simply:

  1. Is Git responsible for those Vim settings?
  2. If so, where (in what file) does Git store those settings?
  3. By what mechanism does Git load those settings? Is some Git hook responsible?

Here is a shell script that reproduces the situation:

#!/bin/bash
cd ~/Desktop
mkdir test_cmtmsg
cd test_cmtmsg
git init
touch test.txt
git add test.txt
git commit -m "inital commit"
# oops, made a mistake there
git commit --amend
jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • 1
    Vim has git settings you can find them in `$VIMRUNTIME/ftplugin/git*.vim`. You can check where a setting was last set from with `verbose set textwidth` – FDinoff Jun 04 '14 at 20:24
  • related: http://stackoverflow.com/q/3459744/2541573 – jub0bs Jun 08 '14 at 10:11

1 Answers1

3

Vim ships with a number of syntax definitions, including ones for use with Git. These are found at $VIMRUNTIME/syntax; specifically, the one for Git commit messages is $VIMRUNTIME/syntax/gitcommit.vim.

mipadi
  • 398,885
  • 90
  • 523
  • 479
  • Ah thanks for that! FDinoff's comment is off by one subdirectory. `$VIMRUNTIME/syntax/gitcommit.vim` is indeed what I was looking for. – jub0bs Jun 04 '14 at 20:41