written by Eric J. Ma on 2017-09-11 | tags: programming nano text editor coding snippets
Much as I've embraced the Atom text editor, there are times when the GUI isn't accessible to us, and we are forced to use a Terminal-based text editor.
Now, I'm not one of those crazy types who use emacs or vim - those are the real seasoned pros. (I still don't know how to exit vim, btw.) As such, my terminal editor of choice remains the venerable nano. Here's some hacks that I recently figured out, to make text editing much easier in nano.
This is such a big one! Syntax highlighting seriously helps a ton. If you're on a Mac, make sure you install homebrew's version of nano - you can look at my dotfiles or run the command:
$ brew install nano
Then, edit your ~/.nanorc file to look something like this:
include /usr/local/share/nano/python.nanorc # gives you Python syntax highlighting
include /usr/local/share/nano/sh.nanorc # gives you bash shell syntax highlighting
Next time you use nano (from your user account), syntax highlighting should be enabled!
You can find a sample .nanorc file on my GitHub dotfiles repository
Here's a laundry list of keyboard shortcuts I've muscle-memorized:
Ctrl-x: quits. There will be a prompt to save the file if it's been modified.Ctrl-x-y-Enter.Ctrl-v scrolls down a pageCtrl-y scrolls up a pageCtrl-w searches the document for a term that you type in (think "where")Ctrl-k cuts the lineCtrl-u pastes a cut lineCtrl-^ (i.e. Ctrl-Shift-6 on macOS keyboards) starts a "select" cursor.Ctrl-c cancels any commands that are 'active'.Ctrl-o activates the "save file" dialogue - lets you save your state without quitting.nano, being not as fancy as vim or emacs, means it doesn't have the concept of sessions. Doesn't matter - use tmux to persist!
All-in-all, the biggest one that aids in writing on a terminal editor is syntax highlighting. I wrote this blog post in nano, and being able to visually see different parts of my text highlighted according to their meaning has made writing much easier.
@article{
ericmjl-2017-nano-text-editor-hacks,
author = {Eric J. Ma},
title = {nano text editor hacks},
year = {2017},
month = {09},
day = {11},
howpublished = {\url{https://ericmjl.github.io}},
journal = {Eric J. Ma's Blog},
url = {https://ericmjl.github.io/blog/2017/9/11/nano-text-editor-hacks},
}
I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.
# TODO(eric): learn how to learn anything. feb 2027.
If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!