Code SnippetsGit commit message highlighting in nano Syndicate content

Sat, 11/24/2012 - 16:07

For those who use nano as their CLI editor of choice: Here’s a syntax highlighting file for Git commit messages which also supports the special KDE commit hook keywords.

  1. ## syntax highlighting for git commit messages of KDE projects
  2. syntax "patch" ".git/COMMIT_EDITMSG$"
  4. # overlong lines
  5. color brightred "^.{70,}.+$"
  7. # KDE commit hook keywords, see:
  9. color yellow "(SVN_SILENT|GIT_SILENT|SVN_MERGE)"
  11. # comment
  12. color blue "^#.*$"
  14. # special comment lines
  15. color green "^# Changes to be committed:"
  16. color red "^# Changes not staged for commit:"
  17. color brightblue "^# Untracked files:"
  18. color brightblue "^# On branch .+$"
  19. color brightblue "^# Your branch is ahead of .+$"
  21. # diff files
  22. # meh - cannot match against \t ... should be: ^#\t.*$
  23. color cyan "^#[^ a-zA-Z0-9][^ ].*$"

Just put this file as gitcommit.nanorc or similar somewhere on your disk and load it from your .nanorc or even /etc/nanorc like this:

  1. include "/path/to/gitcommit.nanorc"
Screenshot of highlighted git commit message
Screenshot of highlighted git commit message


Use [^[:space:]] or Thu, 07/31/2014 - 17:16 — Anonymous

Use [^[:space:]] or [[:space:]] for \t More info search for “bash regex space or tab”

It’s news to me that nano has Sat, 11/24/2012 - 20:53 — Nicolas (not verified)

It’s news to me that nano has syntax highlighting.

Take a look at the bottom of Sat, 11/24/2012 - 21:57 — Milian Wolff

Take a look at the bottom of /etc/nanorc and the files available in /usr/share/nano/ and on the web (including my website).


Merci, it is possible to Sat, 11/24/2012 - 17:31 — christoph (not verified)

Merci, it is possible to alert the user, if the second line is not empty?

Afaik not, since nano Sat, 11/24/2012 - 21:58 — Milian Wolff

Afaik not, since nano highlighting is done on a line-by-line basis. Thus I cannot figure out on which line I am…

I’d be happy to be proven wrong though, esp. if that would mean we could also add a special highlighting for the very first line.


Post new comment

  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options