在vim中为gitcommit配置行高亮显示长度限制



我对vim很陌生。但我一直在读的一件事是,如果你使用vim提交消息(摘要+消息(超过了字符限制,那么就有可能进行颜色高亮显示。

我上下搜索过,但不知道如何配置它。

colorcolumn选项(请参阅:h 'cc'(。假设您已经正确设置了:h 'textwidth',则可以使用colorcolumn:的相对值

~/.vim/after/ftplugin/gitcommit.vim

setlocal textwidth=79
setlocal colorcolumn=+1

您可以在$VIMRUNTIME/syntax/gitcommit.vim中找到语法文件,其中会突出显示提交消息。

syn match   gitcommitSummary    "^.*%<51v." contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell
" hi def link gitcommitOverflow     Error

您可以将这两行添加到本地after/语法文件中,如$HOME/.vim/after/syntax/gitcommit.vim。然后,您可以根据需要调整长度限制(51(和高亮显示(Error(。

syn match   gitcommitSummary    "^.*%<61v." contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell
hi def link gitcommitOverflow       Underlined

最新更新