首页 > 解决方案 > 当我在vim中填写git commit消息时如何在文件列表中显示不同的颜色

问题描述

当我填写提交消息时,我可以看到文件列表,但它们的颜色相同(新/修改/删除)

我在问文件列表突出显示,没有消息突出显示,而不是配置 git 提交编辑器颜色的重复问题

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

第一张在我的vim里,第二张在vs代码里

标签: gitvimsyntax-highlightinggit-commitcolor-scheme

解决方案


你可以通过修改来改变gitcommit.vim

你可以找到你gitcommit.vimsyntax/目录。

您可以在 vim 中轻松找到 vim 目录:echo $VIMRUNTIME

在内部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

举个简单的例子,我清除并为andgitcoomitSelectedType添加新的匹配。(例如简单匹配。您可以自己使用正则表达式)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 之后使用异常 - 但我不知道如何。也许你能找到它。

换色前

在此处输入图像描述

添加

此外,它将为将来添加。在这里检查


推荐阅读