Unix Reference



emacs is a text editor that was modified by Richard Stallman (also see Richard Stallman on Wikipedia, who has an interesting outlook on life.

Emacs has over 10,000 built-in commands, and it also contains a complete LISP intrepreter that allows you to create any command you want.

  1. To open a new file called "test", run
$ emacs test

If test doesn't already exist, emacs will create a new file.

  1. Type anything you want into the file.

  2. Commands in emacs are usually a combination of Ctrl and other keys.

    • Use Ctrl+X followed by Ctrl+S to save.
    • Use Ctrl+X followed by Ctrl+C to quit.

For more, check out The CS 107 Guide to emacs


The emacs refcard


Emacs: The Bare Essentials

Seriously, take a moment to do this!! Much of what gives you comfort in an editor is just muscle memory, so you should plan on spending time this week just typing something, anything!

In coding, it is often necessary to jump directly to a particular line number of your code file. For example, when the compiler complains that you have an error on line 129, it is helpful to be able to jump directly to line 129. In emacs you do this by pressing M-g g . Where M is used to represent either the Alt key or the Esc key. So in this case you would press Alt+g followed by g followed by 129.

M-g g 129

In coding, it is often necessary to search the file for a particular word or phrase. For example, if you want to change the name of the variable foo to be something more descriptive so that you will not lose style points, like longest_string, you will want to search the file for all occurrences of "foo". In Emacs you do this by pressing C-s . Where C is used to represent the Ctrl key. So in order to search for "foo", you would do the following:

C-s foo

Then you would continually press C-s to move to the next occurence or C-r to go to the previous occurence. Back to contents