Skip to main content

Emacs

Before you Start!

An important key sequence is C-g (Control-g).  You'll see why you need this in a moment.

In Emacs lingo, C followed by a dash, followed by a letter (Example: C-x) means Control (Crtl Key) followed by that sequence, in this case, 'x'

For example: C-c would mean control-c to be held down at the same time (like a copy operation in Windows). Don't let go of the Control key before hitting 'c'.

Another Example: Multiple Sequences: C-x C-c, would mean, Control-x followed by Control-c.  This sequence will exit emacs.

Another Example: Multiple Sequences: C-x s, would mean Control-x followed by just the letter 's'.  This sequence will perform a save.


Also in Emacs lingo, we have the Meta key.  (On most systems this is the 'Alt' key on your keyboard.  If the 'Alt' key is not working. substitute this with your 'ESC' key)

For example: M-x would mean Alt-x in the same way that you could use a Control-key sequence. 

- Hold down 'Alt' followed by 'x' and then release both buttons

If your system is not accepting Alt-x as a keyboard input for Emacs, 'ESC' can be used in the same way. 

- Hold down 'ESC' while hitting 'x' and then release both commands


M-x is known as command mode.  You can type built-in commands here like: 'search-forward'  which will start a text search of the file you are currently using.

Note: there is normally a keyboard shortcut associated with these commands.  For example, search-forward is C-s (Control-s)

If you are 'stuck' in some command, or 'stuck' in command mode.  Use C-g (Control-g) to get out!

Buffers: Basic

A 'Buffer' is basically a file you can edit

Quit: C-x C-c

Save File: C-x s

Search-forward: C-s

Search-backward: C-r

Start-of-file: M - >           (Meta Shift >)

End-of-file: M - <             (Meta Shift <)

Buffers: Split-Screen

Split screen horizontally: C-x 2 -- This will split the buffer into two screens the first time you run it

Split screen vertically: C-x 3

Switch to other splits: C-x o -- This will switch between the top and bottom if you have one split.  Or loop through all splits if you have more than that

Close split: C-x 1 -- This will close the split, but not close the file!  The file is still open!  See 'Swap buffers' below

Buffers: Advanced

When opening multiple files, you need a way to switch between them. After an 'Open file' operation, the screen will switch to this new file.  Use 'Swap buffers' to get back to the original file

Open file: C-x C-f

Swap buffers: C-x b

Open buffer list: C-x C-b -- Use this to see all the files you have open.  Once the buffer list is shown, use 'Switch splits' to switch to the buffer list, and then hit enter on the buffer you want to switch to.

Rectangle operations

Copy rectangle: C-x r M-w

Cut rectangle:  C-x r k

Paste rectangle: C-x r y

Offset rectangle with whitespace: C-x r o

Replace rectangle with whitespace: C-x r c

Macro stuff

Define macro: C-x ( <macro> C-x )

Run macro: C-x e

Run command 20 times: M 2 0

Repeat macro for each line: (Select region to operate on)  M apply-macro-to-region-lines