Laura Lindzey

robots, science, code

Apostasy, Step 1: Surviving Vim

October 17, 2015

My colleagues objected to installing emacs on our robot and I find nano woefully insufficient, so I finally admitted that I have to learn vim. Until recently, all I knew was :q!, and I used it with extreme prejudice.

It took me a while to not hate vim, and I still prefer emacs despite not being a power-user in the least. My problem with vim is that I really struggle with remembering which mode I am in. I think the key here is to always leave it in command mode unless you're actively inserting text. I should have taken the hint from how command mode is also called normal mode, but it took a while for this to click.

The other main thing to realize is that compands are composable, such that :w is save and :q is quit, so :wq is save and quit. I suspect that this becomes even more powerful once you're more fluent.

There have been silver linings for me:

  • I can use the default GNU screen configuration on the robot without the usual Ctrl-a headache in emacs.
  • I've fallen in love with the "delete to" command. It is exactly how I frame the operation in my head, and I've yet to find an emacs alternative that doesn't require lots of repetitive keystrokes.


  • Why the heck would you use the least-accessible key on the keyboard for the most-critical key in vim? I assume that everybody remaps it: I chose CapsLock, which was a win all around.

  • This post about how vim's big idea is composability did a great job putting editor history into perspective for me.

  • There's a game for learning vim shortcuts!


For my own reference, I'm documenting the equivalent commands as my fingers reach for the emacs shortcuts:

emacs vim description
(none) Esc enter normal/command mode
(none) i before current character, drop into insert mode
Ctrl‑x Ctrl‑c :q quit
:qa quit all (appending 'a' applies to all buffers)
:q! quit w/o saving (appending '!' forces the command)
Ctrl‑x Ctrl‑s :w save
Ctrl‑x Ctrl‑f :e open file; use tab to cycle through existing files
Ctrl-a ^ go to start of line
I go to start of line, drop into insert mode
Ctrl-e $ go to end of line
a after current character, drop into insert mode
A end of line, drop into insert mode
o insert line below, drop into insert mode
O insert line above, drop into insert mode
Ctrl-n j next line
Ctrl-p k prev line
h prev character
l next character
Alt-< gg start of file
Alt-> G end of file
Meta-x 2 :sp horizontally splits the pane
Meta-x 3 :vs vertically splits the pane
Ctrl-x o Ctrl-w-w cycle through pane
Ctrl-x 0 :q kill current pane
Ctrl-x k kill current buffer in pane
Ctrl-k D cut from current position to end of line
dd cut entire current line
dt. deletes from current position to just before '.'
df. deletes from current position, including '.'
dT. (make the prev comman, but backwards)
d2t. deletes from current position until the second occurrence of '.' (In general, can add numbers
yy yank line
Ctrl-Space select region
Ctrl-w yank selected region
Alt -w copy selected region
Ctrl-y p paste what you just cut/copied
Ctrl-_ u Undo
Alt-% :%s/<s1>/<s2>/gc find-and-replace globally with confirmation

(My learning curve was made much less frustrating thanks to a generously helpful colleague. Thanks Mark!)