OSU Navigation Bar

The Ohio State University

Department of Statistics

Cockins Hall
rollover image OSU Statistics
            Home

design element

OSU Statistics

Home

News

Research & Consulting Groups

People

For Visitors

For Prospective Students

For Current Students, Staff & Faculty

Contact Us



rollover image

For Current Students & Faculty

rollover image

Courses

rollover image

Links

rollover image

Computer Support

rollover image

Internal Documents

rollover image

webmail

Emacs Quick Reference

Note: to access the emacs on-line tutorial, type esc-x help-with-tutorial. To access the help on individual keys type esc-x help-for-help. The esc is the escape key in the upper left of the keyboard, thus hit it and then the x key.

In this guide typographical conventions are as follows: c-c, C-c, or ^ C all mean hit the c key while holding down the control key. M-x, m-x, esc-x, or Esc-x mean hit the escape key, release it, and then hit x.


Moving Around

Some common emacs commands for moving point around are:

C-b (backward-char) backward one character

C-f (forward-char) forward one character

C-p (previous-line) up one line

C-n (next-line) down one line

M-< (beginning-of-buffer) beginning of buffer

M-> (end-of-buffer) end of buffer

C-v (scroll-up) forward one screen, with 2 lines overlap

M-v (scroll-down) backward one screen, with 2 lines overlap

Notice that each command has a longer, descriptive name given in parentheses. This is the actual name of the command, as opposed to the short key sequence which happens to be set up to run the command.


Reseting Emacs

Sometimes you will start typing an emacs command and then realize you don't really want to finish it. To clear away the partial command, use the C-g (keyboard-quit) command. Other times, you may find that emacs is doing strange things which you didn't want or expect. Try using the C-g command. Sometimes you need to give 2 or 3 C-g commands to reset emacs.


Removing Text

Among the commands for removing parts of the text are:

DELETE (delete-backward-char) character before point

C-d (delete-char) character after point

M-DELETE (backward-kill-word) word before point

M-d (kill-word) word after point

C-k (kill-line) from point to end of current line


And Getting It Back

emacs makes a distinction between killing and deleting text. Portions of text which have been killed can be brought back using the command C-y (yank); if point is moved between the kill command and the yank command, the text is inserted immediately after the new location of point. If you do lots of C-k one right after the other - NOTHING ELSE BETWEEN THEM - then C-y will yank them all back.


Searching

To have emacs search for some string of characters, type C-s (isearch-forward). emacs will prompt you to enter a character string in the echo area. To continue searching simply repeat the C-s command again. emacs will look for the next occurrence of this same string. To stop the search, hit the escape key. A command which works the same way but searches backward, toward the beginning of the buffer, is C-r (isearch-backward).


Replacing

Suppose you want to change string1 to string2 (from point to the end of the buffer). Use M-% (query-replace); you will be prompted first for the string to be replaced and then for the new string. emacs shows you each occurrence of string1 in turn and allows you to either replace it with string2 or leave it alone. When the cursor stops at an instance of string1, you hit space to replace it, or delete to leave it alone. In either case, the cursor then moves on to the next occurrence. Hitting ! replaces all remaining occurrences. If you hit escape instead, the command stops.


Getting Out

When you are finished editing the buffer you can exit emacs in various ways.

C-x C-s (save-buffer) writes a new version of your file

C-x C-w (write-buffer) writes a new file

C-x C-c (save-buffers-kill-emacs) kills emacs, but gives you a chance to save changes made since the last save-buffer or write-buffer

Do not exit emacs using C-z, as it merely stops the emacs process.


Safety Nets

emacs saves a copy of the original file. The backup file name is formed by suffixing your file name with the character ~.

Note: the default .emacs file in your home directory supresses the backup files. Edit your .emacs to re-enable them.


Commands in the Echo Area: M-x

Many commands are not bound to (connected with) a simple C- or M- sequence. In order to give these commands, you first type M-x. emacs then reads the complete command name in the echo are. For example, the command replace-string replaces all occurrences of one string with a new string, from point to the end of the buffer.


Blocks of Text

It is often useful to handle large chunks of text at once. For example, you may want to move a whole paragraph to a different position in the buffer. To do this, first set a mark before the first character in the block by moving point to that location and using C-SPACE (set-mark-command). Then move point just after the last character in the block. Then C-w (kill-region) will kill the block. Now it can be yanked back anywhere in the buffer, just like any other killed text. Just move point to the new location and use C-y (yank).



If you have trouble accessing this page, or need an alternate format contact webmaster@stat.osu.edu.