The most popular text editors available on Unix/Linux machines are vi (or vim) and emacs. Both of them are extremely powerful and flexible. Both of them (emacs in particular!) have a pretty steep learning curve. If you are serious about programming, you should learn at least one of them.
For now, we will use nano, which has quite limited functionality, but is a lot more user-friendly.
Nano
Nano is a modeless editor, so you can start typing immediately to insert text.
You can start nano with pi@raspberrypi:~ $ nano
If you are editing a system configuration file, you should use the -w switch to disable wrapping on long lines as it might render the configuration file un-parseable by whatever tools depend on it. pi@raspberrypi:~ $ nano -w
There are four main sections of the editor. The top line shows the program version, the current filename being edited, and whether or not the file has been modified. Next is the main editor window showing the file being edited. The status line is the third line from the bottom and shows important messages. The bottom two lines show the most commonly used shortcuts in the editor. (all of them start with the CTRL
key followed by a letter.)
Let's practice creating a file.
First, we navigate to our /home/pi/work directory and start the text editor.
pi@raspberrypi:~/work $ cd /home/pi/work/
pi@raspberrypi:~/work $ pwd
/home/pi/work
pi@raspberrypi:~/liv $ nano
GNU nano 2.7.4 New Buffer
this is a test.
File Name to Write:
^G Get Help M-D DOS Format M-A Append M-B Backup File
^C Cancel M-M Mac Format M-P Prepend ^T To Files
Type a few words into nano, e.g. "this is a test". Type CTRL
+ o
to save your work, write the name of the file (e.g. "testfile") and hit Enter
. Type CTRL
+ x
to exit.
We can check our work with cat (command that shows the content of a file).
pi@raspberrypi:~/work $ ls -l
total 4
-rw-r--r-- 1 pi pi 16 Aug 31 01:57 testfile
pi@raspberrypi:~/work $ cat testfile
this is a test.
To open a file, type: pi@raspberrypi:~ $ nano filename
To save a file, use the keyboard shortcut To save your work type CTRL
+ o
.
To cut and paste a particular line, first bring the cursor to that line, then press CTRL
+ k
to cut, then head to the place where you want to paste it, and finally use CTRL
+ u
to paste.
To search for a word in Nano, type CTRL
+ w
.
Nano is user friendly, so if you spend some time with it, you will get familiar with its commands just by reading the shortcuts in the lower part.
You can find the user manual for nano here