Search code examples
gitnano

How to set nano up for git commit messages with line length limits


I use nano for git commit messages. Short summary (<=50 chars) plus a new line before the description is relatively straightforward to stick to. However, when it comes to wrapping at 72 chars in the description body I just go off what seems to look right, making for inconsistent logs.

In Vagrantfiles I've seen this sort of thing to tell the editor what to do for vi/vim:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Is there something like that for nano, and a template somewhere for git commit, that means I can ensure that nano would be set up for the correct line wrapping when in the context of a git commit message?


Solution

  • Nano supports the passing of command line arguments when starting it.

    This can be leveraged as part of the git editor config setting.

    git config --global core.editor "nano -r 72"

    Or:

    export GIT_EDITOR='nano -r 72'