Open Source.NET

Write Faster Code by Adding VIM to Visual Studio

VIM is a text editor with a Visual Studio extension. Its time-saving power is well worth the learning curve.

One of the greatest productivity gains you can make is to type less and navigate through your code faster. VsVim, written by JaredParsons, is an extension for Visual Studio 2010 and later which will get you doing just that. To get VsVim, you can download it from the Visual Studio Gallery or via the extension manager in Visual Studio. Mastering VsVim takes an investment of time, but learning it will pay dividends.

As the name suggests, VsVim is based on the functionality of the VIM text editor. VIM isn't something picked up as easily as Notepad; it's a powerful tool with a high initial learning curve. This makes it no different than many tools we use every day.

Multiple Modes
VIM has multiple modes:

  • The Insert mode is most like what Visual Studio users are used to: typing enters text and the modifier keys can be used to execute commands
  • Normal mode is the main operating mode, and is used for navigation and text manipulation
  • Visual mode is used for navigating and manipulating selections of text

I recommend going through the built-in tutorial to become familiar with the basic modes and commands. To open the tutorial, go to Start Menu/All Programs/Vim 7.3/Vim tutor.

VsVim brings the tremendous power of VIM to Visual Studio. Once you get past the initial learning curve and start using the basic features, you'll be editing code faster than ever before.

VIM uses commands that build on one another. Commands combine actions and movements. For example, 'd' is for delete and 'e' means move to the end of the word. If you type 'de' it will delete from your cursor to the end of the word. You can use 'w' as well, which takes you to the beginning of the next word (thus, 'dw' will delete from your current location to the beginning of the next word, including whitespace separating words). The curly braces '{' and '}' take you to the beginning of the previous and next paragraph (or block of code).

You can also use numbers combined with movement. The 'hjkl' keys are used for movements: left, down, up, and right. If you want to move down 15 lines, type '15j'. To move three methods down, type '3}'.

Simpler Searching
Everything flows from these conventions. VsVim also includes part of VIM search capabilities. When in normal mode, type '/' followed by what you're looking for and press Enter.

A simple example of relocating a method:

  • Start with your cursor at or before the current method
  • Press 'v' to enter visual mode (used for selected ranges of text)
  • Press '}' to move past this block of text (end of the method)
  • Press 'd' to delete (cut)
  • Press '{' twice to move up two methods
  • Press 'p' to paste the method

To start learning VsVim (and VIM), don't start with empty documents. Print off a cheat sheet with commands and read a couple of articles on VIM. Then start programming with VIM. If you don't know how to do something, look it up, execute the command, and try to use it again.

The motto for learning VIM could be "Repetitio est mater studiorum (repetition is the mother of study)". You'll build muscle memory and subconsciously start navigating your code without having to think about the commands. Once you get 20 to 30 commands into your workflow, you'll be well on your way to being a much more effective typist (and faster programmer).

In addition to all this, you still get IntelliSense, tab completion, snippets and all other base Visual Studio features when in insert mode. There's built in support for key binding collisions, enabling you to choose if VsVim or Visual Studio itself will handle the shortcuts; just click the options button in the bottom right of your code file. If you need to exit VsVim, you can temporarily disable (and restore) it by pressing Ctrl+Shift+F12.

I've barely scratched the surface of VsVim and VIM's capabilities. To expand your knowledge, I've provided some resources below. Take a look at videos online of people using VIM, and experiment for yourself. Think, before you reach for your mouse: Can you do it much faster from your keyboard?

VIM Resources

About the Author

Ian Davis is the Master Code Ninja for software architecture and development consulting firm IntelliTechture. A C# MVP, Davis is an expert on the .NET Tramework and co-organizer of the Spokane .NET User Group who frequently speaks at industry events. He spends most of his free time as an open source author and advocate, publishing and working on many open source projects.

comments powered by Disqus


  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube