topic title: HOWTO: Nano
Posts: 215
macondo
Joined: 14 Sep 2007
#1
HOWTO: Nano, a basic editor

Nano comes by default, as well as 'vim-tiny' and 'ed', when you install
Debian or its derivates. It has to be the most used editor for newbies
and old timers as well. It's simple, it has the same keybindings as Pico
and you don't have to be a rocket scientist to understand it.

Programmers use heavier editors more appropiate for complex tasks, such
as Vim and Emacs . My needs are basic, i just need to edit files and use
it for simple word processing.

As a good trooper i read the manuals:

$ man nano
$ man nanorc

Then i looked for the global options file:

$ locate nanorc

Once i found it, i went in to see what it had in options:

$ nano /etc/nanorc

This is the global list of options for nano, the options come commented
(#), it is not supposed to be edited, so i created a .nanorc file in my
/home:

$ touch .nanorc

And added the options that will satify my needs:

set const
set smooth
set mouse
set tabsize 3
set fill 72


set const:
gives me the line number as i move (live)

set smooth:
stops the jerking movements as i scroll

set mouse:
will allow you to put the cursor where you want it with a click of the mouse. For this to work it has to have the app 'gpm' installed with apt-get. To activate the mouse press Alt+M .

set tabsize 3:
will indent using 3 spaces.

set fill 72:
sets the word wrapping at 72 if you're writing an article.

NOTE: The following keybindings eventhough are written in caps for
clearer reading are to be used without the caps.

To format the paragraph: Ctrl+J
To erase the help options at the bottom: Alt+X, to bring it back, the
same.

To format the whole file: Alt+J
To get the #words, lines and characters: Alt+D

To delete lines: Ctrl+K
To undo: Ctrl+U

To Cut & Paste
Press Shift and hilite with the mouse left button, to paste: press Shift
again and press the middle mouse button, that's it.

To Save and Exit
Ctrl+O <Enter>
Ctrl+X

To go to the beginning of the line: Ctrl+A
To go to the end of it: Ctrl+E
To go the beginning of the file: Ctrl+Y
To go to the end of the file: Ctrl+V

And a bunch more, ^G (that's Ctrl+G in geek speak) will give you more
info, about spaces, lines, going forward, backwards, you name it.

$ sudo nano -w <file_name>

this will cancel any wrapping, in order to edit any non-text file.

$ sudo nano -wx <file_name>
will cancel the wrapping AND eliminate the help options at the bottom of
the page. There are all kinds of options, please read:


========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://www.nano-editor.org"
linktext was:"www.nano-editor.org"
====================================


To use it as a word processor:
$ nano ~/title_of_article.txt

when you're finished, it will be saved in you /home as a text document.


Cheers,
macondo
Last edited by macondo on 22 Dec 2007, 13:40, edited 1 time in total.
Posts: 319
impuwat
Joined: 13 Sep 2007
#2
Thanks macondo! Great stuff.
Posts: 19
sleekmason
Joined: 08 Jul 2008
#3
Very nice indeed.
Posts: 1,081
OU812
Joined: 29 Sep 2007
#4
Brilliant!

john
Posts: 1,520
eriefisher
Joined: 07 Oct 2007
#5
Nano has got me back into a desktop more than a few times, especially when I was using Kubuntu. They never could get their upgrade process working properly.
Posts: 1,139
masinick
Joined: 26 Apr 2008
#6
Thanks for the informative article. You certainly hit the sweet spot of the basic functions of Nano. While we were on the subject, I thought I would do a quick bit of research on my own and see if I could find any other useful tidbits, which may not be the"every day" kind of commands, but still something that may come in handy once in a while. In addition to what you already documented, here are a couple of handy nano command line options that I had not looked at before that might be useful some day:

-c, --const

Constantly display the cursor position and line number on the statusbar.

-s [prog], --speller=[prog]

Invoke [prog] as the spell checker. By default, nano uses its own interactive spell checker that requires the spell program be installed on your system.

Commands to invert or toggle existing functionality:

Multiple Files Toggle (Meta-F)

toggles the -F (--multibuffer) command line flag.

utoIndent Toggle (Meta-I)

toggles the -i (--autoindent) command line flag.
Cut To End Toggle (Meta-K)

toggles the -k (--cut) command line flag.
Mouse Toggle (Meta-M)

toggles the -m (--mouse) command line flag.
AutoWrap Toggle (Meta-W)

toggles the -w (--nowrap) command line flag.

Open Previous File Toggle (Meta-<)

changes buffer to previously loaded file.
Open Next File Toggle (Meta->)

changes buffer to next loaded file.

NOTE:
* Control key sequences are entered by holding down the Control key and pressing the desired letter.
* Meta key sequences can be entered in a number of possible ways: Pressing the Escape key, then releasing it and pressing the desired key, or holding down the Alt key while pressing the desired key. This varies from keyboard to keyboard, and certain commercial operating systems"swallow" the Alt key so that it never reaches the application. If your operating system does this, you should use the Escape key to generate Meta key sequences.

I already use Ctrl-A, Ctrl-E, because my GNU Emacs fingers are trained to know them to go to the beginning and end of lines, respectively. Ctrl-K is also known to kill, with that same background. It takes some doing, though, to remember Ctrl-Y to go to the beginning of the file or Ctrl-U to go to the end of the file because I have long used the Emacs Esc-< to go to the top of the buffer and Esc-> to go to the bottom of the buffer, or 1G in Vi to go to the top of the file and G to go to the bottom (when in Vi command mode).

Since these are practically all of the Nano commands, except for a few more flags and commands for really arcane cases, this makes Nano really easy to use, ESPECIALLY since you do not even have to know the commands I've just noted AT ALL to use Nano perfectly well. The fact is, though, that even the simple Nano is a bit more powerful than first appearances. Fast, simple, with moderate power? Not a bad choice at all - a very good one with antiX, in fact!

Thanks for bringing these things to the forefront and writing these tips!
Posts: 20
RHTopics
Joined: 20 Feb 2009
#7
Some additional information on setting up spell checking in nano.

This has been tested and works in the full version of antiX M8.

Add the following lines to your /home/"your user id"/.profile file:

Code: Select all

  # set up SPELL environmental variable so spell check will work in nano
  export SPELL='aspell -c'
Log out and log back in and spell checking should now be available in
nano.