Emacs Guide

Starting Emacs

Type "emacs &" (the & will make it open in a separate window).

If you want to load a file into emacs, type "emacs filename &"

Basic Functions
Ctrl+x Ctrl+f Loads a file or starts a new one
To load a file, type in the name
To create a new file, just type in the name of a file that doesn't exist, and emacs will create a new buffer for you.
Ctrl+x Ctrl+s Saves the current buffer to a file
Ctrl+x Ctrl+w Saves the current buffer to a different filename (similar to Save As)
Emacs will prompt you for a new filename
Ctrl+x Ctrl+c ends your emacs session
If you haven't just saved, emacs will prompt you, just answer yes or no.
-space- completes the file or command (same way Tab works in terminal windows)

Text Editing Shortcuts
Ctrl+a moves cursor to start of line
Ctrl+e moves cursor to end of line
Alt+a moves cursor to beginning of sentence
Alt+e moves cursor to end of sentence
Ctrl+v page down
Alt+v page up
Ctrl+w cuts a region of highlighted text
Ctrl+y pastes a cut region of text
Ctrl+x i inserts contents of a file where the cursor is placed

For pasting text, you can also highlight using the left mouse button, and then click the middle button. The text will be copied where the mouse is. Alternatively, you can highlight some text. move the cursor, and press Ctrl+y

You can also delete large portions of a file by placing the cursor where you want to start deleting text and pressing Ctrl+space. This will set a mark. Then move the cursor to the end of the text you want to delete and press Ctrl+w
Ctrl+k deletes from cursor to end of line
Alt+k deletes from cursor to end of sentence
Ctrl+d deletes a letter
Alt+d deletes a word
Ctrl+_ undos changes to a file
Ctrl+s searches for a word after the cursor position

More Advanced Editting Commands

Alt+x allows you to access lengthier commands. (This is where the spacebar comes in handy.) Here are some commands that you will find useful:
query-replace Emacs will prompt you for words you want to look for and replace
Alt+% shortcut key for query-replace (No need to press Alt+X beforehand.)
Emacs will only look at text after the cursor, so be sure to place your cursor before executing this command.
Emacs will highlight the word to be replaced. Just press "y" to replace it.
auto-fill-mode Emacs will not wrap text unless you put it in this mode
To turn off auto wrap, just run this command again.
Alt+q Shortcut key for auto-fill-mode. (No need to press Alt+X beforehand.)
Emacs will not wrap text if you go back and edit it. When you edit text, the shortcut key is the best way to wrap a few lines of altered text.
insert-file inserts the text from another file to the cursor position. Emacs will prompt you for the filename.
Ctrl+x i shortcut key for insert-file

You can delete columns of text by doing the following:

  1. Move the cursor to the upper left part of the column you want to delete and press Ctrl+space to set the mark.
  2. Move the cursor to the bottom right part of the column you want to delete and press Alt+x and entering delete-rectangle in the command section.
  3. This will delete a rectangle of text described by the upper left and lower right cursor positions.

Macros

These are extremely useful when you have to do something more complex than query-replace. Macros are based on repeating patterns, so make sure you start your macro at the appropriate place (a beginning of the first line is nearly always good).

Start with "Cntr+x (". Now you are ready to define your macro. Complete all the necessary steps and do not forget to place the cursor at the appropriate position for the macro to be repeated (e.g. a beginning of the next line). Entering "Cntr+x )" completes your macro. To run it type "Cntr+x e" as many times as necessary. Alternatively, if you know how many times the macro has to be repeated, type "Cntr+number Cntr+x e", where "number" is the number of repetitions.

Openning Multiple Buffers at One Time
Ctrl+x 2 splits the screen into two rows
The current buffer you are in will be loaded into both rows. Just move your cursor into one of the rows, and press Ctrl+x Ctrl+f to open or load a new buffer.
When you want to execute commands in a certain buffer, be sure that your cursor is placed in the correct section.
Ctrl+x 3 splits the screen into two columns
Follow the same rules as above
Ctrl+x 1 changes the screen to just one window
Be sure that your cursor is placed inside the buffer you want to keep in the single window before you execute the command.