Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically wrap long Git commit messages in Vim

Using Git, my editor for commits is Vim. I'm constantly doing a poor job of remembering to wrap lines and so I get long lines (see this answer for example). Is there a way using some git config or .vimrc magic that I can get Vim to automatically wrap lines at 72 columns?

Related question.

like image 617
mgilson Avatar asked Jun 13 '12 20:06

mgilson


People also ask

Can commit messages be long?

Body line length limited to 80 characters The line length for the body text of a commit message should be constrained to 80 characters. Regardless of if you manually wrap the body line length to 80 characters or not, the body text will appear as wrapped as 80 characters in the GitHub UI.

How long should git commit messages be?

The ideal size of a git commit summary is around 50 characters in length. Analyzing the average length of commit messages in the Linux kernel suggests this number.


2 Answers

Add this to your .vimrc:

au FileType gitcommit setlocal tw=72 
like image 191
Abe Voelker Avatar answered Sep 24 '22 03:09

Abe Voelker


While the other answers solve this problem perfectly well, I highly recommend you install Tim Pope's fugitive.vim.

fugitive.vim is an excellent plugin that brings Git functionality to Vim. It has a whole host of features that aren't relevant to your question, but are worth checking out. However, it can also help you remember to keep your commit messages the proper length:

Sample commit message within Vim on fugitive

like image 26
David Cain Avatar answered Sep 23 '22 03:09

David Cain