| Author: | John M. Gabriele |
|---|---|
| Date: | May 2007 |
| Back to: | homepage |
This is a quick help sheet for the GNU nano text editor.
If any of the features below fail to work, it's most likely because your version of nano was not configured/built to support that feature. See below for details on configuring a nano build.
| -Y name | Tells nano to use a given syntax highlight pattern (from ~/.nanorc) |
| -v | View file only (read-only mode) |
| -V | Shows version and build info. |
GNU nano uses the same key combos as pico -- with many additions.
For items with stars (*) in the table below, see the notes under the table.
Note
Any commands that give you a secondary prompt (like Ctrl-o, Ctrl-r, Ctrl-w, Ctrl-\, and Ctrl-_) all have additional subcommands listed at the bottom of the screen. They also have a mini help screen associated with them -- hit Ctrl-g while in them to access it. Hit Ctrl-x to exit these help screens, and Ctrl-c if you want to cancel the operation you started with.
Update: As of v2.1.0 nano, users may now change keybindings for most actions in the editor.
Most common actions are accessed via Ctrl-some_key.
Alt-some_key is often used for toggling various editor features.
Alt-some_key is sometimes used for fancier editor features (like hopping to next/previous paragraph or go to matching bracket).
Often, using Shift is optional for Alt-some_key combos (ex. Alt-6 and Alt-^ do the same thing). This also happens with Ctrl-6/Ctrl-^.
Sometimes Alt-some_key does an amplified version of Ctrl-some_key, like Ctrl-j/Alt-j.
In one odd case, using Alt-some_key reverses what Ctrl-some_key does: Ctrl-Space/Alt-Space. But that's a bit odd.
If you like using the named keys on your keyboard, there's a number of key combos you might not often use:
You can use |
instead of |
|---|---|
Home |
Ctrl-a |
End |
Ctrl-e |
PgUp |
Ctrl-y |
PgDn |
Ctrl-v |
Arrow keys |
Ctrl-{f,b,n,p} |
Tab |
Ctrl-i |
Backspace |
Ctrl-h |
Delete |
Ctrl-d |
Return |
Ctrl-m |
Currently, key actions cannot be remapped.
| help | Ctrl-g |
| show cur cursor loc, or cancel search | Ctrl-c |
| toggle show cursor location | Alt-c |
| exit | Ctrl-x |
| save ("write out") | Ctrl-o |
| toggle syntax highlighting | Alt-y |
| undo | not implemented yet |
| go to next word | Ctrl-Space |
| go to previous word | Alt-Space |
| go to beginning of line | Home (or Ctrl-a) |
| go to end of line | End (or Ctrl-e) |
| go to next paragraph | Alt-0 |
| go to previous paragraph | Alt-9 |
| page down | PgDn (or Ctrl-v) |
| page up | PgUp (or Ctrl-y) |
| go to a given line number | Ctrl-_ |
| go to end of file | Alt-/ (or Ctrl-_ Ctrl-v) |
| go to beginning of file | Alt-\ (or Ctrl-_ Ctrl-y) |
| go to matching bracket | Alt-] |
| scroll down | Alt-= |
| scroll up | Alt-- |
| toggle select mode | Ctrl-6 (or Ctrl-^) |
| select some text | just navigate around while in select mode |
| copy current selection (or line) | Alt-6 (or Alt-^ (or even Ctrl-k Ctrl-u)) |
| cut current selection (or line) | Ctrl-k |
| paste | Ctrl-u |
| insert a file into new buffer (*) | Ctrl-r filename |
| insert output of external command | Ctrl-r Ctrl-x command |
| search ("where is") | Ctrl-w |
| go to next search result | Alt-w (or Ctrl-w Enter) |
| toggle search direction for next search (**) | Ctrl-w Alt-b search term Enter |
| search/replace | Ctrl-\ (or Alt-r) |
| help on searching | Ctrl-w Ctrl-g |
| justify (wrap, reflow) current paragraph | Ctrl-j |
| justify entire doc | Alt-j |
| indent/de-dent selected text | Alt-} and Alt-{ |
| insert the next keystroke verbatim | Alt-v |
(*) If you want Ctrl-r to insert a new file into the current file's cursor position, first hit Alt-f to toggle multiple-buffer file mode off (see "Multiple buffers" below).
(**) To reverse the search direction, you need to be in that little search dialog (after hitting Ctrl-w). From in there, hit Alt-b to toggle the search direction. The search direction will be reversed thereafter until you reverse it again, so you can use Alt-w like you'd expect.
When you select some text with your mouse from another X11 window and middle-click to paste it into a doc you're editing with nano, be sure to toggle autoindent off before the paste (Alt-i).
By default with our configuration shown here, Ctrl-r will insert the contents of a file you name into a new buffer. If you want that command to instead insert into the current buffer, you first have to hit Alt-f to toggle multiple-buffer file mode off.
Use Alt-, and Alt-. to cycle through all open buffers.
Note, you may name multiple files on the command line when you start up nano, and they will be indeed be in multiple buffers, regardless of whether multiple-buffer file mode is enabled or not.
If using nano on an xterm, to get the Alt keys to work correctly you may have to Ctrl-left_click and select either "Meta Sends Escape" or "Alt Sends Escape" (both seem to work fine). To make that fix stick, you can add one of the following two lines to your ~/.Xresources file. Either
xterm*metaSendsEscape: true
or
XTerm*eightBitInput: False
Also, if Alt-Space (move backward-by-word) doesn't work for you, it may be that your window manager is intercepting that particular key sequence and nano isn't even receiving it.
If you're using IceWM, you can fix this by editing your ~/.icewm/preferences file, uncommenting the line that says # KeyWinMenu="Alt+Space" and also changing it to say something like KeyWinMenu="Alt+Shift+Space". (If you don't have a ~/.icewm/preferences file, just copy the default one (mine was at /usr/share/icewm/preferences, but in the past I've seen it at /etc/X11/icewm/preferences) to your ~/.icewm directory.)
To fix the Alt-Space problem on Gnome, just go to System --> Preferences --> Keyboard Shortcuts and remove the shortcut for Alt-Space.
Here's what I usually use:
./configure --prefix=/home/john/opt --disable-wrapping-as-root \ --enable-color --enable-multibuffer --enable-nanorc --disable-mouse
You may also need to add --disable-utf8 if ./configure complains.
Copy path/to/nano-2.n.m/doc/nanorc.sample to your home directory, unzip it, and rename it to ".nanorc". Then uncomment the following lines:
set autoindent set fill 72 set multibuffer set smarthome set tabsize 4 set tabstospaces
(some of these options (like quickblank and tabstospaces) may only be available for versions newer than 1.3.x.)
Uncomment any syntax highlighting sections you think you're likely to need -- it doesn't slow nano down to have them all uncommented. I also like to add one simple one of my own for editing various files in /etc:
syntax "etc" "for_various_simple_config_files" color brightblue "#.*"
Then, when you want to use that one, open a file using the -Y etc option.
Here's some patterns for editing reST docs:
## For reST
syntax "rest" "\.rest$"
# italics
#color magenta "\*[^*]*\*"
# bold
color red "\*\*[^*]+\*\*"
# code block
color brightred "::"
# link reference
color blue "`[^`]+`_{1,2}"
# code
color yellow "``[^`]+``"
# directives or comments
color cyan "^\.\. .*$"
# anon link targets
color cyan "^__ .*$"
# h1
color yellow "^###+$"
# h2
color magenta "^===+$"
# h3
color red "^---+$"
# h4
color green "^\^\^\^+$"
# h5
color blue "^"""+$"