Vim Tips Wiki
(remove content that's on Integrate_gvim_with_Visual_Studio)
(adjust previous/next navigation + minor manual clean)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{review}}
 
{{Duplicate|683|716}}
 
 
{{TipImported
 
{{TipImported
 
|id=580
 
|id=580
 
|previous=579
 
|previous=579
 
|next=581
 
|next=581
|created=October 6, 2003
+
|created=2003
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Francois Leblanc
 
|author=Francois Leblanc
Line 13: Line 11:
 
|category2=Windows
 
|category2=Windows
 
}}
 
}}
 
This tip is probably only useful for '''old versions of Visual Studio'''. For integrating Vim with modern versions of Visual Studio, see [[Integrate gvim with Visual Studio]].
 
For integrating Vim with modern versions of Visual Studio, see [[Integrate gvim with Visual Studio]].
 
   
 
To open a file in an existing instance of some versions of Visual Studio, a DDE call must be initiated. It's an old and obsolete technology called Dynamic Data Exchange used for interprocess communication. When you click on a .cpp file in the Windows Explorer it calls devenv.exe with the /DDE switch (it's undocumented) and sends it an Open DDE command. You can see it for yourself if you look at the file type mapping of .cpp in the Windows Explorer (if you haven't already changed them to open Vim). The Explorer shell is DDE enabled but I found no way to send DDE from the command line (I didn't really look for it either). So I wrote a small C++ console app from the code I got from an Experts Exchange question. I formatted the code, renamed references from Visual Studio to DevEnv and put it in a project.
 
To open a file in an existing instance of some versions of Visual Studio, a DDE call must be initiated. It's an old and obsolete technology called Dynamic Data Exchange used for interprocess communication. When you click on a .cpp file in the Windows Explorer it calls devenv.exe with the /DDE switch (it's undocumented) and sends it an Open DDE command. You can see it for yourself if you look at the file type mapping of .cpp in the Windows Explorer (if you haven't already changed them to open Vim). The Explorer shell is DDE enabled but I found no way to send DDE from the command line (I didn't really look for it either). So I wrote a small C++ console app from the code I got from an Experts Exchange question. I formatted the code, renamed references from Visual Studio to DevEnv and put it in a project.
Line 21: Line 18:
   
 
It is integrated in Vim by a function (in vimrc) that gets the current file name and line number and silently executes the script:
 
It is integrated in Vim by a function (in vimrc) that gets the current file name and line number and silently executes the script:
 
 
<pre>
 
<pre>
 
function! DevEnvDDE()
 
function! DevEnvDDE()
Line 45: Line 41:
   
 
Note: it now defaults to Visual Studio .NET 2003 instead of Visual Studio .NET
 
Note: it now defaults to Visual Studio .NET 2003 instead of Visual Studio .NET
 
----
 
Just to let you know, to open a file with Visual Studio (At least the current versions) you simple can put the file name as an argument to the command line.
 
 
Example:
 
<pre>
 
"C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe" "BE-NotInDirectory\main.cpp" "CC-late\main.cpp" "DO\Lab 5.cpp" "MG\Lab5.cpp" "NathanK\main.cpp" "NH\func.h" "NH\func.cpp" "NH\main.cpp" "NM-late\main.cpp"
 
</pre>
 
 
Would open all of these files.
 
 
An alternative is (choose a keystroke of your desire)
 
<pre>
 
map <C-Tab> :silent exec '!start "c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /Edit ' . expand("%:p")<CR><CR>
 
</pre>
 
The /Edit flag says to open in an existing instance of Visual Studio, if there is one. This doesn't send the editor to the given line, though it is a simple and somewhat-functional solution.
 
----
 

Latest revision as of 05:24, 11 August 2011

Tip 580 Printable Monobook Previous Next

created 2003 · complexity intermediate · author Francois Leblanc · version 6.0


This tip is probably only useful for old versions of Visual Studio. For integrating Vim with modern versions of Visual Studio, see Integrate gvim with Visual Studio.

To open a file in an existing instance of some versions of Visual Studio, a DDE call must be initiated. It's an old and obsolete technology called Dynamic Data Exchange used for interprocess communication. When you click on a .cpp file in the Windows Explorer it calls devenv.exe with the /DDE switch (it's undocumented) and sends it an Open DDE command. You can see it for yourself if you look at the file type mapping of .cpp in the Windows Explorer (if you haven't already changed them to open Vim). The Explorer shell is DDE enabled but I found no way to send DDE from the command line (I didn't really look for it either). So I wrote a small C++ console app from the code I got from an Experts Exchange question. I formatted the code, renamed references from Visual Studio to DevEnv and put it in a project.

Setting the line number is a different problem. I wrote a Perl script using the Win32::GuiTest module. This module allows interacting with the Windows GUI and provides a very useful function called SendKeys. The script finds the Visual C++ window (if you are using a different language change the script) and sends it: a CTRL-G, the current line number as specified on the command line and ENTER.

It is integrated in Vim by a function (in vimrc) that gets the current file name and line number and silently executes the script:

function! DevEnvDDE()
  let cmd = '!devenvdden.pl %:p ' . line(".")
  silent execute cmd
endfunction

All that is left is to map the function to a key.

You can get the source files for the Perl script and DDE project at http://dunderxiii.tripod.com/vimtips/devenvdde.zip

The original DDE code was taken at http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20489782.html

Win32::GUITest is located at http://sourceforge.net/projects/winguitest/

Comments[]

I have the script send-to-msdev.sh, that uses Perl + Win32::Ole to open files in VC. You can even set breakpoints from Perl, this script has pointers to MSDN documentation. http://www.cs.albany.edu/~mosh/Perl/send-to-msdev.ksh


I updated the DevEnvDDE program to connect to Visual Studio .NET 2003. The code now supports an extra command line parameter that specifies the visual studio instance to open the file in (VS6, VSNET or VSNET2003). Simply download the new sources (same link).

Note: it now defaults to Visual Studio .NET 2003 instead of Visual Studio .NET