These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Using The Emacs Editor

Classnotes | UNIX01 | RecentChanges | Preferences

Meta-Keys, Line Commands, and Modes

The Emacs editor operates much like any normal word processor. There is only one mode, the input mode. If you had any character key, you are entering data into the file. Commands are assigned to CTRL keys as well as meta-keys. A meta-key may be either an ALT key sequence or an ESC key sequence.

CTRL keys and meta-keys constitute only a part of the many commands available in Emacs. All commands can be typed into the Echo area (usually the area at the bottom of the Emacs screen). The meta-keys ALT-X or ESC-X will place you in the Echo area.

At the bottom of the Emacs you will see a mode line. This line displays status information about the buffer being edited. The mode line is made up of several components with the following form:

 -ST-Emacs: Buffername  (major minor) ----- Place --

The first field, ST, indicates whether the file has been saved for not since the last change to the text. If the field displays two asterisks, **, the text has been changed but not yet saved. If the field displays two dashes, - -, the text has not been changed since last save. If the field displays two percent signs, %%, the file is read-only and cannot be modified.

The "Buffername" field is the name of the buffer. In the case of files, this will be the name of the file. The "Place" field indicates how far you are positioned in the file. For example, if you were 40% down the file, it would display 40 percent.

The major/minor field indicates the major and minor modes for editing the file. Emacs recognizes several major modes, the most common of which is the text mode. An example of another mode is an indention mode for C programming.

Emacs has three minor modes: fill, overwrite, and abbrev. The fill mode is usually the default. It automatically wraps long lines in the file. The overwrite mode allows you to overwrite text, and the abbrev mode allows you to use abbreviations when entering text.

Basic Emacs Editing Commands

The following are basic commands useful when editing a file.

  • CTRL-F : Moves you forward one character.
  • CTRL-B : Moves you back one character.
  • CTRL-N : Moves you ahead one line.
  • CTRL-P : Moves you to the previous line.
  • CTRL-V : Moves forward to the next page of text (PGDN).
  • CTRL-Z : Moves back one page of text (PGUP).
  • CTRL-E : Moves to the end of a line.
  • CTRL-L : Moves to the center of a line.
  • CTRL-A : Moves to the beginning of a line.
  • ALT-< : Moves to the start of the file.
  • ALT-> : Moves to the end of the file.
  • CTRL-D : Deletes the character after the cursor.
  • DEL : One some UNIXes this functions the same as BKSP, on others it functions like CTRL-D.
  • ALT-D : Deletes the word after the cursor.
  • ALT-BKSP : Deletes the word before the cursor (on some UNIXes, ALT-DEL functions this way as well).
  • CTRL-Y : Deleting text places into something called the "Kill Buffer". You can use CTRL-Y to "yank" it from the kill buffer and paste it back in at the cursor's location.

Cutting & Pasting

  • CTRL-@ : Marks the beginning of a peice of text. Move your cursor to where you want to end the selection. The text between where you marked and where your cursor is will be your selection. Once you have a selection, you may do the following:
    • CTRL-W : Cuts the region and places it in the kill buffer.
    • ALT-W : Copies a region and places it in the kill buffer.
    • CTRL-X, CTRL-X : If you forget where the mark was made (with CTRL-@ above), this sequence shows where it was.
  • ALT-H : Selects the current paragraph.
  • CTRL-X, H : Selects the entire buffer.

Searching

  • CTRL-S pattern : Searches forward for a pattern.
  • CTRL-R pattern : Searches backward for a pattern.

Buffers and Files

  • CTRL-X 0 (zero) : Closes the current screen.
  • CTRL-X 2 : Opens a new screen on the text already in the buffer (will split the screen).
  • CTRL-X O ("oh") : Moves to the next screen.
  • CTRL-X P : Moves to the previous screen.
  • CTRL-X 1 : Close all but the current screen.
  • CTRL-X CTRL-F filename : Opens a file with a new buffer.
  • CTRL-X CTRL-S : Saves the contents of the file.
  • CTRL-X CTRL-C : Quits the current file.
  • CTRL-X 4F filename : Creates a new screen and opens the file in it.
  • CTRL-X D : Enter dired mode which has the following commands:
    • n - Move to next file.
    • p - Move to the previous file.
    • s - Marks the file for saving.
    • d - Marks the file for deletion.
    • u - Undos a mark. (Changes are not made until you leave dired)
    • CTRL-X B - Leave dired mode.


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited July 19, 2003 1:26 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.