Now that we've got Vim setup to a point where it's quite useful for doing C# development, we need to start actually using it. As I've discussed in the past, there will still be lots of times when you'll want to use Visual Studio. Whether it be for the Designer, or for Exploring APIs you're unfamiliar with through Intellisense, or for manipulating resources, settings, project, or solution files, or for debugging.
VS -> Vim
The key is to be able to get back and forth between them easily. To get from Visual Studio to Vim is the easiest. Simply add an "external tool" which launches Vim and opens the current file. In VS go to Tools -> External Tools. Click Add and enter the following:
Title: Vim
Command: C:\Program Files\Vim\vim70\gvim.exe
Arguments: +$(CurLine) "$(ItemPath)"
Initial directory: $(SolutionDir)
Command: C:\Program Files\Vim\vim70\gvim.exe
Arguments: +$(CurLine) "$(ItemPath)"
Initial directory: $(SolutionDir)
There will now be a "Vim" item in your Tools menu which will open Vim to the current file AND the current line.
You can assign a shortcut key to this command as follows.
- Note exactly where the "Vim" command appears in the Tools menu (How many items from the top or bottom is it?)
- Go to Tools -> Customize -> Toolbars
- Click on the Tools menu so it opens and find where the Vim tool was, it will now say External Command X where X is some number. Remember X.
- Back on the Customize window, click "Keyboard..."
- Type "ExternalCommandX" into the "Show commands containing" box, where X is the number you just found
- Choose your shortcut key and assign it. I use Ctrl+Shift+V, Ctrl+Shift+V
Vim -> VS
To get from Vim to Visual Studio is pretty easy as well. Assuming that your current path (:cd) in Vim is the path containing the .sln file, you can simply type the following:
:! *.sln
When you hit the tab key Vim will automatically expand to the full name of the sln file. Hit enter and the solution will open in Visual Studio.
Thank you. It was very usefull for me.
ReplyDeleteHey, i would like to say this is a wonderful blog.
ReplyDeleteAll that you have said in this blog is true, in case you are working on a project from the scratch and may not be true when working on the huge project(some thing like legacy project).
This applies only for fresher or one with less experience. For experienced people it must not make a difference.
VIM is the best editor every developed.
These days we have tools like ViEmu to be grateful for :)
ReplyDeleteVery helpful blog!
ReplyDeleteI found it looking for TFS-Vim related info. Thanks for that.
New to TFS, happy Vimmer >10jrs.
Changing Title: "&Vim" will enable default windows shortcut usage for T,V
Consider $(ItemDir) option for initial dir.
And for arguments:
--servername VimualStudio --remote-silent +"call cursor($(CurLine),$(CurCol))" $(ItemFileName)$(ItemExt)