当我在 vim 中填写 git 提交消息时,如何在文件列表中显示不同的颜色

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

当我填写提交消息时,我可以看到文件列表,但它们的颜色相同 (new/modify/del)

我问的是文件列表高亮,没有消息高亮,不是[=16=的重复问题]

我只能得到标签名称是gitcommitSelectedFile,如何区分它们?

第一张图在我的vim,第二张在vs code里

你可以修改gitcommit.vim

您可以在 syntax/ 目录中找到您的 gitcommit.vim

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

gitcommit.vim 中,您必须找到要更改的组。

在我的设置中,它是 gitcommitSelectedType。这是 gitcommitSelectedType 匹配 - 它使用 \t\@<=[[:lower:]][^:]*[[:lower:]]: 来匹配提交模板中的 modified:new file:

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

举个简单的例子,我清除了 gitcoomitSelectedType 并为 gitcommitNewgitcommitModified 添加了新的匹配项。 (例如简单匹配。您可以自己使用正则表达式)

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

也许有更好的解决方案 - 不使用组,而是在 gitcommitSelectedType 之后使用异常 - 但我不知道如何。也许你能找到。

之前

之后

添加

另外,以后会加上的。检查 here