Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Syntax highlighting in nano on Mac OS
# Last updated March, 2022 for Apple silicon Macs
# Install Homebrew if you don't already have it: https://brew.sh
# install nano from homebrew
brew install nano
# update your nanorc file
echo 'include "/opt/homebrew/Cellar/nano/*/share/nano/*.nanorc"' >> ~/.nanorc
# close and re-open your terminal and you'll have syntax highlighting
@lhaeberle
Copy link

lhaeberle commented Jun 2, 2017

This is my macOS sierra work around:

  1. installed nano using brew: # this fails but find files in /usr/local/Cellar/nano/2.8.4/…
    brew install nano

  2. created an alias: # works well for me since i'm using some aliases
    alias nano='/usr/local/Cellar/nano/2.8.4/bin/nano --smooth --tabstospaces --linenumbers‘

  3. created file .nanorc in my (and su's) home-directory:

set mouse
include "/usr/local/Cellar/nano/2.8.4/share/nano/*.nanorc

@JMV2112
Copy link

JMV2112 commented Oct 12, 2017

If anyone is still having either of these issues

Command "magic" not understood
Command "header" not understood

make sure to run

source ~/.bash_profile

to reload the PATH in your current session.

@tjt263
Copy link

tjt263 commented Feb 10, 2018

All you need to do once it's installed is brew --link nano.

@JBallin
Copy link

JBallin commented Feb 12, 2018

I had issues with above solutions but laid out how I did it here: https://stackoverflow.com/a/48752837/4722345

@supriyo-biswas
Copy link

supriyo-biswas commented Jun 1, 2018

It's also possible to use a wildcard instead of listing all the files:

include /usr/local/share/nano/*.nanorc

@chaim1221
Copy link

chaim1221 commented Sep 20, 2018

yeah wildcard would have been helpful at the top, lol...

but all this talk about not working on High Sierra, it was literally as simple as the first two commands idk what y'all did

@brandonimitch
Copy link

brandonimitch commented Feb 14, 2019

Doesn't work

@fevangelou
Copy link

fevangelou commented Mar 24, 2019

Thanks for the tips from the original post and the comments following.

Since Nano Editor v4.0 was released today, I made a bash script to simplify installation on the Mac, with syntax highlighting enabled.

https://gist.github.com/fevangelou/be744753730e86b8783fd481f311a7c9

Enjoy :)

@a3igner
Copy link

a3igner commented Apr 10, 2019

I tried this but gets an error from nanorc

Cannot find directory

Include ~/.nanorc/Syntax

Even though it does exist! I tried every other possible way to write the include statement

What is wrong? I managed to find out after some digging and will answer this here in case other people have the same problem as me.

nano -V

are we running 4.0 or some old version of nano that comes with OSX?

sudo nano /etc/paths

does it look like this?

GNU nano 4.0 /etc/paths

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~/Library/Python/2.7/bin/

then change the order and copy the row for /usr/local/bin to the top as such

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
~/Library/Python/2.7/bin/

Voila. now nano -V shows up as Vers 4.0 (use new terminal window). and all the syntax is loaded correctly.

@peterdk
Copy link

peterdk commented Oct 13, 2019

Just installing from brew works perfectly here on 10.14.

@Julian-Nash
Copy link

Julian-Nash commented Feb 17, 2020

Create a ~/.nanorc file and paste the include list above.

In your ~/.bash_profile:

alias nano=./usr/local/bin/nano

Next time you open nano you should see the syntax highlighting

@aurimasniekis
Copy link

aurimasniekis commented Apr 16, 2020

Updated .nanorc file with latest syntaxes from brew

include /usr/local/share/nano/asm.nanorc
include /usr/local/share/nano/autoconf.nanorc
include /usr/local/share/nano/awk.nanorc
include /usr/local/share/nano/c.nanorc
include /usr/local/share/nano/changelog.nanorc
include /usr/local/share/nano/cmake.nanorc
include /usr/local/share/nano/css.nanorc
include /usr/local/share/nano/debian.nanorc
include /usr/local/share/nano/default.nanorc
include /usr/local/share/nano/elisp.nanorc
include /usr/local/share/nano/fortran.nanorc
include /usr/local/share/nano/gentoo.nanorc
include /usr/local/share/nano/go.nanorc
include /usr/local/share/nano/groff.nanorc
include /usr/local/share/nano/guile.nanorc
include /usr/local/share/nano/html.nanorc
include /usr/local/share/nano/java.nanorc
include /usr/local/share/nano/javascript.nanorc
include /usr/local/share/nano/json.nanorc
include /usr/local/share/nano/lua.nanorc
include /usr/local/share/nano/makefile.nanorc
include /usr/local/share/nano/man.nanorc
include /usr/local/share/nano/mgp.nanorc
include /usr/local/share/nano/mutt.nanorc
include /usr/local/share/nano/nanohelp.nanorc
include /usr/local/share/nano/nanorc.nanorc
include /usr/local/share/nano/nftables.nanorc
include /usr/local/share/nano/objc.nanorc
include /usr/local/share/nano/ocaml.nanorc
include /usr/local/share/nano/patch.nanorc
include /usr/local/share/nano/perl.nanorc
include /usr/local/share/nano/php.nanorc
include /usr/local/share/nano/po.nanorc
include /usr/local/share/nano/postgresql.nanorc
include /usr/local/share/nano/pov.nanorc
include /usr/local/share/nano/python.nanorc
include /usr/local/share/nano/ruby.nanorc
include /usr/local/share/nano/rust.nanorc
include /usr/local/share/nano/sh.nanorc
include /usr/local/share/nano/spec.nanorc
include /usr/local/share/nano/tcl.nanorc
include /usr/local/share/nano/tex.nanorc
include /usr/local/share/nano/texinfo.nanorc
include /usr/local/share/nano/xml.nanorc

@BlakeGardner
Copy link
Author

BlakeGardner commented Apr 16, 2020

@aurimasniekis thanks, I've updated the gist to reflect the new file list

@valosekj
Copy link

valosekj commented Nov 17, 2020

My set-up on MacOS Catalina (10.15.7) with zsh

Install nano from homebrew

brew install nano

After it, I have two versions of nano:

$ ls /usr/local/bin/nano
/usr/local/bin/nano           # installed from brew
$ ls /usr/bin/nano      
/usr/bin/nano                 # original one

Create alias to nano installed from brew inside my zsh config file:

$ sudo vim /etc/zshrc
alias nano='/usr/local/bin/nano'

Create nanorc file and include which languages you want to highlight:

nano ~/.nanorc

@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

BlakeGardner commented Apr 29, 2021

@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

lorthirk commented May 31, 2021

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

@gilite
Copy link

gilite 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

lorthirk commented Jun 20, 2021

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

@gilite
Copy link

gilite 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

tagplus5 commented Dec 28, 2021

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

@bbuchheim
Copy link

bbuchheim commented Jan 12, 2022

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

@BlakeGardner
Copy link
Author

BlakeGardner commented Mar 25, 2022

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

eureka-cpu commented Jun 19, 2022

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)

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