Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous contents
Next: Compilers Up: Utilities Previous: Utilities

   
Emacs using Control Keys

This section describes how to use emacs using the control keys. Although learning to operate emacs in this way may seem difficult at first, much of the rich functionality of the editor is only available once you have learnt to drive it with the control keys. If you need to use Emacs from a dumb terminal the control key method might be the only one available. In what follows C- means use the control key and M- means use the meta key. On some keyboards the meta key is labelled `Extend char'.

Some terminals will have their labelled function keys bound to appropriate things (e.g. `search' might search-forward).

The DISPLAY Environment Variable:-

Miss out this subsection unless you are a fairly advanced user, or you want to use emacs on a dumb terminal (not running X-windows).

When you invoke emacs on the shell command line, emacs determines whether to use the terminal window or start up its own X-window. To do this emacs looks at the `DISPLAY' environment variable. If the DISPLAY variable is set then emacs tries to start up an X-window on that display otherwise it uses the terminal.

If you are using a dumb terminal (i.e. not X-windows) your DISPLAY variable should not be set. If you are on a X-windows workstation then it should be set.

You can check that the DISPLAY variable is in the correct state with the command:

echo $DISPLAY

If you get a blank reply then the variable is not set. If you get something like tw101.eng.cam.ac.uk:0 then it is set. If the variable is in the wrong state then change it as follows.

You can unset the DISPLAY variable by typing

unset DISPLAY

on a line by itself. To set the variable to the display of the machine you are sat at, look for the label on the machine for the machine's name (maybe tw305) then type

export DISPLAY=tw305:0

Starting Emacs from the Command Line:-

To start the editor from the command line you type its name - emacs.

If you are using a X-windows workstation (and have set the DISPLAY variable) then you should add an ampersand. This will enable you to continue to use the terminal window while the editor is executing by running the editor ``in the background''. The command is thus emacs &.

The Emacs Tutorial:-

Once emacs is running you can obtain an online tutorial by typing C-h t (hold the control key down and type `h' then let go of the control key and type `t'). This is a very good way to start to learn control key use of the editor. It is recommended that you do at least part of this tutorial now.

Emacs Help & the Info System:-

Typing C-h gets you into the Emacs help system. This is useful for finding out what a given control sequence does or whether emacs has a command to do something in particular.

Type C-h k and then any of the control sequences in the previous section and emacs will explain what it does. You will have to type C-x 1 to get rid of the help when you have finished reading it.

Type C-h a and you will be prompted for a string. Type in spell to find out what spelling checking emacs provides. A number of commands are provided, only one of which (spell-word) is bound to control keys. To access a command which is not bound to a control sequence you type M-x (or C-[ x) and then type in the command name.

To find out if a command is bound to a control key sequence you can use C-h w. When the prompt appears specify spell-word and emacs will tell you which key sequence it is bound to.

More descriptive online documentation for emacs - and several other topics - is provided by the info system. This is entered using the command C-h i. Once you are in the info system, typing h will give you a primer for first time users. A list of simple commands is given below.

d Go to top directory node.
<space> Go to next page down in node.
<Back space> Go to previous page in node.
n Go to next node.
m Select menu item.
l Return to last visited node.
q quit.

Summary of basic Emacs commands :-

C-p Moves the cursor up to the previous line in the file.

C-n

Moves the cursor down to the next line in the file.

C-b

Moves the cursor one position back to the left.

C-f

Moves the cursor forward one position to the right.

C-d

Deletes the character under the cursor.

C-k

Kills all the characters from the current cursor position
  to the end of the line.

C-space

Marks a position.

C-w

Kills text from text pointer to marked position

M-w

Copies text from text pointer to marked position

C-y

Yanks back the most recent kill.

C-rstring

Incrementally searches backwards for the string specified.

C-sstring

Incrementally searches forwards for the string specified.

Beware of using C-s on dumb terminals as it might lock
  up the terminal and you will have to type C-q to fix it.

C-v

Displays the next page down in the file.

M-v

Displays the next page up in the file. (If your terminal
  does not have a meta key you can use C-[ or ESC.)

C-g

Interrupts the current command.

C-x C-f

Prompts you to select a new file to edit.

C-x s

Saves files currently being edited.

C-l

Redraws the screen with the cursor in the middle.

C-x C-c

Offers to save all files to disk then exits the editor.

 


next up previous contents
Next: Compilers Up: Utilities Previous: Utilities
© Cambridge University Engineering Dept
Information provided by Tim Love
2005-08-22