Zheng Kai
Zheng Kai

Reputation: 3635

How to show different colors in files list when I filling git commit message in vim

when I'm filling commit messsage, I can see the files list, but they are same color (new/modify/del)

I'm asking file list highlighting, no message highlighting, not duplicate question of Configure git commit editor colors

I can only get the tag name is gitcommitSelectedFile, how to distinguish them ?

the first picture is in my vim, the second one is in vs code

Upvotes: 2

Views: 512

Answers (1)

seuling
seuling

Reputation: 2966

You can change by modify gitcommit.vim

You can find your gitcommit.vim in syntax/ dir.

you can easily find vim dir by :echo $VIMRUNTIME inside your vim.

Inside gitcommit.vim, you have to find gruop you want to change.

In my setting, it's gitcommitSelectedType. Here's gitcommitSelectedType match - it use \t\@<=[[:lower:]][^:]*[[:lower:]]: for matching modified: and new file: in commit template.

syn match   gitcommitSelectedType   "\t\@<=[[:lower:]][^:]*[[:lower:]]: "he=e-2 contained containedin=gitcommitComment nextgroup=gitcommitSelectedFile skipwhite

For simple example, I clear gitcoomitSelectedType and add new match for gitcommitNew and gitcommitModified. (simple match for example. You can use regex for your own)

syn clear gitcommitSelectedType
" match for new file and modified
syn match gitcommitNew  "\t\@<=new file: " contained containedin=gitcommitComment nextgroup=gitcommitSelectedType skipwhite
syn match   gitcommitModified   "\t\@<=modified: "he=e-2    contained containedin=gitcommitComment nextgroup=gitcommitModified skipwhite

" give other color type for these group
hi link gitcommitNew    Type
hi link gitcommitModified   Special
" add two groups we made to gitcommitSelected
syn region  gitcommitSelected   start=/^# Changes to be committed:/ end=/^#$\|^#\@!/ contains=gitcommitHeader,gitcommitHead,gitcommitSelectedType,gitcommitNew,gitcommitModified fold

Maybe there's better solution - not using group but using exception after gitcommitSelectedType - but I don't know how. Maybe you can find it.

Before

Before change color

After

enter image description here

ADD

Also, it will added for future. Check here

Upvotes: 3

Related Questions