Automatically complete long git commit messages in Vim

Using Git, my editor for commits is Vim. I constantly work poorly, remembering the wrapper of the lines, and therefore I get long lines (like this answer ). Is there a way to use the magic of git config or .vimrc that I can get Vim to automatically wrap rows in 72 columns?

Related question.

+58
git commit-message vim textwrapping
Jun 13 '12 at 20:59
source share
6 answers

Add this to your .vimrc :

 au FileType gitcommit setlocal tw=72 
+79
Jun 13 2018-12-12T00:
source share

While the other answers solve this problem perfectly, I highly recommend installing Tim Pope fugitive.vim .

fugitive.vim is a great plugin that brings Git functionality to Vim. It has a number of features that are not relevant to your question, but they are worth checking out. However, it can also help you remember that your commit messages have the proper length:

Sample commit message within Vim on fugitive

+19
Jun 23 2018-12-12T00:
source share

Add this to your .vimrc :

 filetype indent plugin on 

From here .

+17
Jun 23 '12 at 8:45
source share

2018 Update

If you update vim, it will automatically highlight the first 50 characters of your title and wrap the lines in 72 characters. He knows that you are editing a git commit file.




Install Homebrew

 brew install vim 
+6
Feb 12 '18 at 19:49
source share

Here's a git hook for an automatic wrapper that will work with any editor: https://github.com/surabhigupta/AutoWrapSeventyTwo

+1
Jan 18 '14 at 9:09
source share

Several options from previous posts work, except that I noticed inconsistencies between different systems.

Fedora 28 (recently upgraded from F26) was easy as soon as I realized: the version inside the bastard of commit / GIT tags showed that it was pointing to .virc files (weird *), so I just copied my ~ / .vi m gs in ~ /. Virk [except, see below].

macOS 10.13.4 with vim 8.0 from brew works fine with /usr/share/vim/vim80/ftplugin/gitcommit.vim according to : verbose: set tw =? ,

CentOS 7.4 with vim 7.4 (git version 1.8.3.1) for some reason, although it didn't seem to use the textwidth line in the attached gitcommit.vim, so I went for a quick and dirty workaround (to save me from working with multiple files ) in ~ / .vimrc:

 nmap <F2> :set textwidth=72<CR> inoremap <F2> <Esc>:set textwidth=72<CR>a 

This seems to work quite well and is easy to remember - I still basically just get out of there and have already stopped messing with the old versions of git and vim.

Otherwise, I (temporarily) went after Chip Hogg's suggestion after Abe Voelker answered: autocmd FileType gitcommit setlocal textwidth = 72

I don't think this matters a lot in git-commit, but it might be better to be safe (especially if this line ends with copying in vimrc). The file type is, of course, included, as in many vimrcs examples.

* However, I was still curious why vim ruler wasn’t showing up, so I looked: a help line that says + cmdline_info (displayed after: version) needs to be installed at compile time. Execution: ver in vim outside of git-commit detected different settings and different compilation times, suggesting that git might have called a system copy of vim instead of a custom one.

In the beginning, I had to run git config --global core.editor "vim", except that I did not, because I assumed that it was an excess step. Doing this first with every git installation can save you a lot of trouble from the start!

+1
Jun 07 '18 at 20:29
source share



All Articles