27 Oct 2007
Using Unicode in GNU nano on OS X
After an afternoon of fiddling, I’ve managed to get GNU nano working on my Mac with full UTF-8 support. Although I’m monolingual, this allows the use of nice things like “smartquotes” and emdashes, right in the actual text file.
The version of nano that ships with Mac OS 10.4 doesn’t support Unicode. In order to get it, you’ll need to install Darwinports and then install nano through it, explicitly enabling UTF-8 as you do so. I recommend using the command
sudo port install nano +utf8 +wrap +mouse +color
This enables not only UTF-8, but also support for automatic line-wrapping (which can be disabled on command and is disabled by default for root, for ease in editing config files that don’t like hardwrapped lines), mouse, and color.
Once Darwinports does its thing, you’ll probably want to rename the old
version of nano, located in /usr/bin, to something like ‘nano-1.2.4’,
and then make a symlink from /usr/bin/nano to the newly installed version
in /opt/local/bin/nano. This isn’t required if you have /opt/local/bin
in your PATH, but it’s just nice to do in case other users don’t. (Just
sudo ln -s /opt/local/bin/nano /usr/bin/nano)
To make sure it worked, type
nano --version and make sure it shows
version 2.0.6 or newer, and that
--enable-utf8 is shown as one of the
compiled options. On my system, the following is shown:
$ nano --version GNU nano version 2.0.6 (compiled 17:26:26, Oct 27 2007) Email: email@example.com Web: http://www.nano-editor.org/ Compiled options: --disable-nls --disable-speller --disable-wrapping-as-root --enable-color --enable-nanorc --enable-utf8
Now, there’s one final step: you need to set your LANG environment
variable to a locale that specifies UTF-8, or nano won’t use it. This is
as easy as adding
export LANG=en_US.UTF-8 to the bottom of your
.bash_profile file. You’ll need to close and reopen your terminal
window or SSH session in order for this to take effect.
To test, open nano and try using the curly-open-quote character ( Option-[ ). If you see a quote, it worked. If you see a bunch of question marks, something’s wrong.
This entry was converted from an older version of the site; if desired, it can be viewed in its original format.