(→Original tip: add more arguments (current column)) |
|||
Line 52: | Line 52: | ||
*''Title:'' &Vim |
*''Title:'' &Vim |
||
*''Command:'' C:\Vim\vim62\gvim.exe |
*''Command:'' C:\Vim\vim62\gvim.exe |
||
− | *''Arguments:'' +$(CurLine) |
+ | *''Arguments:'' --servername VimualStudio --remote-silent +"call cursor($(CurLine),$(CurCol))" $(ItemFileName)$(ItemExt) |
− | *''Initial directory:'' $( |
+ | *''Initial directory:'' $(ItemDir) |
− | This will allow you to use the key combination Alt-t-v to open the current file at the current line in a new vim browser. The browser will start at the directory of that file, so ':e .' will edit the directory of that file. |
+ | This will allow you to use the key combination Alt-t-v to open the current file at the current line and cursor in a new vim browser. The browser will start at the directory of that file, so ':e .' will edit the directory of that file. |
+ | |||
+ | Remove the <code>--servername VimualStudio</code> part if you want to have each Alt-t-v to open a new instance of Vim. |
||
'''THE SECOND KEY:''' In order to effectively use the two together and make sure .NET does not complain about its files changing, goto Tools > Options > Environment > Documents and ensure these two options are checked: |
'''THE SECOND KEY:''' In order to effectively use the two together and make sure .NET does not complain about its files changing, goto Tools > Options > Environment > Documents and ensure these two options are checked: |
Revision as of 21:47, 16 March 2009
Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
created 2004 · complexity intermediate · author Jon Heiner · version 6.0
On Windows systems, you may be able to integrate Vim with Microsoft Visual Studio.
VisVim for Visual Studio 5.0 and 6.0
- The OLE version of gvim can be used as the editor in Visual Studio 5.0 and 6.0. This is called VisVim. :help VisVim
- The source code for Vim includes directory src/VisVim which allows building file VisVim.dll.
- File src/VisVim/README_VisVim.txt is the documentation.
- With VisVim, you can use Visual Studio for designing and building, and use Vim commands within Visual Studio for editing.
- VisVim does not work with Visual Studio 2002 and later (Visual Studio .NET). However the Visual Studio versions after VS6 support use of an external editor.
Integration of Vim with Visual Studio 2003 and later
Script visual_studio.vim includes features:
- Compatible with Visual Studio 2003, 2005 and 2008.
- Control Visual Studio from within Vim.
- Load the current Visual Studio file into Vim.
- Load the current Vim file into Visual Studio.
- Compile the current file (C/C++) within Vim.
- Build the current project (C/C++/C#) within Vim.
- Load results from Visual Studio into the Vim quickfix file.
ViEmu for Visual Studio is commercial software that emulates Vim editing commands within Visual Studio (Vim is not used).
See also
Todo Merge some of following:
- 345 Quickfix and Visual Studio and cygwin keep this separate as the "with cygwin" tip
- 368 Use gvim in VS.Net
- 580 Switching between Vim and Visual Studio ability to move back and forth between Vim and VS
- 683 Integrate gvim with Visual Studio (see "Original tip" below)
- 716 Calling gvim from MS Visual Studio
- 719 Use Python to build project in Visual Studio
- 946 VisVim for Visual Studio
Original tip
Disclaimer: This is NOT a tip on how to get Vim to run inside of MS Visual Studio .NET. I have not yet found anyone who can make that work, so this is the next best thing. VisVim.dll seems to only work with VS6.
If you are someone who prefers Vim and uses MS Visual Studio .NET for development, and you have been struggling with a less than perfect integration of the two, this tip may help you tighten that up. I've been working with the two together since .NET came out and this tip is a compilation of all the tricks and setup I use.
THE KEY: Before you do anything else, do this. goto Tools > External Tools > Add:
- Title: &Vim
- Command: C:\Vim\vim62\gvim.exe
- Arguments: --servername VimualStudio --remote-silent +"call cursor($(CurLine),$(CurCol))" $(ItemFileName)$(ItemExt)
- Initial directory: $(ItemDir)
This will allow you to use the key combination Alt-t-v to open the current file at the current line and cursor in a new vim browser. The browser will start at the directory of that file, so ':e .' will edit the directory of that file.
Remove the --servername VimualStudio
part if you want to have each Alt-t-v to open a new instance of Vim.
THE SECOND KEY: In order to effectively use the two together and make sure .NET does not complain about its files changing, goto Tools > Options > Environment > Documents and ensure these two options are checked:
- Detect when file is changed outside the environment.
- Auto-load changes (if not currently modified inside the environment).
CTAGS: This is an obligatory statement, but a lot of MS developers do not know about ctags. Google for it and use it. This enables you to jump to tags, preview function declarations, use tab completion, and ton of things you can't live without. My personal mappings are:
map <C-[> <C-T> " use C-] to goto a tag and C-[ to come back up the tag stack noremap <C-P> <C-W>} " use C-P to preview a tag in a small window
For tag completion, there are a TON of options, but I use VimTip102 because it's simple and does the job:
inoremap <Tab> <C-R>=InsertTabWrapper("forward")<CR> inoremap <s-tab> <C-R>=InsertTabWrapper("backward")<CR>
One snag for ctags on MS is that the tag pathnames require the old dos style pathnames. Use the appropriate DIR switches to figure yours out:
set tags=./tags,tags,c:/projects/tags,c:/PROGRA~1/MIEEF7~1/tags
If you must use make at the command line ( I don't compile at command line for .NET but i've gotten it working. not sure where this tip was ), use:
set autowrite setlocal errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m setlocal makeprg=devenv\ c:/Projects/MySolution.sln\ -build\ release
Lastly, if you are afraid to leave the IDE because you like Visual Assist's file browser, I'm maintaining a script to emulate that behavior [ProjectBrowse.vim]. It requires the unix find command which can be easily obtained via the cygwin win-unix set of utils.
map <A-o> :ProjectBrowse c:\Projects\<CR>
Comments
Using the following command abbreviation, I can tell VS to open the file I'm currently editing.
:cabbrev vsedit :!"c:\Program Files\Microsoft Visual Studio 8\Common7\ide\devenv.exe" /edit "%"
Though the file will not be opened at the exact location.