You are getting these settings for a git commit message because Vim recognizes the filetype (gitcommit
) and loads filetype-specific settings for it.
In this case, it's coming from file $VIMRUNTIME/ftplugin/gitcommit.vim
, which includes the following line:
setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72
You can override that by adding another filetype plugin for gitcommit
to your home directory, one that will load after the one from the Vim runtime.
You can do that with a file named ~/.vim/after/ftplugin/gitcommit.vim
(assuming you're using Vim, if you use NeoVim the initial part of the path will be different.) The after
directory is used for plugin files that are loaded at the end, so by placing your file there you'll be sure your code will run after the one mentioned above.
In that file you can add a command to undo the unwanted effects of line wrapping, for example:
setlocal textwidth&
Or:
setlocal formatoptions-=t formatoptions-=l
Either of these two settings will prevent automatically breaking lines at column 72. The advantage of changing 'formatoptions'
rather than resetting 'textwidth'
is that by only changing 'formatoptions'
you can still use commands such as gq
to manually format a block of text to conform to the 72 character line width limit, if you wish to do so. You get the best of both worlds that way.
Whichever of the two options you decide to set, make sure you use :setlocal
rather than :set
, since that plugin is loaded for that buffer only, you should try to only modify the options on that buffer alone and avoid touching global options.
:set ft?
Is itgitcommit
or justcommit
or something to that effect? Knowing the filetype, you can add an override to it. – Greave