Brief Introduction to the GNU Emacs Editor
Emacs is a popular editor which allows you to do basic and advanced editing
using a series of keystroke commands. However, it is much more than just a
text editor, with major editing modes for all programming languages, the
ability to do directory editing, the ability to run Unix shells inside Emacs
buffers, and much more. This guide will show you the bare minimum of how to
invoke the Emacs editor and how to perform basic cursor movements once you
are inside. Once you become familiar with Emacs and learn how to access its
documentation, you will find that it is possible to do virtually all of your
Unix work without ever leaving the Emacs editor.
Invoking Emacs
Entering "emacs" at the Unix prompt followed by a filename will invoke the
emacs editor on the file, or create a new buffer if the filename does not
exist. Entering "emacs" without a filename will put you into a scratch
buffer and also give you the opportunity to run the tutorial (see below).
Entering Text
To insert text into a file at a particular location, just move the
cursor to that location (see below for cursor movement) and start
typing the text.
Notes on the following:
- C- stands for the Control key, which you must hold down while
pressing the next key. For example, C-a means press the Control
key and then the "a" key while Control is still pressed.
- ESC- stands for the Escape key, which you must release before
pressing the second key in the sequence. For example, ESC-v would
be entered as "ESC (release) v".
Moving the Cursor
- C-a
- Move to the beginning of the line.
- C-e
- Move to the end of the line.
- C-f
- Move forward one character.
- C-b
- Move backward one character.
- C-n
- Move down one line.
- C-p
- Move up one line.
- C-v
- Page forward one screen.
- ESC-v
- Page backward one screen.
- ESC-<
- Go to beginning of file.
- ESC->
- Go to end of file.
Deleting Text
- C-d
- Delete character cursor is on
- C-k
- Delete from cursor to end of line
Manipulating Panes
- C-x 2
- Split current buffer into two panes
- C-x o
- Move cursor to other pane
- C-x b
- Switch to buffer
Managing Files
- C-x C-f
- Load or create a file
- C-x C-s
- Save current buffer to file without name prompt
- C-x C-w
- Save current buffer to file with name prompt
Running a Shell Buffer
A shell buffer is a window (or pane) in emacs that allows you to interact
directly with unix through the C shell, just as though you were not using an
editor at all. But since the shell buffer is running in emacs, you can leave
it at any time to resume editing a file buffer, and you can return to it any
time to invoke unix commands through the C shell. This means that you don't
have to exit and restart emacs each time you need to compile a file or
otherwise execute a unix command.
To start a shell buffer
while in emacs, simply type ESC-x shell while in emacs. A window
into a buffer called *shell* will appear with your standard unix prompt.
You can then move between this buffer and your program buffer(s) using the
keystroke commands given above in Manipulating Panes.
Miscellaneous
- C-l
- Clear the screen and reprint everything. Use this if the
screen becomes garbled due to line noise.
- C-g
- Aborts the current emacs function. If something weird happens
and you get a prompt which you don't understand, try this.
Running the Emacs Online Tutorial
There is an online emacs tutorial which walks you through the basic
operations of the editor. It would be helpful to go through it at least once
before you try to edit a file. To run it, start up emacs then just type "C-h
t". Note that the tutorial refers to the ESC- key as M-.
Other Help
- C-h ?
- Get internal Emacs help
- ESC-x info
- Use online Emacs documentation system.
Complete online documentation for Emacs is available within Emacs
by invoking the info system with "ESC-x info". This puts you
into a documentation buffer which is organized hierarchically
into menus and submenus. Type "h" to get help for first-time
info system users.
- ESC-x doctor
- Talk to the psychotherapist
Quitting Emacs
In order to exit emacs simply type "C-x C-c". You will be prompted for
whether you want to save your edits. Be sure to reply with "y" or
your work will not be saved.
Quick Reference Card
A postscript file with basic emacs keystroke commands is available
here.
Page URL: http://www.d.umn.edu
/~tcolburn/emacs/guide.html
Page Author: Tim Colburn
Last Modified: Monday, 27-Sep-1999 14:47:28 CDT
Comments to: tcolburn@d.umn.edu