Nano – Shortcuts, syntax highlight and nanorc config file – pt1

I have been using nano as my favourite console editor (i use emacs/kate for the rest) for some time now. It’s simplicity, the speed and usefulness of it made it what it is. But recently, i’ve been trying to find out more features that i might been missing. One of those were the shortcuts. The other was syntax highlighting! Meanwhile, the things i discovered!

Before we start, here’s some useful links:

Nano homepage
Online Manual
the fine Man Page

So let’s start with the basic shortcuts!

“Special functions displayed in the help and shortcut lists use:

  • the Control (Ctrl) key, as ^;
  • the Meta key ( Alt ) is displayed as M;
  • or the Escape as Esc key.

The help system in nano is available by pressing ^G.

Copy, Paste, Cut and selection

( Thanks to sweenist for the copy text shortcut! )
M+6 : copy text (if nothing is selected, it copies the line )
^K : cut text (if nothing is selected, it cuts the line )
^U : paste the cut text, or undo the justification
^J : Justify the paragraph
Meta+j : justify the whole buffer

Meta+a : set/unset the mark ( similar to ^space in emacs)


Meta+} : indent
Meta+{ : unindent


^space : move forward one word
Meta+space : move backward one word

Page up/down : scroll up/down half(?) buffer

^W ^Y : jump to the first line
^W ^V : jump to the last line

^Y : jump to the Previous Page (up almost “one” buffer”)
^V : jump to the Next Page (down almost “one” buffer”)

^W ^Y : jump to the first line
^W ^V : jump to the last line

Meta-< or (Meta-,) Switch to the previous file buffer
Meta-> or (Meta-.) Switch to the next file buffer

Where is
^W : allows to search for an expression

^W expr Meta+w : find the next match
^W ^T numline or Meta+g numline, numcol : will jump to that line number
^W Meta+R expr1 RET expr2 : will replace expr1 with expr2. It asks for the confirmation

Replace this instance?
 Y Yes           A All
 N No           ^C Cancel 

So, that might be enough for your daily tasks. See the next part for more nano’s details.
Part 2: nanorc and syntax hightlight

18 thoughts on “Nano – Shortcuts, syntax highlight and nanorc config file – pt1

  1. I also use nano, it is really great.And its console based so extremely portable. Long live ncurses :)
    All the best to you and your blog :)

  2. what’s .ini mean?? i don’t understand.. (sorry if my word are wrong)

    [quote]This is useful for those debian people.

    ## syntax highlighting for /etc/apt/sources.list
    ## syntax “apt/sources.list” “sources\.list(\.old|~)?$”
    # component
    color brightmagenta “^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+ .+$”
    # distribution
    color brightred “^deb(-src)? ((http|file|ftp):/[^ ]+|cdrom:\[[^\]]+\]/|cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/) [^ ]+”
    # URI
    color brightgreen “(http|file|ftp):/[^ ]+”
    # cdroms
    # [^\]] does not work…
    color brightgreen “cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/”
    # deb / deb-src
    color cyan “^deb”
    color brightblue “^deb-src”
    # comments
    color brightyellow “#.*”

    config files (.ini)

    # ini highlighting
    syntax “ini” “\.ini(\.old|~)?$”
    # values
    color brightred “=.*$”
    # equal sign
    color green “=”
    # numbers
    color brightblue “-?[0-9\.]+\s*($|;)”
    # ON/OFF
    color brightmagenta “ON|OFF|On|Off|on|off\s*($|;)”
    # sections
    color brightcyan “^\s*\[.*\]”
    # keys
    color cyan “^\s*[a-zA-Z0-9_\.]+”
    # comments
    color brightyellow “;.*$” [/quote/

    what is this? i mean, how to more shining with this code..
    create .ini.nanorc? or ??
    sorry i’am newbie :D

    1. hi umek,

      exactly, create a ini.nanorc , and add “include /path/to/ini.nanorc” in your ~/.nanorc

      nano will match everything ending in .ini (and .ini.old or even .ini~ ) with those syntax highlights.

      to use the “sources.list” highlighting, follow the same procedure but don’t forget to uncomment this line like so:

      syntax “apt/sources.list” “sources\.list(\.old|~)?$”

      have fun with the shiningness! :D

  3. Hi my friend! I want to say that this article is
    awesome, great written and include almost all important infos.
    I would like to see extra posts like this .

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s