Department of Engineering

IT Services

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 Alt.

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.