As not to give false ideas of what this post is about, let's lay it out up front. I'm going to show you how to be able to get work done in emacs. You're not going to be an emacs guru after reading this. You're not even going to be as productive as possible. That being said, you will be able to accomplish your work as well as you could as a mid-level vim user.
Note: For those unfamiliary with emacs shortcut notation, C-m means ctrl+m. M-x refers to meta+x. For me (a `carbonemacs`_ user, my meta key is command. It could also be alt or escape so experiement if that doesn't work for you.
Configuration for an Effective Session
Following Steve Yegge's epic post, there are a few things in there that you might question. I know I did. He suggests swapping the places of capslock and control. At first this just seemed pointless. After 2 days of trying the keyboard shortcuts without it, I got a case of emacs pinkie (pain from over use). Taking his suggestion, however, has proven to be quite helpful. It keeps my fingers on the home row a majority of the time which allows for speedier typing. Another change he suggested, C-w as kill-word, seemed to be another one of those small gains that wasn't worth doing. I can attest, however, that if you can type at a reasonable speed (50wpm+) its a godsend. rewriting an entire word is actually much quicker than backspacing 10 times to get rid of your last word. While they seem like small gains, its always the tiny stuff that makes the difference, isn't it?
Effective Movement
Moving around in an editor is super important. We spend a majority of our time editing moving from one place to another. Moving around vertically is done via C-v (page down) and M-v (page up) if you want to go a screenful at a time or C-n (next line) and C-p (previous line) if you want to go a line at a time. Arrow keys also work here. To go to the beginning or end of a document, the shortcut is M-< and M-> respectively. (Yes, there is a shift in there. Emacs style is that you don't mention the shift, just the resulting character.)
Horizontal movement can be done in one of three ways. A line at a time, C-a (start of line) or C-e (end of line), a word at a time, M-f (forward) or M-b (backwards) or a character at a time, C-f (forward) or C-b (backwards) or arrow keys. I rarely use the per-character movement commands, opting instead for arrow keys. This is likely an inefficency, but old habits die hard. Don't worry if you need to write these down or something. I had to keep a cheat sheet handy for a bit.
Text Surgery
Now that we have you moving around the editor, you need to know how to slice and dice things like a waiter at Benihana. Its important to note that emacs doesn't have a true delete commmand. It operates only on a copy or cut basis. This seems weird at first, but its really quite nice.
To kill (cut) an entire line from your cursor to the end of line, you press C-k. If you want the entire line gone, you combine move to start of line and kill line together and you get C-a C-k. Its important to know that kill line doesn't kill the whitespace at the end of a line. You can press C-k again on the empty line to remove it. I'm not entirely "enlightened" as to why that is yet, but Yegge's article offers fair enough reasoning for it, so I'm willing to live with that for now. One important caveat to this rule is that if you are killing multiple lines at a time C-4 C-k (kill for lines), it WILL eat the newline.
Take too much text? You can undo with the key combo C-/ . C-_ also works, but its crazy out of the way. Learn C-/ and thank me later. As I said earlier, emacs doesn't really have a delete command, opting for cut instead. To paste the lines you just cut, you can use C-y (which stands for yank. This might be confusing for vim users, but in emacs world, you yank things from your kill ring).
The kill ring is a very beautiful thing. Instead of a clipboard that holds your last copied bit of info, emacs offers a kill ring which is
a list of things you've previously killed (cut). To access it, press C-y to yank (paste) the last item from the kill ring. If that isn't what you want, you can use M-y to cycle through the kill ring values until you get to the item you're aiming for.
The next in the series of emacs conver.. err.. learning... I'll be going over some of the packages I consider to be must-haves. You can get the RSS feed using your browser's default settings or pick it up at http://justinlilly.com/blog/feeds/latest/
Hit me up in the comments if you have questions.
About C-k behaviour. I think it's more flexible that way. It can empty a line or remove rest of the line, delete line(s) and join lines. Consider you want to join lines. Pressing C-k at the end of line the newline character is deleted and the next line is joined to the current line. I think it makes editing a bit faster because user can do different but related things with only one keybinding.
C-S-Backspace is the complete delete line command.
Posted by DtW on Nov 15, 2008 at 10:38 AM