20

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?

5
  • 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). Commented Jun 19, 2014 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. Commented Jun 19, 2014 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. Commented Jun 19, 2014 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. Commented Oct 22, 2014 at 10:45
  • @jw013 Nonsense! The guy obviously does not like the Tim Pope's style pulled out of nowhere. The question is about how to make vim to do what the OP considers reasonable. Commented Jun 8, 2022 at 13:44

2 Answers 2

9

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

setlocal textwidth=0

1
  • 1
    Thank you. The other solution didn't work for me on OpenSUSE, but this one did. Commented Sep 14, 2019 at 19:30
7

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<
1
  • 3
    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'. Commented Feb 27, 2018 at 23:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.