Vim Tips Wiki
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 = '! %:p ' . line(".")
  silent execute cmd

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

The original DDE code was taken at

Win32::GUITest is located at


I have the script, that uses Perl + Win32::Ole to open files in VC. You can even set breakpoints from Perl, this script has pointers to MSDN documentation.

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