Friday 22 February 2008

Emacs Cheat Sheet

I have been trying to learn emacs. Note the use of the word learn. It's not just something you can just use, you have to learn and get used to a heap of things before you can meaningful use it. There are lots of cheatsheets for emacs out there but I want to compile my own one with just the stuff that is most important to me.

The best way to learn emacs is probably by going through a tutorial like this one and the built-in tutorial but what's missing is a quickstart tutorial for emacs...

Here's my attempt:

C-x Ctrl and press x
M-x Meta/Alt key and press x
C-x y Ctrl and press x and then press y
M-x y Meta/Alt key and press x and then press y

Getting Started

Installing on Debian/Ubuntu: sudo apt-get install emacs

Starting a new file (from the commandline):
emacs filename

Starting a new file (from inside Emacs):
C-x b and type the name of your new file

C-h t - start the builtin tutorial
C-g Abort a command

Saving
C-x C-s Save
C-x s Save all (or a few at a time)


Navigation
C-a Beginning of line
C-e End of line
M-f Forward one word
M-b Backward one word


Editing

C-d == DELETE, deletes character to the right
backspace == Deleting, deletes character to the left
M-d Delete word
C-k Delete to the end of the line
C-x u or C-_ Undo (Redo is more complicated)


Cutting, Copying and Pasting
While copying is still copying, what I think 90% of people know as cutting and pasting is not called as such in Emacs. We have Killing and Yanking. Basically kill == cut, yank == paste. (The name yank is a bit counter-intuitive at first I think. It made me assume it was cut. like you were yanking it out of the text, but in fact you're yanking it back into the text.) Emacs also has the concept of a kill-ring. That's just a fancy name for a clipboard.

C-k Kill/Cut to the end of the line
C-SPACEBAR - mark the start of a piece of text followed one one of the following:
M-w Copy
C-w Kill/Cut

C-y Paste (yank)



Find/Replace

C-s Find... (Search) - This does some cool highlighting of matches
C-s C-s Find again
M-% Replace
C-g Abort


Moving between buffers (fancy name for an open file)

C-x b switch-to-buffer. Prompts for a buffer name and switches the buffer of the current window to that buffer.
C-x C-b list-buffers.
C-x k kill-buffer.

Navigating between open windows (split views and stuff)
C-x o other-window. Switch to another window, making it the active window.
C-x 1 delete-other-windows. Deletes all other windows except the current one, making one window on the screen.
C-x 0 delete-window. Deletes just the current window
C-x 2 split-window-vertically
C-x 3 split-window-horizontally

Exiting
C-x C-c - exit, prompts for saves
C-x C-z - suspend


Thats all for now!

0 comments: