GNUemacs: beyond the tutorial

In an unmodified GNUemacs version 24.3.1, there are 2506 commands -- and more are available for loading, some of them automatically. The Emacs tutorial introduces a few tens of commands; this document introduces around a hundred more that I have found useful (in over 25 years of using Emacs).

Some of the most useful of these commands are also listed on the reference card that is supplied (as TeX and PostScript files) in the Emacs distribution.

Using Emacs to anything like its full power requires a lot of chording, and if you use Emacs a lot, you can unload some of the strain from your hands by attaching a set of footswitches, at least for the Control and Alt keys.

Alternatively, many Emacs users also modify their keyboard mapping, to put the Control key above the left Shift key (where Caps Lock usually is), to make it easier to reach.

Terminology

Buffer
The text you edit in Emacs is held in things called buffers. A buffer typically holds the contents of a file, although there are also non-file buffers.
Frame
What most systems call a window (the thing you can minimize, maximize, drag around, etc), Emacs calls a frame.
Window
Emacs' frames can be subdivided into what Emacs calls windows. Each window displays a buffer (usually just part of the buffer).
minibuffer
There is a special area at the bottom of the Emacs frame, usually one text line high, in which Emacs displays buffers called minibuffers when it needs to display messages or prompt you for information.
Mode
Each Emacs buffer is in a mode. There is a mode for each type of file that Emacs specifically supports, and also some modes not related to files. The mode defines what each key does when typed when that buffer is the current one, and defines various other information about it (for example, how to indent it, what the comment syntax is, which characters can be parts of symbols, and so on). Sometimes, a particular key is bound to different commands in different modes, but doing conceptually equivalent things. For example, in many modes for text in programming languages, the TAB key adjusts the indentation of the current line.
Point
The current editing position in each buffer. When a particular buffer is active, the cursor is displayed at point.
Mark
Another position in a buffer, set by various commands.
Region
The part of a buffer between its point and its mark.
Command names
Each action that Emacs does is done by running a named Emacs-Lisp function. The mostly useful commands' names are normally bound to keystrokes, but you can also run any command by name.
Recursive edit
Enters another copy of the editing loop, for a specific purpose or activity. To go back to the previous activity, use M-x exit-recursive-edit, which is usually bound to M-C-c.
regexp or regular expression
A search expression, containing text to search for, allowing wildcards and other non-literal searches
prefix argument
A prefix argument is number or flag specified before giving a command, that modifies the behaviour of that command (for example, for movement commands, it typically gives a repeat count to the movement; for commands that prompt the user for confirmation, it may pre-confirm). To give a simple flag, type C-u before the command; to give a certain number, either type C-u then the number, then the command, or type the number while holding the C- (control) or M- (meta, alt, diamond, clover, or whatever it is on your particular keyboard) key down. C-u by itself, taken as a number, is taken to mean 4, and successive C-u's multiply that by 4. For just a few commands, C-u and C-u 4 have different meanings.

Notation

Emacs uses modifier keys a lot, and has a systematic notation for describing keystrokes with modifiers.

C-a
This means typing some character, such as a, while holding the Control key down.
M-a
This means typing some character, such as a, while holding the Meta key down. On most keyboards, this is what other programs call the Alt key, although on some it may be a diamond shape, or a cloverleaf, or various other intuitive graphics equally meaningful to speakers of any language. If your keyboard has no Alt key, or if some other program is grabbing the Alt key, you can instead press (and release) Escape, followed by typing the plain character a.
C-M-a
This means a with both Control and Meta applied to it.

Table of sections

Recap of the tutorial

KeystrokesCommand nameExplanation
C-x C-c save-buffers-kill-emacs

Offer to save each buffer, then quit Emacs.

C-v scroll-up

Scroll text of current window upward.

M-v scroll-down

Scroll text of current window down.

C-l recenter

Center point in window and redisplay frame.

C-b backward-char

Move point left N characters (right if N is negative).

C-f forward-char

Move point right N characters (left if N is negative).

C-p previous-line

Move point vertically up.

C-n next-line

Move point vertically down.

C-u universal-argument

Begin a numeric argument for the following command.

M-b backward-word

Move backward until encountering the beginning of a word.

M-f forward-word

Move point forward a word.

C-a move-beginning-of-line

Move point to beginning of current line as displayed.

C-e move-end-of-line

Move point to end of current line as displayed.

M-a backward-sentence

Move backward to start of sentence.

M-e forward-sentence

Move forward to next end of sentence.

M-< beginning-of-buffer

Move point to the beginning of the buffer; leave mark at previous position.

M-> end-of-buffer

Move point to the end of the buffer; leave mark at previous position.

C-u universal-argument

Begin a numeric argument for the following command.

C-g keyboard-quit

Signal a `quit' condition.

C-x 1 delete-other-windows

Make the selected window fill its frame.

DEL delete-backward-char

Delete the previous character.

C-d delete-char

Delete the following characters.

M-d kill-word

Kill characters forward until encountering the end of a word.

M-DEL backward-kill-word

Kill characters backward until encountering the beginning of a word.

C-k kill-line

Kill the rest of the current line; if no nonblanks there, kill thru newline.

M-k kill-sentence

Kill from point to end of sentence.

C-SPC set-mark-command

Set the mark where point is, or jump to the mark.

C-w kill-region

Kill ("cut") text between point and mark.

C-y yank

Reinsert ("paste") the last stretch of killed text.

M-y yank-pop

Replace just-yanked stretch of killed text with a different stretch.

C-x u advertised-undo

Undo some previous changes.

C-_
C-x C-f find-file

Edit a specified file.

C-x C-s save-buffer

Save current buffer in visited file if modified.

C-x s save-some-buffers

Save some modified file-visiting buffers. Asks user about each one, unless a prefix was given.

C-x C-b list-buffers

Pop up a buffer describing the set of Emacs buffers, and allow selection of them.

C-x b switch-to-buffer

Switches to a specified buffer in the current window.

C-z iconify-or-deiconify-frame

Iconify the selected frame, or deiconify if it's currently an icon.

M-x execute-extended-command

Read function name, then read its arguments and call it.

C-s isearch-forward

Do incremental search forward.

C-r isearch-backward

Do incremental search backward.

C-x 2 split-window-vertically

Split current window into two windows, one above the other.

C-M-v scroll-other-window

Scroll next window upward.

C-x o other-window

Select the next window on this frame.

C-x 4 C-f find-file-other-window

Edit a specified file, in another window.

C-h c describe-key-briefly

Print the name of the function a specified key invokes.

C-h k describe-key

Display documentation of the function invoked by a specified key.

C-h a apropos-command

Show commands (interactively callable functions) that match a given regexp.

C-h i info

Enter Info, the documentation browser.

Help commands

KeystrokesCommand nameExplanation
C-h c describe-key-briefly

Print the name of the function a specified key invokes.

C-h k describe-key

Display documentation of the function invoked by a specified key.

C-h a apropos-command

Show commands (interactively callable functions) that match a given regexp.

C-h f describe-function

Display the full documentation of a specified function (a symbol).

C-h a apropos-command

Show commands (interactively callable functions) that match a given regexp.

C-h d apropos-documentation

Show symbols whose documentation contains matches for a given regexp.

C-h i info

Enter Info, the documentation browser.

C-h r info

Enter Info, the documentation browser, at the Emacs manual.

C-h m describe-mode

Display documentation of current major mode and minor modes.

C-h b describe-bindings

Show a list of all defined keys, and their definitions.

C-h s describe-syntax

Describe the syntax specifications in the syntax table of a specified buffer.

Use M-x man

Get a Un*x manual page and put it in a buffer.

Kill-ring operations

KeystrokesCommand nameExplanation
C-w kill-region

Kill ("cut") text between point and mark.

M-w kill-ring-save

Save the region as if killed, but don't kill it.

C-M-w append-next-kill

Cause following command, if it kills, to append to previous kill.

C-y yank

Reinsert ("paste") the last stretch of killed text.

M-y yank-pop

Replace just-yanked stretch of killed text with a different stretch.

Programming language operations

Expression operations

We move by symbolic (bracketed) expressions, by statements, and by function definitions. Emacs refers to symbolic expressions as sexps. A sexp may be a single symbol or number, or a series of things delimited by matching (possibly nested) brackets.

KeystrokesCommand nameExplanation
C-M-f forward-sexp

Move forward over a balanced bracketed expression; a symbol also counts as an expression.

C-M-b backward-sexp

Move backward over a balanced bracketed expression.

C-M-d down-list

Move forward and in one level of parentheses.

C-M-u backward-up-list

Move back and out one level of parentheses.

C-M-SPC mark-sexp

Set the region to the balanced bracketed expression starting at point.

C-M-k kill-sexp

Kill the balanced bracketed expression starting at point.

C-M-q mode-dependent

Re-indent the balanced bracketed expression starting at point.

M-( insert-parentheses

Insert a pair of parentheses, leaving point between them.

Expression tips

You can use a prefix argument (C-u number or C-number or M-number) to move over multiple expressions.

Rather than marking one end of a series of expressions, and moving to the other end, then deleting or copying the series: instead, move to one end, and use a prefix argument to kill-sexp or mark-sexp (the latter being followed by kill-ring-save). If doing this from the end of the series of expressions, use a negative prefix argument, rather than moving to the beginning.

To remove a bracketed expression(s) around the one(s) you want, use the sexp commands and a numeric argument to yank. For example, to change foo(bar(x,y)) with bar(x,y), move to the start of bar, and do C-2 M-C-k M-C-u M-C-b C-2 M-C-k C-2 C-y

Using M-( saves keystrokes and makes sure you keep the brackets balanced.

Statement operations

KeystrokesCommand nameExplanation
M-a mode-dependent

Move to the start of the current statement.

M-e mode-dependent

Move to the end of the current statement.

TAB mode-dependent

Adjust the indentation of the current line.

C-j mode-dependent

Start a new line, at the appropriate indentation.

M-; comment-dwim

Start a comment, or move to an existing one, or adjust its position, or comment out a region.

Use M-x comment-region

Comment or uncomment each line in the region.

Use M-x uncomment-region

Uncomment each line in the region.

Function definition operations

KeystrokesCommand nameExplanation
C-M-a beginning-of-defun

Move to the start of the current function.

C-M-e end-of-defun

Move to the start of the current function.

C-M-h mark-defun

Set the region to the function definition around point.

C-M-x mode-dependent

In some programming languages, send the function definition around point to an attached session of the programming language system.

Text operations

KeystrokesCommand nameExplanation
M-} forward-paragraph

Move forward to end of paragraph.

M-{ backward-paragraph

Move backward to start of paragraph.

M-h mark-paragraph

Set the region to the current paragraph.

Use M-x kill-paragraph

Kill forward to end of paragraph.

M-u upcase-word

Convert following word to upper case, moving over it.

M-l downcase-word

Convert following word to lower case, moving over it.

M-c capitalize-word

Capitalize the following word, moving over it.

C-x C-u upcase-region

Convert the region to upper case.

C-x C-l downcase-region

Convert the region to lower case.

Use M-x capitalize-region

Convert the region to capitalized form.

M-q fill-paragraph

Fill paragraph at or after point.

Use M-x fill-individual-paragraphs

Fill paragraphs of uniform indentation within the region.

Movements, systematically

The keybindings for common movement commands are fairly systematic, as shown in the following table. The entries shown in lighter type are other ways of regarding keystrokes that appear elsewhere in the table.

Unit First Backward Forward Last Mark Delete
Character C-a C-b C-f C-e C-d
Word M-a M-b M-f M-e M-@ M-d
S-expression C-M-a C-M-b C-M-f C-M-e C-M-@ C-M-k
Depth C-M-a C-M-u C-M-d
Function C-M-a C-M-e C-M-h
Line M-< C-p C-n M-> C-k
History M-p M-n
Sentence M-{ M-a M-e M-} M-k
Paragraph C-x [ M-{ M-} C-x ] M-h
Page M-< C-x [ C-x ] M-> C-x C-p

Transposition

The transpose- commands exchange two adjacent pieces of text. The pattern of modifiers is like that shown at Movements, systematically. With a prefix, rotates pieces of text, and with 0 as the prefix, exchanges the pieces at point and mark.

KeystrokesCommand nameExplanation
C-t transpose-chars

Interchange characters around point, moving forward one character.

M-t transpose-words

Interchange words around point, leaving point at end of them.

C-x C-t transpose-lines

Exchange current line and previous line, leaving point after both.

C-M-t transpose-sexps

Like M-t but applies to sexps.

Idempotent operations (etc)

These operations all go to a certain state in one operation, and are more efficient than using a repeating action and watching for when it has repeated enough, undoing any overshoot, etc.

KeystrokesCommand nameExplanation
M-m back-to-indentation

Move to left margin.

C-x C-n set-goal-column

Constrains movement up and down, to stay in the same column; with prefix, releases the constraint.

M-SPC just-one-space

Leaves just one space at point.

M-\ delete-horizontal-space

Leaves no spaces at point.

C-x C-o delete-blank-lines

Leaves one or none lines at point.

Rectangles

A rectangle in Emacs is a series of sections of successive text lines, of the same length and same starting column.

KeystrokesCommand nameExplanation
C-x r k kill-rectangle

Delete the region-rectangle and save it as the last killed one.

C-x r y yank-rectangle

Yank the last killed rectangle with upper left corner at point.

C-x r o open-rectangle

Blank out the region-rectangle, shifting text right.

C-x r c clear-rectangle

Blank out the region-rectangle.

C-x r t string-rectangle

Replace rectangle contents with a specified string on each line.

If you're drawing ASCII diagrams, you may well find picture-mode (draws in eight directions using keyboard) and artist-mode (freehand drawing with mouse) useful.

Registers

KeystrokesCommand nameExplanation
C-x r s copy-to-register

Copy region into a register.

C-x r i insert-register

Insert contents of a register.

C-x r r copy-rectangle-to-register

Copy rectangular region into register.

C-x r i insert-register

Insert contents of register a specified register. (a specified register is a character.)

Use M-x list-registers

Display a list of nonempty registers saying briefly what they contain.

Window and frame commands

KeystrokesCommand nameExplanation
C-x 0 delete-window

Remove the selected window from the display.

C-x 1 delete-other-windows

Make the selected window fill its frame.

C-x 2 split-window-vertically

Split current window into two windows, one above the other.

C-x 3 split-window-horizontally

Split current window into two windows side by side.

C-x 4 f find-file-other-window

Edit the specified file, in another window.

C-x 4 b switch-to-buffer-other-window

Select the specified buffer, in another window.

C-x 5 0 delete-frame

Delete the present frame, permanently eliminating it from use.

C-x 5 1 delete-other-frames

Delete all frames except the selected one.

C-x 5 2 make-frame-command

Make a new frame, and select it if the terminal displays only one frame.

C-x 5 f find-file-other-frame

Edit the specified file, in another frame.

C-x 5 b switch-to-buffer-other-frame

Switch to a specified buffer, in another frame.

C-x o other-window

Select the next window on this frame.

Commands

M-x

KeystrokesCommand nameExplanation
M-x execute-extended-command

Read function name, then read its arguments and call it.

C-h w where-is

Print message listing key sequences that invoke the given command.

C-h k describe-key

Display documentation of the function invoked by the following keystrokes.

C-h c describe-key-briefly

Print the name of the function invoked by the following keystrokes.

C-h a apropos-command

List the commands whose names match a given regexp.

M-: eval-expression

Read an Emacs-Lisp expression in the minibuffer, and run it.

Command history

These commands browse the command history, in the form of the fragments of Lisp that you'd have to write to do the same thing in an Emacs-Lisp program. You can edit the recalled command before re-running it.

KeystrokesCommand nameExplanation
C-x M-: repeat-complex-command

Bring up the most recent complex command, in the minibuffer.

M-p previous-history-element

Move to the previous history element.

M-n next-history-element

Move to the next history element.

RET exit-minibuffer

Run the currently selected recalled command.

Use M-x repeat-matching-complex-command

Bring up the most recent complex command that matches a given regexp, in the minibuffer.

Use M-x list-command-history

Bring up a browsable buffer containing recent commands.

Completion

In some places (such as entering a filename, or a command name) ``completion'' is available, where Emacs fills in text from a known set of choices.

KeystrokesCommand nameExplanation
? minibuffer-completion-help

Display a list of possible completions of the current minibuffer contents.

TAB minibuffer-complete

Complete the minibuffer contents as far as possible.

SPACE minibuffer-complete-word

Complete the minibuffer contents at most a single word.

RETURN minibuffer-complete-and-exit

If the minibuffer contents is a valid completion then exit.

Tip: if the completion possibilities include a plain extension to the current word, and a hyphenated one, pressing the SPACE key at that point will select the hyphen.

Dynamic abbreviation

KeystrokesCommand nameExplanation
M-/ dabbrev-expand

Expand previous word "dynamically". This searches back through the buffer for words that start the same way as the one you have started to type, and fills in the rest of the word.

Doing this multiple times without any other actions inbetween will try successive other words that start the same way. If it runs out of possibilites in the preceding text, it tries the following text, then the text of other buffers.

If done when not in a word, it offers the word that followed the preceding copy of the preceding word. So, for example, if you have occurrences of fprintf(stderr,...) around, you can enter another by typing (typically) fp M-/ ( M-/. The first one will complete the fprintf, and the second one will add the stderr.

Incremental search

Entering isearch

KeystrokesCommand nameExplanation
C-s isearch-forward

Do incremental search forward.

C-r isearch-backward

Do incremental search backward.

C-M-s isearch-forward-regexp

Do incremental search forward for a specified regexp.

C-M-r isearch-backward-regexp

Do incremental search backward for a specied regexp.

During isearch

KeystrokesExplanation
C-s

At the start of a search, resume the previous search, going forwards; when already searching, search for the next occurence of the search string.

C-r

At the start of a search, resume the previous search, going backwards; when already searching, search for the previous occurence of the search string.

C-w

Include the rest of the current word, as part of the search string.

C-y

Include the rest of the current line, as part of the search string.

M-y

Add the top item from the kill-ring to the search string.

M-n

Move backwards and forwards through the history of search strings.

M-p
M-%

Switch to query-replace, with the current search string as the query string.

M-r

Toggle regexp searching.

Narrowing

``Narrowing'' means hiding part of the buffer, leaving just a contiguous region available for editing. In effect, it sets a temporary effective start and end of the buffer.

KeystrokesCommand nameExplanation
C-x n n narrow-to-region

Restrict editing in this buffer to the current region.

C-x n d narrow-to-defun

Make text outside current defun invisible.

C-x n p narrow-to-page

Make text outside current page invisible.

C-x n w widen

Remove restrictions (narrowing) from current buffer.

Replacing strings and regexps

KeystrokesCommand nameExplanation
Use M-x replace-string

Replace all occurrences of a given string, from point onwards, by a given replacement.

C-M-% query-replace

Query-replace all occurrences of a given string, from point onwards, by a given string.

Use M-x replace-regexp

Replace all occurrences of a given regexp, from point onwards, by a given replacement.

C-M-% query-replace-regexp

Query-replace all occurrences of a given regexp, from point onwards, by a given replacement.

Regexp syntax

Regexp elementExplanation
.

Match any character.

[abc]

Match any of characters a, b, or c.

[^abc]

Match any characters except a, b, or c.

a*

Match a zero or more times, taking as many matches as possible.

a+

Match a one or more times, taking as many matches as possible.

a?

Match a zero or one times, taking as many matches as possible.

a*?

Match a zero or more times, taking as few matches as possible (that is, if a piece of text could match this or match the next thing in the regexp, it will be taken to match the next thing).

a+?

Match a one or more times, taking as few matches as possible.

a??

Match a zero or one times, taking as few matches as possible.

^

Match the start of the line.

$

Match the end of the line.

a\|b

Match either a or b. a and b extend as far as possible in the regexp (see \( .. \)).

\( ... \)

A grouping construct, which limits the \| construct, can be used with *, +, ? etc, and which remembers the text matched in a numbered register.

\(? ... \)

Like \( .. \) but does not use up a numbered register.

\n

Represents the piece of text matched by the nth \( .. \) construct. Mostly used in the replacement text, but may also be used in the search expression to indicate matching a copy of something that has already been matched.

\&

Represents the entire matched text. Used only in the replacement text.

\<

Matches the start of a word.

\>

Matches the end of a word.

\w

Matches any word-constituent character.

\W

Matches any non-word-constituent character.

\sa

Matches any character of syntax class a. Common syntax classes are:

- Whitespace
. Punctuation
_ Symbol
w Word-constituent
( Opening bracket
) Closing bracket

Which characters have which syntax class depends on the mode of the current buffer. Use C-h s to see the current syntax values.

\Sa

Match any character not of syntax class a.

a\{m,n\}

Match a between m and n times.

a\{n\}

Match a, n times.

This is just the most commonly useful, and maybe a few others; there are a few more that I haven't listed here, which are of more use when programming Emacs, or when editing text in a mixture of western and oriental characters.

Regexp replacement syntax

Replacement elementExplanation
\&

Insert the whole matched text

\n

Insert the text matched by the nth \(...\) construct in the pattern

\#

Insert the number of replacements done so far -- useful for numbering lists

\,lisp-expression

Insert the result of evaluating lisp-expression; \1 etc are allowed, e.g. \,(capitalize \1)

Commands during query-replace

During a query-replace or query-replace-regexp, you can confirm or skip each possible replacement, and do some other actions as well.

KeystrokesExplanation
SPC

Replace this occurrence, then move to the next one.

DEL

Skip to the next occurrence.

ESC

Exit query-replace

.

Replace this occurrence, then exit query-replace

,

Replace this occurrence, but don't move to the next one

!

Replace all remaining occurrences.

C-r

Enter a recursive edit

C-w

Delete this occurrence, then enter a recursive edit

^

Go back to the previous occurrence.

C-l

Redisplay the screen.

e

Edit the replacement string.

C-h

Display the options.

Keyboard macros

KeystrokesCommand nameExplanation
C-x ( kmacro-start-macro

Record subsequent keyboard input, defining a keyboard macro.

C-x ) kmacro-end-macro

Finish defining a keyboard macro.

C-x e kmacro-end-and-call-macro

Call last keyboard macro, ending it first if currently being defined.

Bulk operations

KeystrokesCommand nameExplanation
Use M-x append-to-buffer

Append to specified buffer the text of the region.

C-x i insert-file

Insert contents of file a specified filename into buffer after point.

Use M-x write-region

Write current region into specified file.

C-x C-w write-file

Write current buffer into specified file.

See also Shells for how to transfer text between buffers and external programs.

Directory editing

KeystrokesCommand nameExplanation
C-x d dired

"Edit" directory a specified dirname--delete, rename, print, etc. some files in it.

f dired-find-file

In Dired, visit the file or directory named on this line.

o dired-find-file-other-window

In Dired, visit this file or directory in another window.

m dired-mark

Mark the current (or next specified number) files.

u dired-unmark

Unmark the current (or next specified number) files.

d dired-flag-file-deletion

In Dired, flag the current line's file for deletion.

~ dired-flag-backup-files

Flag all backup files (names ending with `~') for deletion.

x dired-do-flagged-delete

In Dired, delete the files flagged for deletion.

R dired-do-rename

Rename current file or all marked (or next specified number) files.

C dired-do-copy

Copy all marked (or next specified number) files, or copy the current file.

g revert-buffer

Replace current buffer text with the text of the visited file on disk.

Shells

KeystrokesCommand nameExplanation
M-! shell-command

Execute a command in inferior shell; display output, if any. With prefix argument, insert the command's output at point.

M-| shell-command-on-region

Execute a command in inferior shell with region as input; with prefix arg, replace the region with the command output.

Use M-x shell

Run an inferior shell, with I/O through a specified buffer (which defaults to `*shell*').

RET comint-send-input

Send input to process.

C-c C-o comint-delete-output

Delete all output from interpreter since last input.

C-c C-r comint-show-output

Display start of this batch of interpreter output at top of window.

There are some specialized variants of M-x shell for running particular kinds of programs, such as Lisp interpreters.

If you want more than one shell buffer, rename `*shell*' using M-x rename-buffer, then the next M-x shell, instead of finding the existing shell buffer, will create a new one.

Compilation

KeystrokesCommand nameExplanation
Use M-x compile

Compile the program including the current buffer. Default: run `make'.

C-x ` next-error

Move to next error message and corresponding source code.

Use M-x ediff

Compare and merge two (or three) files interactively.

C-x v v vc-next-action

Do the next logical version control operation on the current file (check in, check out, etc).

Use M-x gdb

Run a debugger on a given program. Supports similar features to graphical IDEs (windows displaying variables, etc).

Tags and imenu

Tags files are index files pointing to function and variable definitions, typically within a project directory tree.

KeystrokesCommand nameExplanation
visit-tags-table

Select which tags file to use. (Use the external command etags to create tags files.)

M-. find-tag

Find tag (in current tags table) whose name contains a specified tagname.

M-, tags-loop-continue

Continue last M-x tags-search or M-x tags-query-replace command.

tags-query-replace

Like query-replace but throughout all files mentioned in the current tags table

Use M-x imenu

Jump to a place in the buffer chosen using a buffer menu or mouse menu.

Input methods

Input methods help you to type text in languages which your keyboard doesn't support fully. For example, you can type Japanese as Romaji (romanized transliteration) and it will convert it to kana as complete syllables are recognized from the letters, and to kanji as complete words are recognized from the kana.

KeystrokesCommand nameExplanation
C-x RET C-\ set-input-method

Select and activate input method a specified input-METHOD for the current buffer.

C-\ toggle-input-method

Enable or disable multilingual text input method for the current buffer.

C-x 8 weird stuff

Follow this with a character sequence that, if overtyped, would like a bit like the character you want; for example, to get an a with an umlaut, type C-x 8 " a.

Miscellaneous

KeystrokesCommand nameExplanation
C-x C-x exchange-point-and-mark

Exchange the mark and the point. Useful for checking whereqthe mark is, and other things.

M-z zap-to-char

Delete up to, and including, the next occurrence of a given character.

C-x = what-cursor-position

Describes the cursor position, and the character at that position.

M-= count-words-region

Display the number of characters, words, and lines, in the region

Use M-x delete-matching-lines

Delete all lines starting after point containing a given regexp.

Use M-x delete-non-matching-lines

Delete all lines starting after point except those containing a given regexp.

C-x TAB indent-rigidly

Indent all lines starting in the region sideways by specified number columns.

C-x h mark-whole-buffer

Put point at beginning and mark at end of buffer.

Use M-x delete-trailing-whitespace

Delete all the trailing whitespace across the current buffer.

Use M-x tabify

Convert multiple spaces in region to tabs when possible.

Use M-x untabify

Convert all tabs in region to multiple spaces, preserving columns.

C-x C-q toggle-read-only

Change whether this buffer is visiting its file read-only.

Use M-x auto-fill-mode

Switch auto-fill-mode on or off.

Use M-x calendar

Display a browsable calendar.

Use M-x phases-of-moon

Display the quarters of the moon for last month, this month, and next month.

timestamps

Emacs as your main environment

Emacs can do many things beyond editing files, and many people use it as their main computing environment. Here are some more things that you can do with Emacs (mostly built-in, others downloadable):

Mail
Emacs has facilities for sending and receiving email; using these gives you the best possible integration with editing, as well as the same, or related, commands available for both.
Typing break reminders
type-break-mode
Playing music
emms, the Emacs Multi-Media System, manages and plays playlists
Web browsing
There is a web browser (rather slow) written in Emacs-Lisp, and a (faster) interface to an external text-mode browser. It is also possible to send a command and URL from Emacs to a conventional browser, using M-x browse-url.
Games
Some games and other entertainment are built-in to Emacs, and more are available for download.
Speaking Emacs
Emacspeak and speech-d are speech output interfaces to Emacs (including for its web browsers).

Emacs and windowing systems

If you use Emacs as your main work environment, on Linux (or other systems using X-windows) you might like to try the ``ratpoison'' window manager, which is designed to work well in that style; it doesn't have any of the clutter that most ``desktop'' systems do, and instead dedicates the entire screen to applications (typically one window, with Emacs in it), although you can split it into non-overlapping panes, and put separate applications in each pane).

Coda

The first command given in the tutorial is how to get out of Emacs. By the time you're using most of the commands given here, you may well be using Emacs as your main work environment, and only shutting it down when you shut the machine down or upgrading to a newer version of Emacs. I know someone who had an Emacs session that had lasted 18 months and accumulated 10000 buffers! So let's amend the explanation for that first command:

KeystrokesCommand nameExplanation
C-x C-c save-buffers-kill-emacs

Offer to save each buffer, then quit Emacs. You don't normally need to do this.

[emacs] [computing]
John C. G. Sturdy
[John's home] Last modified: Thu Mar 20 20:00:28 GMT 2014