Skip to content

Instantly share code, notes, and snippets.

@BlakeGardner
Last active November 11, 2024 10:29
Show Gist options
  • Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Save BlakeGardner/5587269 to your computer and use it in GitHub Desktop.
Syntax highlighting in nano on Mac OS
# Last updated May, 2024 for Apple silicon Macs
# Install Homebrew if you don't already have it: https://brew.sh
# install nano from homebrew
brew install nano nanorc
# update your nanorc file
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc
# close and re-open your terminal and you'll have syntax highlighting
@docdyhr
Copy link

docdyhr commented Apr 29, 2021

nanorc: stable 2020.10.10, HEAD
Improved Nano Syntax Highlighting Files
https://github.com/scopatz/nanorc

brew install nanorc
include /usr/local/share/nanorc/Dockerfile.nanorc
include /usr/local/share/nanorc/Rnw.nanorc
include /usr/local/share/nanorc/apacheconf.nanorc
include /usr/local/share/nanorc/arduino.nanorc
include /usr/local/share/nanorc/asciidoc.nanorc
include /usr/local/share/nanorc/asm.nanorc
include /usr/local/share/nanorc/awk.nanorc
include /usr/local/share/nanorc/batch.nanorc
include /usr/local/share/nanorc/c.nanorc
include /usr/local/share/nanorc/clojure.nanorc
include /usr/local/share/nanorc/cmake.nanorc
include /usr/local/share/nanorc/coffeescript.nanorc
include /usr/local/share/nanorc/colortest.nanorc
include /usr/local/share/nanorc/conf.nanorc
include /usr/local/share/nanorc/conky.nanorc
include /usr/local/share/nanorc/creole.nanorc
include /usr/local/share/nanorc/csh.nanorc
include /usr/local/share/nanorc/csharp.nanorc
include /usr/local/share/nanorc/css.nanorc
include /usr/local/share/nanorc/csv.nanorc
include /usr/local/share/nanorc/cython.nanorc
include /usr/local/share/nanorc/dot.nanorc
include /usr/local/share/nanorc/dotenv.nanorc
include /usr/local/share/nanorc/elixir.nanorc
include /usr/local/share/nanorc/email.nanorc
include /usr/local/share/nanorc/erb.nanorc
include /usr/local/share/nanorc/etc-hosts.nanorc
include /usr/local/share/nanorc/fish.nanorc
include /usr/local/share/nanorc/fortran.nanorc
include /usr/local/share/nanorc/fsharp.nanorc
include /usr/local/share/nanorc/gemini.nanorc
include /usr/local/share/nanorc/genie.nanorc
include /usr/local/share/nanorc/gentoo.nanorc
include /usr/local/share/nanorc/git.nanorc
include /usr/local/share/nanorc/gitcommit.nanorc
include /usr/local/share/nanorc/glsl.nanorc
include /usr/local/share/nanorc/go.nanorc
include /usr/local/share/nanorc/gophermap.nanorc
include /usr/local/share/nanorc/gradle.nanorc
include /usr/local/share/nanorc/groff.nanorc
include /usr/local/share/nanorc/haml.nanorc
include /usr/local/share/nanorc/haskell.nanorc
include /usr/local/share/nanorc/hcl.nanorc
include /usr/local/share/nanorc/html.j2.nanorc
include /usr/local/share/nanorc/html.nanorc
include /usr/local/share/nanorc/i3.nanorc
include /usr/local/share/nanorc/ical.nanorc
include /usr/local/share/nanorc/ini.nanorc
include /usr/local/share/nanorc/inputrc.nanorc
include /usr/local/share/nanorc/jade.nanorc
include /usr/local/share/nanorc/java.nanorc
include /usr/local/share/nanorc/javascript.nanorc
include /usr/local/share/nanorc/js.nanorc
include /usr/local/share/nanorc/json.nanorc
include /usr/local/share/nanorc/keymap.nanorc
include /usr/local/share/nanorc/kickstart.nanorc
include /usr/local/share/nanorc/kotlin.nanorc
include /usr/local/share/nanorc/ledger.nanorc
include /usr/local/share/nanorc/lisp.nanorc
include /usr/local/share/nanorc/lua.nanorc
include /usr/local/share/nanorc/m3u.nanorc
include /usr/local/share/nanorc/makefile.nanorc
include /usr/local/share/nanorc/man.nanorc
include /usr/local/share/nanorc/markdown.nanorc
include /usr/local/share/nanorc/moonscript.nanorc
include /usr/local/share/nanorc/mpdconf.nanorc
include /usr/local/share/nanorc/mutt.nanorc
include /usr/local/share/nanorc/nanorc.nanorc
include /usr/local/share/nanorc/nginx.nanorc
include /usr/local/share/nanorc/nmap.nanorc
include /usr/local/share/nanorc/ocaml.nanorc
include /usr/local/share/nanorc/octave.nanorc
include /usr/local/share/nanorc/patch.nanorc
include /usr/local/share/nanorc/peg.nanorc
include /usr/local/share/nanorc/perl.nanorc
include /usr/local/share/nanorc/perl6.nanorc
include /usr/local/share/nanorc/php.nanorc
include /usr/local/share/nanorc/pkg-config.nanorc
include /usr/local/share/nanorc/pkgbuild.nanorc
include /usr/local/share/nanorc/po.nanorc
include /usr/local/share/nanorc/pov.nanorc
include /usr/local/share/nanorc/powershell.nanorc
include /usr/local/share/nanorc/privoxy.nanorc
include /usr/local/share/nanorc/prolog.nanorc
include /usr/local/share/nanorc/properties.nanorc
include /usr/local/share/nanorc/pug.nanorc
include /usr/local/share/nanorc/puppet.nanorc
include /usr/local/share/nanorc/python.nanorc
include /usr/local/share/nanorc/reST.nanorc
include /usr/local/share/nanorc/rpmspec.nanorc
include /usr/local/share/nanorc/ruby.nanorc
include /usr/local/share/nanorc/rust.nanorc
include /usr/local/share/nanorc/scala.nanorc
include /usr/local/share/nanorc/sed.nanorc
include /usr/local/share/nanorc/sh.nanorc
include /usr/local/share/nanorc/sieve.nanorc
include /usr/local/share/nanorc/sls.nanorc
include /usr/local/share/nanorc/sparql.nanorc
include /usr/local/share/nanorc/sql.nanorc
include /usr/local/share/nanorc/svn.nanorc
include /usr/local/share/nanorc/swift.nanorc
include /usr/local/share/nanorc/systemd.nanorc
include /usr/local/share/nanorc/tcl.nanorc
include /usr/local/share/nanorc/tex.nanorc
include /usr/local/share/nanorc/toml.nanorc
include /usr/local/share/nanorc/ts.nanorc
include /usr/local/share/nanorc/twig.nanorc
include /usr/local/share/nanorc/vala.nanorc
include /usr/local/share/nanorc/verilog.nanorc
include /usr/local/share/nanorc/vi.nanorc
include /usr/local/share/nanorc/x11basic.nanorc
include /usr/local/share/nanorc/xml.nanorc
include /usr/local/share/nanorc/xresources.nanorc
include /usr/local/share/nanorc/yaml.nanorc
include /usr/local/share/nanorc/yum.nanorc
include /usr/local/share/nanorc/zig.nanorc
include /usr/local/share/nanorc/zsh.nanorc
include /usr/local/share/nanorc/zshrc.nanorc

@BlakeGardner
Copy link
Author

@docdyhr I've updated the gist with your new list of includes

@atmonshi
Copy link

atmonshi commented May 8, 2021

thank you so much, worked perfectly for me on mac OS

@hacker1024
Copy link

hacker1024 commented May 10, 2021

Why does every file need to be listed? The following works for me:

brew install nano
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

@lorthirk
Copy link

+1 on @hacker1024 comment. single include with *.nanorc works for me as well.

@regexyl
Copy link

regexyl commented Jun 20, 2021

Thanks this worked! Is there any reason why the syntax highlighting only applies to nano, not sudo nano though?

@lorthirk
Copy link

Thanks this worked! Is there any reason why the syntax highlighting only applies to nano, not sudo nano though?

In order to have it for sudo nano you have to edit the .nanorc for the root user

@regexyl
Copy link

regexyl commented Jun 20, 2021

@lorthirk That makes sense. Thanks for the help!

@romantech
Copy link

romantech commented Aug 22, 2021

Why does every file need to be listed? The following works for me:

brew install nano
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

This is nice! It works fine for me. Thank you!

@secfb
Copy link

secfb commented Oct 4, 2021

Mac OSX Big Sur
nano version:5.8

brew install nano 
echo 'include "/opt/homebrew/Cellar/nano/5.8/share/nano/*.nanorc"'>> ~/.nanorc

@robert-duplock-adg
Copy link

robert-duplock-adg commented Dec 13, 2021

Thanks @secfb (above), it worked beautifully on an M1 Mac running Monterery & zsh.
I ran:

brew install nano 
# Restart terminal
nano -V 
# Note the version number
echo 'include "/opt/homebrew/Cellar/nano/NANO_VERSION_NUMBER/share/nano/*.nanorc"'>> ~/.nanorc
# EG: echo 'include "/opt/homebrew/Cellar/nano/5.9/share/nano/*.nanorc"'>> ~/.nanorc

@tagplus5
Copy link

Brew creates symlink so you don't need set nano version number:
echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

@bbuchheim
Copy link

or for Apple Silicon: echo 'include "/opt/homebrew/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

@BlakeGardner
Copy link
Author

Brew creates symlink so you don't need set nano version number: echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

Thanks @tagplus5, updated the gist for Apple Silicon

@phillco
Copy link

phillco commented Apr 7, 2022

or for Apple Silicon: echo 'include "/opt/homebrew/Cellar/nano//share/nano/.nanorc"' >> ~/.nanorc

Thanks! It's weird that you have to encode the wildcard for the version and you don't get a nice symlink like /usr/local/share/nano/ on Intel Macs. Hopefully there's only one version there at a time!

@eureka-cpu
Copy link

Brew creates symlink so you don't need set nano version number: echo 'include "/usr/local/share/nano/*.nanorc"' >> ~/.nanorc

Thanks @tagplus5, updated the gist for Apple Silicon

This worked for me, brew install nano and then this command. Thanks! (on M1 MBP)

@IoannisTM
Copy link

for me what worked is

echo "include /opt/homebrew/Cellar/nano/6.3/share/nano/*.nanorc" >> ~/.nanorc

@up9cloud
Copy link

brew install nano
echo include "$(brew --prefix nano)/share/nano/*.nanorc" >> ~/.nanorc

or

brew install nano
brew install nanorc
echo include "$(brew --prefix nanorc)/share/nanorc/*.nanorc" >> ~/.nanorc

@x86txt
Copy link

x86txt commented Nov 8, 2022

latest is:

echo "include /opt/homebrew/Cellar/nano/6.4/share/nano/*.nanorc" >> ~/.nanorc

@x86txt
Copy link

x86txt commented Nov 27, 2022

For macOS Ventura:

brew install nano nanorc

echo "include /opt/homebrew/Cellar/nano/7.0/share/nano/*.nanorc" >> ~/.nanorc

Note you might want to take this opportunity to just start with a clean .nanorc if you've been upgrading nano and nanorc frequently.

mv ~/.nanorc ~/.nanorc.orig && echo "include /opt/homebrew/Cellar/nano/7.0/share/nano/*.nanorc" > ~/.nanorc

@RobThree
Copy link

RobThree commented Feb 15, 2023

@x86txt: Replace the …/nano/7.0/share/… part with …/nano/*/share/… so you don't have to keep updating your .nanorc file every time nano updates to a newer version.

@dhorster
Copy link

Worked for me:

brew install nano nanorc
echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

@s-ota-66
Copy link

Worked for me:

brew install nano nanorc
echo 'include "/opt/homebrew/share/nanorc/*.nanorc"' >> ~/.nanorc

macOS Ventura 13.2.1
Homebrew 4.0.13

@BlakeGardner
Copy link
Author

Thanks, updated the gist @s-ota-66

@benolot
Copy link

benolot commented Apr 22, 2023

Thanks all for the guide! Can confirm current version is working on 13.3.1

@ryenus
Copy link

ryenus commented May 11, 2023

Better to use $(brew --prefix) to work with both Intel & ARM chips

brew install nano nanorc
echo 'include "'"$(brew --prefix)"'/share/nanorc/*.nanorc"'

@nospam2k
Copy link

nospam2k commented Nov 24, 2023

echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

Works for Sonora

@firstrecall
Copy link

firstrecall commented Nov 29, 2023

echo 'include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc

Probably it would be better to use

echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

so in such case it will use the right path depends on if mac uses Intel or Apple Silicon

@tobsn
Copy link

tobsn commented May 13, 2024

as of today, may 13th 2024, the following works without issues on sonoma 14.4.1 with and brew 4.2.21:

brew install nano
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc

thanks everyone for keeping this going :)

@BlakeGardner
Copy link
Author

Updated the gist thanks @tobsn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment