jquery

gist JS

Wednesday, January 21, 2009

vi in five minutes

For a long time I was pretty merciless with vi users. Me and my IDE posse would hide the icons on their desktop, pants them in front of girls, etc. Mostly though, everything was fine. I used my tools and they used theirs. But as we all know vi stands for virus (well, it's a shortcut for virus) and the vi plot is to take over all the editors on your system. That's why even if you're a loyal IDE-bound code monkey, honking away and generating thousands of lines of configuration XML, home interfaces and remote interfaces, vi still manages to sneak up on you when you do something silly like svn commit and leave off the -m to add your own message.

At this point I would scream out over the cubicle wall 'how in the @*#(! hell do I close vi!!' And they would tell me :q! and I would stop listening after the first colon and just close the offending terminal.

But sometimes we'd get into the issue in a little more depth.
  • I'd say 'vi sucks.'
  • And they'd say: "you just don't know how to use it."
  • And I'd say: "any bleeding editor where the arrow keys only work if your config file asks nicely and I need to switch modes just to type is an abomination."
  • And they say something like "If I want to start all the paragraphs in the document with '========' I just type 'a9 i8= . wtfbbq'."
  • And I just stand there and have pity over their poor abused souls.

But now that I'm on git, what was once a passing annoyance has now become a daily part of life.

Happily this time everything is different. Different because of the actions of one man: Jon.

Much as the heroes of Starship Troopers find that they need to understand the bug to beat the bug, it turns out that spending the five minutes it takes to get a handle on vi is actually worth it. Counterintuitive I know, but it must be done. Jon has written up something that very nicely explains Why, oh WHY, do those #?@! nutheads use vi?

Now, armed with a grounding of wtf vi is trying to do, we are now prepared to do battle with the beast.

And beast it is. With no further ado I present:

vi in 11 simple years

Year 0: Accidentally end up in vi. Close terminal.

Year 5: Tape a Post-It note with ":q!" to your monitor. This is a significant improvement.

Year 6: Type i to enter insert mode. Use it like notepad. Type "esc :wq" to save and quit. Add these to the post-it note.

Year 11: Read the aforementioned post. Decide it's time to take the plunge. Learn 5 new key combos and finally, finally get the sweet sweet power of copy and paste back!
Insert Mode: i
Cut line dd
Paste buffer p (or P to paste above)
Cut 3 lines at the same time!! d3
Delete word dw
Quit without saving :q!
Save and Quit :wq

There it is. vi in 5 minutes. Plus 10 something years. Who says you can't teach old dogs new tricks.