nano keystroke configuration

A post about a simple text editor might seem unnecessary, but I still meet junior admins who only think about vim or emacs. But nano has its place - it's installed on just about every system I come across, it's easy to use and it's quite capable. And with a little effort it can be reconfigured to use Windows-style keystrokes.



## nano is a terminal-based text editor; it was originally a pico clone; pico was the editor in the e-mail client pine which was a follow-on of elm; nano was once named tip which is a recursive acronym for tip isn't pico

! links
http://www.nano-editor.org/


## nano's command line syntax is straightforward:

nano [<option> ...] <file> ...

! http://manpages.ubuntu.com/nano
! http://manpages.ubuntu.com/nanorc

! nano presents an empty file buffer if no file is specified on the command line;
! multiple files may be specified and edited if the multibuffer option is used


## nano options may be configured via the command line or via an rc file using the set/unset commands; key bindings may only be configured via an rc file using the bind/unbind commands; nano reads the rc file /etc/nanorc followed by ~/.nanorc

! for simple option setting the command line is sufficient e.g. one could enable some useful options by running nano -FSET4

-F (--multibuffer)
       Enable multiple file buffers, if available.
-S (--smooth)
       Enable smooth scrolling.  Text will scroll line-by-line, instead of the usual chunk-by-chunk behavior.
-E (--tabstospaces)
       Convert typed tabs to spaces.
-T cols (--tabsize=cols)
       Set the size (width) of a tab to cols columns.  The value of cols must be greater than 0.  The default value is 8.

! options are unset by default; the -I option disables rc file processing and is useful for testing
! a comprehensive /etc/nanorc file is installed with nano

! if nano encounters an error in an rc file it will display e.g.

Error in /etc/nanorc on line 341: Could not map name "wheris" to a function

Press Enter to continue starting nano.


## nano relies on normal keys as well as ctl and meta key combinations; the meta key is typically the alt key; if alt is not available for some reason then the meta key is the esc key; some of the default nano key bindings are quite traditional whereas others are rather idiosyncratic but are generally mnemonically based

! in gnome terminal alt is the menu key but the keystroke is passed through to an application if it is not being used for a gnome terminal menu
! below are the default key bindings in the main editing screen; in various menus and other contexts ctl-x is typically used to exit and ctl-c to cancel

ctl-r         read i.e. open file into current buffer, or into new buffer in multibuffer mode; press enter for new empty buffer
ctl-o         writeout i.e. save file
ctl-x         exit i.e. quit; also exits from buffer in multibuffer mode; prompts for writeout/save
ctl-g         get help/aid/assistance

enter, ctl-m  newline
bksp, ctl-h   delete previous character
del, ctl-d    delete current character
left, ctl-b   backward character
right, ctl-f  forward character
home, ctl-a   beginning of line
end, ctl-e    end of line
up, ctl-p     previous line
down, ctl-n   next line
pgup, ctl-y   previous page
pgdn, ctl-v   next page

m-space       previous word
ctl-space     next word
alt-\         beginning of file
alt-/         end of file
ctl-c         display cursor position
ctl-/         go i.e. jump to line and column

ctl-^         set/unset mark; or alt-a
alt-^         copy marked, or copy line if nothing marked; actually alt-6 i.e. do not need shift key
ctl-k         cut marked, or cut line if nothing marked, or cut to end of line if cut-to-end is enabled using alt-k
ctl-u         paste cut or copied
alt-t         cut to end of file

ctl-w         search
alt-w         search again
alt-r         search and replace

alt-<         previous file buffer; actually alt-, i.e. do not need shift key
alt->         next file buffer; actually alt-. i.e. do not need shift key

alt-x         toggle bottom help display
alt-y         toggle color syntax highlighting; colors configured via /usr/share/nano/*.nanorc files
alt-c         toggle cursor position display
alt-d         toggle dos/unix format option at writeout/save prompt
alt-k         toggle cut to end of line

ctl-t         show file list at read/open prompt
ctl-x         prompt for external command to execute at read/open prompt and insert output

ctl-z         suspend to shell; use fg to return


## nano can be given a more mainstream user interface by appending a handful of lines to /etc/nanorc or ~/.nanorc; the strategy used is to leave the traditional cursor keys alone and rebind their ctl equivalents in more mainstream ways

! some functions have both commands and toggle keys e.g. nohelp and nohelp, const and constupdate, whitespace and whitespacedisplay
! whitespacedisplay doesn't seem to work
! help screens nicely display the new key bindings
! apparently there is no way in text mode to distinguish between e.g. left and ctl-left so no way to bind cursor keys
! use # for comment lines

keith@dev$ cat ~/.nanorc
set morespace
set multibuffer
set nohelp            # perhaps comment out until comfortable
set quickblank
set regexp
set smooth
set suspend
set tabsize 4
set tabstospaces
set undo             # undo/redo is an experimental feature; buggy?

unbind ^K main
unbind ^U main
unbind ^W main

bind ^O insert main
bind ^S writeout main
bind ^Q exit main
bind ^A help main

bind ^P prevword main
bind ^N nextword main
bind ^B firstline main
bind ^E lastline main
bind ^L curpos main
bind ^J gotoline main

bind ^Space mark main
bind ^X cut main
bind ^C copytext main
bind ^V uncut main

bind ^F whereis main
bind ^G searchagain main
bind ^H replace main

bind ^Z undo main
bind ^Y redo main

bind M-A nohelp main
bind M-L constupdate main

bind M-Z suspend main

! the above configuration yields:

ctl-o         read i.e. open file into current buffer, or into new buffer if multiple buffers are enabled
ctl-s         writeout i.e. save file
ctl-q         exit i.e. quit; also exits from a file buffer if multiple file buffers are enabled; prompts for writeout/save
ctl-a         get help/aid/assistance

enter, ctl-m  newline
bksp          delete previous character
del           delete current character
left          backward character
right         forward character
home          beginning of line
end           end of line
up            previous line
down          next line
pgup          previous page
pgdn          next page

ctl-p         previous word
ctl-n         next word
ctl-b, alt-\  beginning of file
ctl-e, alt-/  end of file
ctl-l         display cursor position
ctl-j         go i.e. jump to line and column

ctl-space     set/unset mark
ctl-c         copy marked, or copy line if nothing marked; actually alt-6 i.e. do not need shift key
ctl-x         cut marked, or cut line if nothing marked, or cut to end of line if cut-to-end is enabled using alt-k
ctl-v         paste cut or copied
ctl-d         cut to end of file

ctl-f         search
ctl-g         search again
ctl-h         search and replace

ctl-z         undo
ctl-y         redo

alt-<         previous file buffer; actually alt-, i.e. do not need shift key
alt->         next file buffer; actually alt-. i.e. do not need shift key

alt-a         toggle bottom help display
alt-y         toggle color syntax highlighting; colors configured via /usr/share/nano/*.nanorc files
alt-l         toggle cursor position display
alt-d         toggle dos/unix format option at writeout/save prompt
alt-k         toggle cut to end of line

ctl-t         show file list at read/open prompt
ctl-x         prompt for external command to execute at read/open prompt and insert output

alt-z         suspend to shell; use fg to return
Current rating: 5

Categories

Tags

Authors

Feeds

RSS / Atom