Vim has this awful annoying habit of splitting my commit messages and automatically line-breaking them, rendering the second line with a red background for some reason.

enter image description here

How can I make vim stop doing this?

  • 1
    What are the vim variables tw and wm set to? If they're set to non-zero values, you will get automatic line breaks inserted (by default at column 80). – ewhac Jun 19 '14 at 23:15
  • 11
    This is Vim's built-in file type syntax highlighting for git commit messages trying to enforce a certain format for git messages. Your highlighting looks ugly because your git commit message is "ugly", in the sense that it does match the format Vim is expecting you to follow. Both the gitcommit.vim syntax highlighting module and the guidelines were written by Tim Pope. You can read them here: tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html. For a quick summary, make the first line a 50 character summary, leave a blank line, and then write your paragraphs below. – jw013 Jun 19 '14 at 23:21
  • 11
    (continued)... So, this is not technically an answer, but you are supposed to make the highlighting not ugly by writing a properly formatted git commit message. Try to keep line one below 50 characters. Line 2 is supposed to be blank, which is why it is being colored a BOLD RED for "Warning: this text isn't supposed to be here!" Type the extended message beginning on line 3. Vim will automatically break your lines at 72 characters. Let it do so. If you need Vim to redo the line breaks because you did some editing, highlight the paragraph and do gq to fix the line breaks. – jw013 Jun 19 '14 at 23:25
  • 1
    "If you need Vim to redo the line breaks because you did some editing, highlight the paragraph and do gq to fix the line breaks." Or navigate to the paragraph and type gqip to gq the paragraph you're in. – Andrew Martin Oct 22 '14 at 10:45

The filetype plugin enforces the preferred Git commit message style: Short title, and hard line breaks. If you don't agree with that style, undo the settings by putting the following into ~/.vim/after/ftplugin/gitcommit.vim:

setlocal wrap formatoptions<
| improve this answer | |
  • 1
    For those wondering how formatoptions< could be a valid argument to setlocal, the docs for :setlocal explain that it will “Set the local value of {option} to its global value by copying the value.” So this command will remove the t and l flags (documented in fo-table) that the plugin adds to 'formatoptions'. – Rory O'Kane Feb 27 '18 at 23:35

I found the setting I needed in ~/.vim/after/ftplugin/gitcommit.vim was:

setlocal textwidth=0

| improve this answer | |
  • Thank you. The other solution didn't work for me on OpenSUSE, but this one did. – Artem Russakovskii Sep 14 '19 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.