vim语法高亮显示git提交消息 - 自定义commentchar [英] vim syntax highlighting for git commit messages - custom commentchar

查看:470
本文介绍了vim语法高亮显示git提交消息 - 自定义commentchar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如前所述,在此回答中,自Git 1.8.2起,您可以使用 core.commentchar config值将提交消息注释更改为默认值(hashmark或hashsign)之外的值。



这是一个救命星球如果您的提交消息策略要求您开始提交票证号的提交消息:

 #123固定数组索引

可悲的是,这打破了Vim的语法高亮。



您应该尝试运行:verbose语法 c>。活动语法文件可能为 $ VIMRUNTIME\syntax\gitcommit.vim github版本,其可能在您的 .vim 中)。



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



您可能会看到类似的结果:

  gitcommitComment xxx match /^#.*/ 
链接到评论

  syn match gitcommitComment^#。*

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



您可以修改它,使第一行上的不被视为注释。我不知道语法的格式足以给你一个完整的解决方案。

  \%^匹配文件的开头
\%1l匹配行1
\%> 1l匹配行1下面

所以你可以尝试修改gitComment模式,使它不能在git commit的第1行工作。



(我尝试了一些东西,但没有设法只排除第一行注释!似乎还有一个 diffComment 混乱的事情,因为gitcommit包括diff格式与 syn include @gitcommitDiff syntax / diff.vim



有关详细信息, $ c>:help语法:帮助模式



语法错误:学习Vim的艰难的方式,第46章


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?

解决方案

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.

这篇关于vim语法高亮显示git提交消息 - 自定义commentchar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆