Day 1: Vim to Emacs

Today’s my first day using Emacs at work. I picked a cognitively easy task (HTML markup editing) to practice on. Being somewhat wired up in Vim, I found myself thinking in terms of Vim operations, and trying to replicate it in Emacs. I know it’s not the most orthodox way of learning/doing Emacs, but it was the only way I knew to get started, and it’s helped me cope so far.

Here is my personal Vim to Emacs conversion table. It’s what I’ve been able to pick up and use fairly proficiently so far, in the order that made most sense to me as I picked the tool up.

“-” in the Vim column means I don’t know how it’s done, rather than Vim not being able to perform it. I expect that all these keys would work on a plain vanilla Emacs 23 install with no configuration or extra scripts added on.

You notice that I’ve used ctrl- and alt- notations directly instead of C- and M- which is the Emacs convention. I’ve done so because that’s what the labels say on the keyboard I use. Also,ย my brain is already bogged down enough making the cognitive leaps from Vim to Emacs, it doesn’t need to be bothered by M- to alt- and C- to ctrl- translations for now. If you’re not happy with it, go make your own list. Apologies to Mac users, you’ll have to think of alt- as your cmd- key.

Here we go.

 

Moving around

Vim Emacs
Left h ctrl-b (back)
Right l ctrl-f (forward)
Up j ctrl-p (previous)
Down k ctrl-n (next)
Start of Line ^ ctrl-a (alpha)
End of Line $ ctrl-e(end)
Left by a word w alt-f (forward, bigger)
Right by a word b alt-b (back, bigger)
Next paragraph ctrl-] alt-e (end of next line)
Previous paragraph ctrl-[ alt-a (alpha of previous line)
Start of buffer gg alt-<
End of buffer G alt->

 

Basic file and program operations

Vim Emacs
Cancel command esc ctrl-g
Open file :e ctrl-x ctrl-f
Save file :w ctrl-x ctrl-s
Quit :q ctrl-x ctrl-c

 

Making selections

Vim Emacs
Start selection v ctrl-space

 

Undo, Cut, Copy, Paste, Delete

Vim Emacs
Undo u ctrl-_ or ctrl-/
Cut d ctrl-w
Copy y alt-w
Paste p ctrl-y
Cycle through previous copies - ctrl-y (once) alt-y (to iterate)
Delete x ctrl-d
Delete word dw (to clipboard) alt-d (no clipboard)
Cut line dd ctrl-a ctrl-k
Copy line yy ctrl-a ctrl-space ctrl-e alt-w
Copy entire buffer gg v G y alt-< ctrl-space alt-> alt-w

 

Move around with search

Vim Emacs
Search forward /[search chars] ctrl-s [search chars]
Search backwards ?[search chars] ctrl-r [search chars] (reverse)
Next result n ctrl-s (after Search forward)
Previous result N ctrl-r (after Search backwards)
Clear search :nohlsearch ret

 

Search and replace

Vim Emacs
Whole document :%s/[search]/[replace]/g alt-x replace-string ret [search] ret[replace]alt-x replace-regex ret [search] ret [replace]
Within selection (make selection):s/[search]/[replace]g (make selection)alt-x replace-string ret [search] ret [replace]

alt-x replace-regex ret [search] ret [replace]

 

Opening new lines

Vim Emacs
Before current line O ctrl-a ctrl-o
After current line o ctrl-e ctrl-o

 

Buffer splits

Vim Emacs
Split top/bottom ctrl-w s ctrl-x 2
Split left/right ctrl-w v ctrl-x 3
Close current split ctrl-w d ctrl-x 0
Close other splits ctrl-w o ctrl-x 1

9 thoughts on “Day 1: Vim to Emacs

  1. Important productivity tip: After C-s to search, C-w will increase the search term with the word at point (the cursor).

    So often you move to what you want to search for and type C-s C-w C-s to jump to the next occurrence.

  2. To copy the entire buffer in Vim, there’s no need to enter visual mode. Just: gg y G.

    Rule of thumb: Only use visual mode to link together several movements (for example, gg v G k $ y to copy all but the last line.)

  3. Don’t put too much emphasis on the default keybindings. Emacs is about making it work like you want, so don’t accept everything just because they are default,

    For example, for such a frequent operation as opening files it is stupid to use a a complex key sequence like ctrl-x ctrl-f. I use F3 instead, etc

    The defaults are only suggestions and some of them are bad suggestions, so feel free to override them aggressively, instead of adapting to them. In Emacs there is no one True Way, everyone should use it the way it’s the best for him or her.

  4. Some comments for emacs:

    Select whole buffer: C-x h โ†’ Copy whole buffer: C-x h M-w.

    You can search a regexp with C-M-s.

    Query-replace is bound to M-%. It’s easier to answer ‘!’ to the first query rather than write the full function name. C-M-% for the regexp version.

    In emacs, for copying it’s sometimes easier to just kill and yank. For example,

    C-S-backspace deletes the whole line. To copy a whole line, just do: C-S-backspace C-y.

    M-d deletes a word. To copy a word, do: M-d C-y.

    Etc.

Comments are closed.