Apps

VsVim brings the power of vim to Visual Studio

Learn how to put VsVim, an adaptation of vim that works with the Visual Studio IDE, into action.

I have fond memories of the dot com boom in the late 1990s -- creating "dynamic" websites with CGI and Perl, quickly typing and formatting with the vi editor on Unix, and later using the vi clone vim. I may be nostalgic, but I missed the power that these editors put at my fingertips (no reaching for the mouse). I was reintroduced to vim with my MacBook purchase a few years ago, with further research leading me to VsVim, an adaptation of vim that works with the Visual Studio IDE. Let's take a closer look at VsVim and how it can make you more productive.

Edit this

Developers are a loyal bunch who defend their favorite text editors as if they were family members. If you don't believe me, ask any hardcore developer what's their favorite text editor and be prepared for a speech. A quick scan of popular development editors includes gedit, GNU Emacs, UltraEdit, TextPad, Notepad++, TextMate for Mac users, and the venerable Notepad available on all flavors of Microsoft Windows. (I did not leave out your favorite editor on purpose; I just don't know every editor in existence, and I'm sure your favorite does what you need very well. Translation: please don't spam me.) I have used TextPad, TextMate, and in a pinch Notepad, but I have rediscovered vim and the marriage of it with Visual Studio in VsVim.

Learning curve

Vim and VsVim are acquired tastes, so do not expect to become a master overnight. There are a number of online resources for becoming more familiar with vim's capabilities; for instance, the vim wiki page has great information including this tutorial, and the vim FAQ is an excellent resource.

A good editor can save you time by eliminating keystrokes and mouse clicks, but this is a matter of opinion, as some developers prefer working with the mouse. For me, I like the ability to hit a few keys to perform common tasks.

Getting VsVim

VsVim is a Visual Studio extension, so I'll state the obvious by saying you need Visual Studio to use it. VsVim is available via the Visual Studio Gallery. Furthermore, if you are interested in contributing to its development or are curious about the code, it is a project on GitHub. The code/project is interesting; a great deal of it is written in F#, which I found surprising.

Follow the installation instructions via Visual Studio Gallery. The installation process recognized both versions of Visual Studio (2010 and 2012) on my machine, and it allowed me to choose one or both for the extension. Extensions are managed via the Tools menu (Tools | Extensions and Updates in Visual Studio 2012 and Tools | Extension Manager in Visual Studio 2010).

Figure A shows the installed extensions for Visual Studio 2012 Ultimate on my development machine. Notice it provides the Disable button if you ever want to turn off the extension -- it can also be disabled/enabled within Visual Studio with Ctrl+Shift+F12. Figure A

List of installed extensions in Visual Studio 2012. (Click the image to enlarge.)
With VsVim installed, you now have the option of using its key bindings to perform certain tasks. These bindings are configurable, as you may want to use the native Visual Studio functionality for certain keys as opposed to a vim alternative. The Options button shown in Figure B appears when VsVim is installed. The Options window in Figure C is presented when the Options button is selected. When VsVim was first installed on my machine, the message shown in Figure D appeared in the code window -- it basically told me there were key binding conflicts between Visual Studio and VsVim, and it wanted me to go to the Options window to resolve them. The Options window is restricted to the key bindings overlap between the VsVim extension and its Visual Studio host. Figure B

The Options button (lower right) allows you to configure VsVim key bindings. (Click the image to enlarge.)
Figure C

VsVim key bindings are configurable via the VsVim Options window. (Click the image to enlarge.)
Figure D

Key binding conflicts in Visual Studio 2012 when VsVim is installed. (Click the image to enlarge.)

VsVim in action

Once VsVim is installed, you can use its various keys to perform tasks within your code. One keystroke I use a lot is the forward slash (/) for searching. You simply type / followed by search text and hit return. If a match is found, the cursor moves the first instance.

Also, I like the navigation shortcuts like w to move forward a word, b to move backwards a word. With your right hand on the keys (in the normal asdf jkl; configuration), you can easily move around text with j for down, k for up, h is left, and l is right. (It would have made sense for l to be left, but it works out well in terms on finger placement.)

While this is only the tip of the iceberg in terms of VsVim usage, it does show you some basics like most text editors offer. You should take a closer look at the previously mentioned resources (wiki, FAQ, and tutorial) to dive deeper into VsVim's functionality.

To each their own

This post clearly conveys my fondness for vim and VsVim, but it also demonstrates the fact that the older (some say less user-friendly) approach to coding/editing can be combined with newer tools to create a powerful hybrid. With that said, you may not like vim but love Emacs, so take a look at its Visual Studio Extension. If there is no extension available for your favorite editor, you can change the default editor setting for Visual Studio (Tools | Options expand Text Editor in Visual Studio 2010 and 2012).

Keep your engineering skills up to date by signing up for TechRepublic's free Software Engineer newsletter, delivered each Tuesday.

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

0 comments

Editor's Picks