Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Git load Vim settings for COMMIT_MSG? If so, where are they stored?

Tags:

git

vim

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
like image 428
jub0bs Avatar asked Jun 12 '26 17:06

jub0bs


1 Answers

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.

like image 186
mipadi Avatar answered Jun 15 '26 12:06

mipadi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!