Topics Map > University of Chicago > IT Services > Applications, Operating Systems, & Devices

Unix - Using Emacs

This article explains how to use the emacs text editor in Unix.

Emacs is a very powerful text editor which has so many bells and whistles that it has a largely undeserved reputation for being slow as well (the joke is that `emacs' stands for "emacs makes a computer slow"). Emacs has many specialized features for such tasks as editing program code, it's complicated enough that it can be difficult to learn on your own. Instead, run the (excellent) emacs tutorial by typing, at your Unix prompt:

teachemacs

The GNU emacs reference card (this document) gives a list of the basic emacs commands.

Getting in and out

  • Start emacs: emacs or emacs file
  • Visit/find a file: ^X^V or ^X^F
  • Insert another file: ^X i
  • Write a file: ^X^W
  • Save a file: ^X^S
  • Suspend emacs: ^Z
  • Exit emacs: ^X^C

Moving around

  • forward 1 character: ^F
  • back 1 character: ^B
  • forward 1 word: ESC F
  • back 1 word: ESC B
  • previous line: ^P
  • next line: ^N
  • beginning of line: ^A
  • end of line: ^E
  • beginning of sentence: ESC A
  • end of sentence: ESC E
  • forward 1 screen: ^V
  • back one screen: ESC V
  • beginning of document: ESC <
  • end of document: ESC >

Searching

  • Search (incrementally, forward): ^S
  • Reverse-search (back): ^R
  • to stop searching: ESC

Editing

  • Delete previous char.: Delete-key
  • Delete next char.: ^-D
  • Delete previous word: ESC Delete-key
  • Delete next word: ESC D
  • Kill to end of line: ^K
  • Kill to end of sent.: ESC K
  • Transpose 2 chars.: ^T
  • Transpose 2 words: ESC T
  • Set mark: ^-spacebar or: ^-@
  • Exchange point and mark: ^X^X
  • Kill region (cut): ^W
  • Copy region (copy): ESC W
  • Yank (paste): ^Y
  • Capitalize word: ESC C
  • Uppercase word: ESC U
  • Lowercase word: ESC L

Modes

  • Enterfoo mode: ESC xfoo
  • Set fill column: ^X f
  • Fill paragraph: ESC Q
  • Fill region: ESC G

Windows

  • Make two windows: ^X 2
  • Make one window: ^X 1
  • Go to other window: ^X o

Fixing problems

  • Abort current command: ^G
  • Undo last big change: ESC x undo
  • Redraw screen: ^L

Functions

Many functions in emacs can be called by typing

ESC X function

where function can be anything from

search-and-replace: ESC X replace-string [return] or: ESC X query-replace [return]

to file inclusion:: ESC X insert-file [return]

Help

  • Get help: ^H
  • Get help: info program: ^H i
  • Get help: tutorial: ^H t



Keywords:unix emacs text editor   Doc ID:15871
Owner:Larry T.Group:University of Chicago
Created:2010-11-30 18:00 CSTUpdated:2015-01-26 10:27 CST
Sites:University of Chicago, University of Chicago - Sandbox
Feedback:  1   0