Commands covered in this section: emacs xemacs jove vi lpr lpq lprm
Emacs is a powerful, extensible text editor. The name stands for Editor Macros, although some pretend it stands for Emacs Makes A Computer Slow (it is so large it can be slow compared with more simple editors), or for Escape, Meta, Alt, Control, Shift (in reference to the complex key sequences often required). Full versions of emacs come with packages written in Emacs-Lisp, which provide all manner of additional features, such as e-mail and news modes, and even a web browser mode. Also, different modes are usually supplied to aid the editing of different types of files, such as plain text, programming language source code, and TeX files. They can highlight different parts of the file in different colours or fonts, which can make the file easier to work with.
Due to its immense popularity in the UNIX world, emacs has spawned numerous flavours and clones. Three of the main ones are:
All versions should come with extensive documentation and tutorials, which are obviously worthy of careful study if you intend using the program. However, a few basics will be covered here, to start you off. They should apply to all versions of emacs.
To start up the editor, simply type its name. If you type a filename after it, it will attempt to load this file, and it if doesn't exist it may create it. You can then enter some text straight into the editor window.
Commands are given to the editor through key combinations,
although in some cases a mouse can be used to select
operations from a menu bar. In describing key combinations,
the following abbreviations will be used: C- means hold the
down and press the following key, so C-g means press and
hold the Control key and
press g while
still held down. Similarly the abbreviation M- is used to
indicate the Meta key, which
is often next to or close to the space-bar and may be labelled as
a diamond. Users of Jove (and some
other versions) should use
the Escape key
instead, labelled "Esc", and this should pressed and released,
before pressing the next key.
|Forward one word||M-f|
|Back one word||M-b|
|Up one screen||M-v|
|Down one screen||C-v|
|To start of line||C-a|
|To end of line||C-e|
|To start of sentence||M-a|
|To end of sentence||M-e|
|To start of file||M-<|
|To end of file||M->|
There are numerous ways of moving the cursor around a text file, aside from the cursor keys which move one character at a time. The more common ways are shown in the table. If there are no cursor keys on your keyboard the following key combinations can be used instead. The letters used stand for Previous, Next, Forward and Back.
|Delete to end|
|Delete to end|
In addition to the standard Delete or Backspace key, which deletes the character before the cursor, there are numerous commands for deleting and moving text, as shown in the table.
command is very useful when used in conjunction with the Delete to end of
line operation. Multiple lines can be
deleted, and then pasted back in a different place, using
command. This provides an easy way of moving text around. If
you are running a graphical version of emacs you can also
use the mouse to select and paste text.
|Save current file||C-x C-s|
|Edit a file||C-x C-f|
The current text can be searched by pressing the appropriate key combination and then entering the string to search for. In some versions of emacs the search is performed interactively; the cursor jumps to the next position which currently matches the entered text. You can search for the next match by pressing the key combination again. The search can be cancelled by pressing C-g, which can also be used to cancel many other operations.
If the Edit
file command is given you will be
prompted for a the name of a file, which will then be loaded
into the editor. But any file you were previously editing will
remain in memory. You can open as many files as you like,
and each is placed in its own buffer, and there are
various ways of changing buffers, depending on your version of
|Insert text in front|
|Insert text after|
|Insert text after|
|Insert text before|
The main feature which distinguishes vi from most editors is its separate modes: text entry mode and command mode. The editor can be started by typing vi, with a optional filename. On startup it enters command mode. To change to text entry mode one of the keys listed in the table is pressed, depending of the nature of the entry mode required.
You can now enter text, but you cannot use any of the cursor
keys to move around or perform any other operations. To do so,
you must leave the mode and enter command mode, by
pressing the Escape key. You
can then perform the operations described in the following
|To start of line||^|
|To end of line||$|
|Forward one word||w|
|Back one word||b|
|Up one screen||C-b|
|Up half a screen||C-u|
|Down one screen||C-f|
|Down half a screen||C-d|
|To line n||:n|
The keys shown in the diagram below can be used to move the cursor around. In addition, cursor keys can be used, if they are present on your keyboard.
The last command listed, to jump to a given line number,
shows use of the extended command entry facility. The Enter key should be
pressed after the command is entered.
|Delete entire line||dd|
|Delete to end of line||D|
|Replace word||cw (then Esc)|
|Replace line||cc (then Esc)|
|Yank lines into buffer||:<range>y|
|Paste buffer after current line||:pu|
|Paste buffer after line n||:npu|
Vi provides numerous commands for manipulating text, many of which are shown in the table.
To replace a word or line, press the keys listed, then enter the replacement word or line, pressing Escape to finish.
Two of the commands listed contain a <range>
parameter which specifies the lines the command is to be
applied to. This can be a single line number, or a start and
end line number, separated by a comma. There are two special
characters that can be used: $ for the last
line, and .
for the line containing the cursor.
|Repeat last search||n|
|Replace first occurrence of|
str on each line with rep
|Replace every occurrence of|
str on each line with rep
|Save current file||:w|
|Save as <name>||:w <name>|
|Edit <name> instead of current file||:e <name>|
|Quit if saved||:q|
|Quit without save||:q!|
To search for a string in the current buffer, press the key shown in the table, type in the search string, and then press Enter.
The replace commands operate on the entire buffer, unless a range parameter is given.
You must save the buffer before quitting, unless you use the
Most networked systems have at least one printer attached to the network, which can be used to obtain a hard copy of your work. For most purposes fast dot matrix printers are adequate, although laser printers can be used for higher quality output.
To send a file to a printer type lpr followed by the name of the file to be printed. This will send the file to the default printer, whatever that may be set to. If you wish to use a different printer, you need to know the name of the printer, as it is known to the system, and then you can use the -P option to lpr. For example a laser printer may be known as ps (for Post-Script), in which case lpr -Pps text will send the file to it.
Files sent to a printer are held in a queue until the printer is free to print them. On a busy system this could take some time, especially if the printer runs out of paper or breaks down. You can monitor the print queue, and the progress of your file in it, using the lpq command. It will list the job number, name, size, and owner of all the items on the queue.
Files can be removed from the print queue before they are printed by using the lprm command. Provide this command with the job number or numbers you wish to cancel, obtained using lpq, or use lprm - to cancel all of the items on the queue belonging to you. Make sure you use this command if you make a mistake or change your mind; don't waste resources, and remember you are responsible for files you print, which you may have to pay for. Find out first!
|Previous: Making a Difference||Next: Finding Out|