Vim Eye For The Visual Studio Guy

Sunday, 01 April 2012
  • By
  • Jeff Ammons
  • Tags:
  • Career
  • Programming
  • Tools
  • Vim

OK, first take a deep breath and repeat after me, “Jeff is not asking me to give up Visual Studio.”

Far from it. Visual Studio is without question the most productive environment for developing for Windows.

When everything is going well it functions like your little robotic code-monkey assistant. Memorizing a million API calls and settings is dumb. They will change. Your little robo-minion, however, has those APIs hardwired into his mechano-simian brain. Start typing and he will start suggesting possible matches.

So, relax, sip some nice, calming herbal tea and rest-assured that I'm not asking you to give anything up. Prying things from your cold, dead hands will not be required.

Having said that, [click] you have to admit [click, click] that Visual Studio [click] sure does make you [click] reach for the mouse WAY too often [click, click, clickety-click].

It also displaces memory the way the Titanic displaced water. It also occasionally behaves like the Titanic in a very crash and sink way.

Sometimes you need something light, fast and simple. In true “pick any two” fashion, you can try Vim. It is light and fast. It sure as heck isn't simple.

Vim In All Its Glory
Vim In All Its Glory - Click for full-size. Really. It's animated. ANIMATED. CLICK IT!

OK, I'll admit it, it's a tough sale.

On one hand you have the aforementioned all-singing, all-dancing robot-monkey vs. what appears at first glance to be a dead monkey.

Don't be fooled. THAT MONKEY IS NOT DEAD.

You don't see that in print very often. That makes me sad.

What's So Great About Vim?

Let's start with the obligatory Top-n List.

Top 5 Things I Like About Vim

  1. Runs anywhere
  2. Keep hands on the keyboard
  3. Macros become easy and wildly useful (not at first!)
  4. Lightweight
  5. Configurable
The first thing you hear about is the keyboard-centric nature of Vim. Vim, like it's predecessor Vi can be used without ever touching the mouse.

This was why I decided to take a deeper look at Vim. I find the frequency with which I have to reach for the mouse in Visual Studio distracting. Downright annoying.

You may already know that you can move around using home-row keys instead of those distant arrow keys, but what you don't know is that after a few days that won't be moving one character at a time as often as you will be leaping around.

The richness of text navigation options in Vim is a great strength.

You can jump to:

  • Start/End of word
  • Start/End of line
  • Start/End of document
  • Start/End of tag (opening or closing curly-brace for instance)
  • Start to specific text
  • Start to text specified by regular expression
  • More and More and More
Why does this matter?

Remember the mention of macros?

Once you get in the flow of navigating your code in this manner, then creating macros becomes trivial. Literally 2 keys and you are recording a macro. Two more and you play it back.

So What Now?

First things first, do this:
  1. Install Vim
  2. Open it
  3. Shut it down
  4. Curse
  5. Laugh at me for suggesting you look at this crap!
Now that you have that out of your system, get ready to watch some screen-casts. You cannot learn what is good about Vim by just playing around with it.

Start With Derek Wyatt's Screencasts

Derek Wyatt made a series of screencasts a few years back that are found on his blog.

Derek is very funny and full of energy and enthusiasm for Vim. Watch his Novice and Intermediate level videos to get an idea of why you might care about Vim.

Move On To VimCasts.Org

Drew Neil put together a great series of tutorials as well over at VimCasts.org. Drew's videos are typically short and sharply focused.

Who Is Hosting This

12/11/2016 Update! A new resource you might want to check out is Vi Introduction and Resources from Who Is Hosting This.

Decide If Vim Is For You

Once you've watched some videos from Derek and Drew, you should have a good idea whether you want to pursue delving into Vim.

You might not. That's OK.

Some of you might.

For me, it isn't an either/or question. I use Vim with Visual Studio.

Options For Integrating With Visual Studio

  1. Keep them separate. Use Vim occasionally as needed.
  2. Install Visual Studio plug-in:
    1. VsVim (free)
    2. ViEmu (not free)
  3. Make Vim an External Tool
If you remember my Titanic analogies back in the days when you were young and had just started reading this ridiculously long post, you'll probably agree that the last thing the Titanic needed was more cargo. Making that ship heavier would not have helped.

In much the same way, I try to avoid putting too many plug-ins into Visual Studio. Bare weight right now for me without a project loaded is around ~90 MB. Once I load a project, it will go way, way up.

For that reason, I have opted for the “Make Vim an External Tool” approach.

I have my F-1 key mapped to launch Vim (well GVim, actually) with the current document open at the current line I'm editing. I even have a Vim plug-in for working with Team Foundation Server.

For details on how to set this up (plus more), check out Integrate gvim with Visual Studio over at the Vim Wiki.

Summary

I can't say if you will like Vim. I'm guessing 90% of you will not.

I also can't say if a year from now I will be using Vim heavily.

I consider my current set up to be an experiment. For some things Visual Studio is perfect. For some things Vim is perfect. Neither is perfect for everything.

As long as I have to SSH into a server and edit files, I will use Vim or Vi to some extent. Now I will use it far more effectively.

##Update Here's a newer post on working with Vim: Stop Vim From Crapping In My Directories