A large number of editors exists for the Unix family of operating systems. This chapter only introduces the most common ones.
Table of contents
There are two basic types of editors that you'll encounter: Screen editors and stream editors.
Screen editors are interactive editors that let you edit text on a screen. Stream editors are working on streams of text, usually reading from the standard input and outouting to standard output. For simple tasks, you use the CLI to interact with a stream editor. But you may also use stream editors inside scripts to alter text that is streamed through the script.
The standard screen editor that comes with GNU/Linux and Unix is vi or vim. The latter is just an improved version of the former. The version described below is vim, but vi is very similar.
It is a good idea to have a working knowledge of vim and vi, since these are the only screen editors you can rely on being available on any computer running Unix or Gnu/Linux.
As for the two other screen editors introduced in this ebook, nano and zile, these may have to be installed before you can use them. Their main attraction is that they are very similar to other screen editors (i.e. pico and emacs). If you know one of these already, you may prefer to use nano or zile instead of vim or vi.
Standard screen editor (vim)
The default text editor on many GNU/Linux and Unix sytems is vim. It is a modal editor similar to vi, which was the text editor that shipped with BSD Unix (a version of Unix developed at the University of California, Berkeley in the 1970ies).
In vim, you have four modes:
- Normal mode: most keys om the keyboard are interpreted as a specific command. This is the mode vim will start in.
- Command mode: longer commands may be typed after the prompt (
:) at the bottom of the screen. To switch from the normal mode to the command mode type
- Insert mode: most keystrokes are inserted as text (leaving out those with modifier keys). To switch from the normal mode to the insert mode type
- Visual mode: helps to visually select some text, may be seen as a submode of the normal mode. To switch from the normal mode to the visual mode type
The command mode reverts to normal mode when the command has
completed (unless the command was to quit vim). To go back
to normal mode from the insert or visual mode, type
To quit vim when nothing has been changed, type
:q while in normal mode. To quit vim and save
the changed file, type
:wq. To force close all windows
and quit without saving, type
The editor starts in normal mode. Below is a table with some the most common keys you may use in normal mode:
||Enter command mode.|
||Enter insert mode.|
||Enter visual mode.|
||Search for expression exp.|
||Go to line number n.|
||Delete character under cursor.|
||Delete character before cursor.|
||Delete to end of line.|
||Delete current line.|
||Join current line with next.|
The above table only lists the most essential vim keys. For a much longer list of keystrokes, download and print one of these versions of the vim quick reference card: Adnan Aziz (html), Minglong Shao (pdf), or UTools (pdf).
Pico-like screen editor (nano)
Emacs-like screen editor (zile)
The text editor zile (Zile Is Lossy Emacs) is a light-weight text editor belonging to the emacs family that originated at MIT around 1976.
The keybindings of Zile are designed to resemble those of emacs. It incorporates many standard Emacs features, including:
- Multi buffer editing with multi level undo.
- Multiple windows.
- Killing, yanking and registers.
- Minibuffer completion.
- Word wrap.
Simple substitutions (tr)
Advanced stream editor (sed)
Character set conversion (iconv)The iconv converts converts text from one encoding to another. You specify the encoding to convert from with the
-f, and you specify the encoding to convert to with the
-t. The converted text goes to the standard output.
To see the list of character set encondings iconv recognises, type:
$ iconv -l
For example, to convert from ISO Latin 1 (ISO-8859-1) into UTF-8, type:
$ iconv -f ISO-8859-1 -t UTF-8 < infile.txt > outfile.txt
$ iconv -f ISO-8859-1 -t US-ASCII < infile.txt > outfile.txt
||The standard screen editor for Gnu/Linux and Unix.|
||A Pico-like screen editor.|
||An Emacs-like screen editor.|
||Character set conversion|