1

For some context, I'm talking about Git commits specifically. The Linux server that I use for work changes the color of the first line starting from column 53 (since 52 is the recommend commit title length) and for the body after column 70 the words wrap to the next line automatically.

How do I configure Vim to do this?

2
  • What you want is the default behavior if you enable syntax highlighting: syntax on.
    – romainl
    May 10, 2023 at 15:43
  • Did you found a solution to your problem? How can we help you further? May 11, 2023 at 15:14

3 Answers 3

1

You can override the gitcommit file type by adding a gitcommit.vim file into: ~/vimfiles/after/ftplugin.

To change the body width to 50 you could add to the file:

setlocal textwidth=50

The first line warning is probably a specific colorization using a regular expression of the kind \%>52v.

1

The column 70 wrapping can be set with

setlocal textwidth=70

as @VivianDeSmedt recommended. You can highlight columns 53 and greater on line 1 only using

call matchadd('Error', '\%1l\%>52v')

Note that "Error" can be any highlighting color group.

0

Your question is a bit unclear whether you want to enable this behavior on your machine or change it. Since Vivian already explained how to override filetype settings, I'm going to talk about the other things.

The syntax highlighting and textwidth are set in two files called gitcommit.vim. One is located in $VIMRUNTIME/syntax, the other one in $VIMRUNTIME/ftplugin. These files come with Vim.

To set the filetype for the current buffer, write set filetype=gitcommit.

To have automatic filetype detection, put :filetype plugin on in your vimrc.

As always, refer to :help for the options mentioned above.

It's also possible to define new filetypes or define aliases. I once did this to apply git syntax highlighting to svn commit messages (not perfect but better than nothing).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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