It must be noted that my first experience at Hashrocket with vim was a few weeks pairing with Tim Pope (the dude who wrote the rails.vim plugin you should be using) on a rescue mission. I didn’t touch the keyboard for three days – that’s how many hours of watching the man operate it took me to absorb the ridiculously awesome things he was doing. Credit for nearly all of my vim knowledge goes to him. The rest goes to the other Rocketeers who put up with my continual discussions about how to more quickly achieve line edits.
I thought I might sit down and document some key ways that I interact with vim, and then I realized that would take a couple hours and way more thought than I want to put into a drunken Saturday night. So I decided to talk only about targets instead.
In vim are the concepts of actions and targets. Actions are pretty straightforward and are really only useful when combined with targets. Some actions in vim are listed below for reference.
- d: delete
- y: yank (copy)
- c: change
- v: select
- iw: in word
- t: to the character before the next character entered
- f: to the next character entered
- $: to end of line
- ciw: change in word. Whatever the word under the cursor, remove it entirely and put me in insert mode.
- diw: delete in word. Delete the entire word currently under the cursor.
- ct.: change to the next period. Helpful for changing the name of an object, but not the method called on it.
- ct(: change to the next open paren. Helpful for changing the name of a method.
- df): delete to next close paren. Helpful for deleting entire method calls.
- yiw: yank in word. Yank the entire word under the cursor.
- d$ or D: delete to end of line
- c$ or C: change to end of line
- y$: yank to end of line
March 21, 2009 at 7:23 PM
I use (y|c|d)i in combination with arbitrary enclosures (parens, brackets, quotes) a lot. e.g.: ci"
Nothing ground breaking but I use it all day, every day.
March 21, 2009 at 7:49 PM
voxdolo: Wow, that's really cool. I will start training myself on that one immediately. I always had it in the back of my head that i should be more useful than it currently is for me.voxdolo: Wow, that's really cool. I will start training myself on that one immediately. I always had it in the back of my head that i should be more useful than it currently is for me.
March 31, 2009 at 7:41 AM
Thanks Veez! Very helpful quick guide for a VIM Padawan like me.