17

As mentioned in this answer, since Git 1.8.2 you can use core.commentchar config value to change commit message comments to something else than the default # (hashmark or hashsign).

That is a life-saver e.g. if your commit message policy wants you to start commit message with ticket number:

#123 Fixed array indices

Sad part is that this breaks Vim syntax highlighting.

How can you bring the beauty back?

Community
  • 1
  • 1
Alois Mahdal
  • 10,763
  • 7
  • 51
  • 69

1 Answers1

16

You should try to run :verbose syntax. The active syntax file is probably $VIMRUNTIME\syntax\gitcommit.vim (github version which is likely in your .vim).

It will tell you which syntax line will trigger the formatting as comment.

You'll probably see something like :

 gitcommitComment xxx match /^#.*/
     links to Comment

or

 syn match   gitcommitComment   "^#.*"

meaning it matches every line starting by #.

You might be able to modify it so that a # on the first line is not considered as a comment. I don't know syntax format enough to give you a full solution.

 \%^   match the beginning of file
 \%1l  match line 1
 \%>1l match below line 1

So you might try to modify the gitComment pattern so that it does not work on line 1 of your git commit.

(I tried some things but did not manage to only exclude first line of comment ! It seems there is also a diffComment messing things up because gitcommit includes diff format with syn include @gitcommitDiff syntax/diff.vim) )

For more details, see :help syntax and :help pattern.

Another good resource on syntax highligthing : Learn Vim the Hard Way, chapter 46.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • 2
    Worked! I just add that to retain full HL functionality (like showing error on any text on 2nd line or coloring state details later in comments) I actually changed `#` to my `core.commentchar` (`'`) pretty *everywhere* in the file. Time will show if it broke something though... ;) – Alois Mahdal Apr 30 '13 at 14:51
  • Somebody knows if I can do this "adjustment" setting up my system by just running a system command eg. using ansible? – lony Aug 30 '19 at 20:31