The GNU of Life, the Universe and Everything

June 23, 2007

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

Filed under: nano — Tags: , , , , — Pedro Carvalho @ 8:02 pm

I have been using nano as my favorite 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 use the Control (Ctrl) key, displayed in the help and shortcut lists as ^; the Meta key, displayed as M; or the Escape (Esc) key.”

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

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 

^K : cut text (if nothing is selected, it cuts a line
^U : paste the cut text, or undo the justification
^J : Justify the paragraph
Meta+j : justify the whole buffer

Meta+} : indent
Meta+{ : unindent

Meta+a : set/unset the mark ( similar to ^space in emacs)
^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

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

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

About these ads

13 Comments »

  1. [...] config file, try to explain parts of it and set the syntax highlight on. See the first part forshortcuts . You can use the sample nanorc from /usr/share/nano/ , a copy from /etc/nanorc, or even from the [...]

    Pingback by Nano - Shortcuts, syntax highlight and .nanorc config file - pt2 « The GNU of Life, the Universe and Everything — June 23, 2007 @ 8:04 pm

  2. 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 :)

    Comment by Rui — June 23, 2007 @ 8:54 pm

  3. very interesting, but I don’t agree with you
    Idetrorce

    Comment by Idetrorce — December 15, 2007 @ 12:41 pm

  4. Thanks for this list, very useful.

    Comment by Nicolas — November 14, 2008 @ 9:50 am

  5. [...] I found this VERY insightful blog post on nano’s advanced features. Random PostsSubversion: checkout a [...]

    Pingback by nano editor keyboard shortcuts | Zen of Linux — March 2, 2009 @ 5:41 pm

  6. [...] found a great two part articles on the .nanorc file.  Here is the nano documentation.  And a copy of my .nanorc [...]

    Pingback by Dubayou[dot]com | Where i like to think. » Nano on the command line. — November 27, 2009 @ 10:30 pm

  7. Very neat & useful article!

    Comment by Kotzbrocken — October 20, 2010 @ 9:03 am

    • thank you :)

      Comment by Pedro Carvalho — October 20, 2010 @ 10:47 am

  8. [...] have a thing for code and colours. Let it be lolcode, lpsolve syntax for whatever the editor i’m using at the time, i have to tweak [...]

    Pingback by Syntax hightlight theme for Ruby/Rails/Haml in Aptana « The GNU of Life, the Universe and Everything — March 8, 2012 @ 1:53 pm

  9. 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

    Comment by umek1 — March 15, 2012 @ 10:08 am

    • 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

      Comment by Pedro Carvalho — March 15, 2012 @ 10:21 am

  10. [...] I found this VERY insightful blog post on nano’s advanced [...]

    Pingback by nano editor keyboard shortcuts ● Linux goes Zen — March 19, 2012 @ 6:02 pm

  11. Well, that’s cool, but i think you choose better text color pattern :)

    Comment by Ozan Y. — October 28, 2013 @ 10:24 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: