Enable Git Commit Message Syntax Highlighting in Vim on Fedora

Were you looking forward to reading an exciting blog post about substantive technical issues affecting GNOME or the Linux desktop community? Sorry, not today.

When setting up new machines, I’m often frustrated by lack of syntax highlighting for git commit messages in vim. On my main workstation, vim uses comforting yellow letters for the first line of my commit message to let me know I’m good on line length, or red background to let me know my first line is too long, and after the first line it automatically inserts a new line break whenever I’ve typed past 72 characters. It’s pretty nice. I can never remember how I get it working in the end, and I spent too long today trying to figure it out yet again. Eventually I realized there was another difference besides the missing syntax highlighting: I couldn’t see the current line or column number, and I couldn’t see the mode indicator either. Now you might be able to guess my mistake: git was not using /usr/bin/vim at all! Because Fedora doesn’t have a default $EDITOR, git defaults to using /usr/bin/vi, which is basically sad trap vim. Solution:

$ git config --global core.editor vim

You also have to install the vim-enhanced package to get /usr/bin/vim, but that’s a lot harder to forget to do.

You’re welcome, Internet!

One Reply to “Enable Git Commit Message Syntax Highlighting in Vim on Fedora”

  1. Something I like to add on top of your recommendation, is a git message template, which IIRC I got from drew devault’s blog:
    https://drewdevault.com/2019/02/25/Using-git-with-discipline.html

    In a nutshell, in ~/.gitconfig add:
    [commit]
            template = ~/.gitmessage

    Then create the ~/.gitmessage with the following:
    “`
    # When applied, this commit will… (max 50 col):

    # Extend the commit message, include details like rationale for the
    # change, tradeoffs and limitations of the approach, etc. (max 72 col):

    “`
    Both comments are as long as they say the Max should be (aprox at least), which is a good visual hint.

    Sorry if you knew about this already!

    Cheers,
    Minkiu.

Comments are closed.