dmkc
dmkc

Reputation: 1181

Vim using non-standard configuration when called from `git commit`?

I've noticed that git seems to use different vim settings any time I'm writing a commit message. I have the git+svn install off Macports, and I've checked the $MYVIMRC variable: it's set to the correct file. Still, every time I go to commit a message I have a restriction on 80 characters per line, case sensitive search, and none of the plugins I've installed.

It's probably something silly. Would appreciate a pointer as to what it is.

EDIT: Actually I just checked: my plugins work. It's only the column width of 80 chars that miraculously comes alive when I type out commit messages.

Upvotes: 8

Views: 2873

Answers (4)

Cody Hess
Cody Hess

Reputation: 1796

FWIW, I had a similar problem -- Vim was disabling my textwidth setting in .txt files because one of the filetype plugins being called had the line "formatoptions -=t"

Instead of editing the plugins (which made me uncomfortable), I circumvented the problem by adding the line ":filetype plugins off" to my ~/.vimrc file. The solution was detailed here - http://peox.net/articles/vimconfig.html

(I originally thought the problem was git-related, but after testing in a non-git directory I found it was due to the .txt file extension.)

Upvotes: 1

Cascabel
Cascabel

Reputation: 497592

That's not a bug, it's a feature!

Vim knows about a lot of filetypes - including git commits (and interactive rebases, and config...). There are syntax definitions and ftplugins (filetype-activated plugins) for each of these. One of the settings in the commit ftplugin is textwidth=72. This is done so that the output of git log will look good in a standard-width terminal. If you really want to change it, you could go edit the plugin, but I'd really recommend keeping it.

The plugin should be in <vim-directory>/vimXX/ftplugin/gitcommit.vim. The XX is the version number, e.g. 72 for version 7.2, and the leading component is generally something like /usr/share/vim.

P.S. The plugin also defines a command DiffGitCached, which will open the diff to be committed in a preview window. Handy!

Upvotes: 15

Thomas
Thomas

Reputation: 182063

Partial answer, maybe helpful...

According to ps aux, git starts vim with this command:

vim .git/COMMIT_EDITMSG

This triggers the syntax mode gitcommit, which on my Ubuntu system lives in

/usr/share/vim/vimcurrent/syntax/gitcommit.vim

and is loaded from

/usr/share/vim/vimcurrent/filetype.vim

Upvotes: 1

jamessan
jamessan

Reputation: 42757

:verbose set textwidth? formatoptions? will tell you the values of these option and what script last set them. Text is only hard-wrapped while typing if 'textwidth' is non-zero and 'formatoptions' contains the t setting. It's likely that the gitcommit filetype plugin (ftplugin/gitcommit.vim) is changing one or both of these options because you have filetype plugins enabled (:filetype shows plugin:ON).

Upvotes: 4

Related Questions