11

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?

bcmcfc
  • 25,966
  • 29
  • 109
  • 181

2 Answers2

19

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'

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 3
    I found that in order to apply the configured word wrapping you'll need to press `ESC` followed by `L` once nano has opened. – JamesFrost May 11 '18 at 10:02
  • 2
    For nano v4.0 and later, you may want to also add `-b` option. – Craig McQueen Jan 25 '20 at 00:46
  • Regarding @JamesFrost comment: Also consider `set breaklonglines` in .nanorc file. "Since version 4.0, nano by default: • does not automatically hard-wrap lines that become overlong [...] To get the old, Pico behavior back, you can use set breaklonglines" [...] (See https://www.nano-editor.org/dist/latest/nanorc.5.html) – pedrito Mar 24 '22 at 09:46
0

A very detailed tutorial (with further information) on how to set line wrapping for nano (in general, not only in the context of git) can be found at: https://croccifix.io/gnu-nano.
Essentially you only have to comment out 'nowrap' and add or change 'set fill' to 'set fill 72' in nanorc.

In a terminal (I've tried it on a MAC):

cd /etc
sudo nano nanorc
#set nowrap
set fill 72 
HVossi92
  • 11
  • 2