gpt4 book ai didi

git - git 提交消息的 vim 语法突出显示 - 自定义 commentchar

转载 作者:IT王子 更新时间:2023-10-29 00:37:40 27 4
gpt4 key购买 nike

如前所述in this answer ,从 Git 1.8.2 开始,您可以使用 core.commentchar 配置值将提交消息注释更改为默认 #(井号或井号)以外的其他内容。

那是救命稻草如果您的提交消息策略希望您使用票号开始提交消息:

#123 Fixed array indices

可悲的是,这会破坏 Vim 语法高亮。

怎样才能把美丽带回来?

最佳答案

您应该尝试运行 :verbose syntax。事件语法文件可能是 $VIMRUNTIME\syntax\gitcommit.vim(github version 可能在您的 .vim 中)。

它会告诉您哪个语法行将触发格式化为注释。

您可能会看到类似这样的内容:

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

 syn match   gitcommitComment   "^#.*"

意味着它匹配以 # 开头的每一行。

您可以修改它,以便第一行的 # 不被视为注释。我对 syntax 格式的了解不足以为您提供完整的解决方案。

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

因此您可能会尝试修改 gitComment 模式,使其在您的 git 提交的第 1 行不起作用。

(我尝试了一些方法,但没有设法只排除第一行评论!似乎还有一个 diffComment 把事情搞砸了,因为 gitcommit 包含 diff 格式和 syn include @gitcommitDiff语法/diff.vim))

有关详细信息,请参阅:help syntax:help pattern

关于语法高亮的另一个很好的资源:Learn Vim the Hard Way, chapter 46 .

关于git - git 提交消息的 vim 语法突出显示 - 自定义 commentchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16164624/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com