Tag Archives: text editing

Nano as a Focus Oriented Editor

One of my previous blog posts dealt with using Markdown for writing. Once its clear what markup to write in, another question pops up: which of the humongous number of text editors to choose? I’ve been sniffing around for an editor that fits me for quite some time now and I feel like I’ve tried them all: Gedit, Geany, Notepad++, Moe, Vi, Vim, Emacs, Sublime, Brackets, Atom, Light Table… and Nano.

nano

Obviously not all, but still. I find it somehow paradoxical that after all the spoiling from editors that are feature packed to the roof, I ended up with Nano. And with ended up I mean: I haven’t changed my editor for a while, I’m quite happy about the setup, I’m able to work efficiently and when I try a different editor, I’m naturally drawn back.

With all those shiny next generation editors around, why choose an editor whose history reaches to 1990s and which can be operated only from the command line? Well, because Nano helps me to solve these problems quickly and easily:

 

 

  1. Focus. This has been a major problem for me. No matter how good your editor is, if you get distracted by the web browser lurking in the background, you still don’t get much done. This is why I turned to command-line editors in the first place. Having a full screen terminal, or being on a separate tty really helps to channel the attention. And if some distractions still remain, you can go as far as slapping your old useless PC with a headless system and unplugging it from the network. Still feel like in the need of a new simplistic focus oriented editor?

  2. Keyboard utilization. Being a command line editor, you can rest assured that Nano won’t force you to constantly oscillate between keyboard and mouse. And it gets even better, there are keyboard shortcuts for all actions using the alphanumeric keys. This will surely please all the touch typing keyboard ninjas out there. I know it makes me happy.

  3. Custom syntax highlighting. Need one? Know regular expressions? No problem then. Just write the rules into the .nanorc file and you’re done. This comes really handy for me as I use the Pandoc’s version of Markdown, which is usually not well supported by the out-of-the-box syntax highlighting in other editors. Here’s the custom syntax highlighting I use:


syntax "markdown" ".txt$" ".md$" ".markdown$"
# Emphasis
color magenta "[^]_"
color magenta "*[^*]
*"
# Strong emphasis
color brightmagenta "**[^*]**"
color brightmagenta "[_]*"
# Underline headers
color yellow "^====(=
)"
color yellow "^----(-)"
# Hash headers
color yellow "^#.
"
# Inline HTML tags
color brightblue start=""
# Inline footnotes
color green start="\^[" end="]"
# References
color brightgreen "@([a-z]|[0-9])+"
# Links
color blue "[.](.)"
# Code spans
color cyan "[^]*`"
# Quotations, lists, horizontal lines, newlines and footnote marks
color brightblue "^> "
color brightblue "^- "
color brightblue "^* "
color brightblue "^[1-9][0-9]?[0-9]?. "
color brightblue "^---"
color brightblue "\$"
color brightblue "[\^[1-9][0-9]?[0-9]?]"
color brightblue "[\^]"
# Todo
color ,red "TODO"
# Trailing whitespace
color ,red " +$"

For more information on how to set up the nanorc config file, see this page.

Okay, maybe I turned this post into an advertisement for Nano. Luckily, it’s free and that should drive the accusations away :) To balance this, I will add one thing that I miss in Nano and that is snippet support. But, there is a workaround for this, just follow these steps:

  1. For each snippet you want to have, create a text file that contains only it.

  2. Put them in a folder, and open your other files from within that folder (it will make this folder the default one Nano looks into when opening new files).

  3. This step applies only if you have enabled the support for multiple buffers: Once you have opened a file you want to edit, hit alt-F to tell Nano that the contents of files you choose to open should be inserted into the current buffer (this setting lasts until you quit Nano or until you hit alt-F again).

  4. Now if you need one of the snippets, hit ctrl-R to open a file, type the first few letters of the file which contains the desired snippet, complete it with Tab and hit Enter.

And that’s it, now you have the snippet at cursor position. It’s not perfect, there are no placeholders for cursor positions, but well… for Markdown with occasional HTML comments? Good enough.

Okay, enough rambling from me. To the machines!

Advertisements