9

I'm of the opinion that the orthodox 50-character limit on git commit messages is absolutely ridiculous. (Primarily because I think using an 80-character wide Terminal in 2015 is equally ridiculous.) :P

I've fixed a few other glaring issues with vim's default settings for git commit-messages in my vimrc; but vim still hilights the first line if it's longer than 50 characters:

How can I change the line-length at which this occurs?

1
  • Don't forget that git is a tool to share your work. Unless you do only your personal stuff and never share it, you may assume terminals are very wide. However don't assume all users that may work with your changes use the same terminal width. Yes, having a "crispy one-line-summary" of your changes can be a challenge.
    – U. Windl
    Commented Mar 14, 2023 at 7:59

2 Answers 2

8

This is caused by the following line from $VIMRUNTIME/syntax/gitcommit.vim:

syn match   gitcommitSummary    "^.\{0,50\}" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell

You could just copy that syntax script to ~/.vim/syntax/ and modify it, but that drags you into maintaining your clone. I prefer to selectively change that single syntax definition in ~/.vim/after/syntax/gitcommit.vim:

syn clear gitcommitSummary
syn match   gitcommitSummary    "^.\{0,80\}" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell

Alternatively / in addition, you could open an issue at the project and ask for a configurable threshold; the hard-coded limit certainly isn't nice.

5
  • Is it even possible for that to be configurable? If so, I'll pass it on to @tpope. Commented Mar 12, 2015 at 15:08
  • 1
    For future reference: the maximum length as imposed by GitHub is exactly 72 characters. (Thanks, @tpope.) Commented Mar 12, 2015 at 15:16
  • On my Mac $VIMRUNTIME is empty. Is that likely ~/.vim? Commented Jan 5, 2019 at 15:22
  • 1
    @DanRosenstark: No, that's your personal configuration directory (where you'd put the override in the after directory). $VIMRUNTIME refers to the Vim scripts that ship with Vim. You should see the actual location in the :scriptnames output; lots of scripts are loaded on startup from there (and one of those will end with syntax/gitcommit.vim). Commented Jan 5, 2019 at 17:45
  • 1
    Cool, I see it now, thanks! /usr/share/vim/vim80/syntax/gitcommit.vim Commented Jan 5, 2019 at 22:15
1

As of of Vim 9.1, you can put let gitcommit_summary_length = 80 in your vimrc and the gitcommit.vim syntax script will automatically honor it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .