You are here

Modify Dreamweaver to Open files in Vim

I use Dreamweaver to edit files on a variety of webservers. It's a pretty handy tool, that has definitely improved over time. The code editor is good, but not great.

One thing that's always bugged me, is that DW won't just open a file as text if it doesn't recognize the extension. So for instance, I wanted to look at drupal's module code today (a .module) file and DW wouldn't open it, even though it was php.

At the same time, i've been working more and more on unix/linux boxes, and i forced myself to sit down and learn vim. After a bit of a steep learning curve, I'm continually impressed by its power.

So, here's my initial attempt at uniting the two. In DW, when you open a file in the 'local site' dialog, you normally have 'Dreamweaver' and 'browse...' Unlike windows, where when you browse once, your app then shows up in there for that file type.. DW never learns.

I taught it.

NOTE: Most of this editing shouldn't be done with DW open. Might i suggest using vim to edit your files? Be sure to restart DW if you make a change and want to test the results.

First, you need to dig up the xml file that controls that menu. That can be found at this ugly location in your user directory:

C:\Documents and Settings\Aaron\Application Data\Macromedia\Dreamweaver 8\Configuration\Menus\Cache\Menus\

In there, you can find a file called: DWContext_LocalSite_OpenWith.xml
which contains the following XML Code:

<menus xmlns:MMString="">
<menuitem name="_Dreamweaver" file="Menus/MM/Dreamweaver_Editor.htm" id="DWContext_LocalSite_OpenDW" />
<menuitem dynamic="true" name="No Editors Found" 
	enabled="true" file="Menus/MM/Editors_Dynamic.htm" id="DWContext_LocalSite_OpenWith_NoEditors" />

Check out line 2. Using the dreamweaver entry as a template, we make our own for vim.

<menuitem name="_Vim" file="Menus/AB/VI_Editor.htm" id="DWContext_LocalSite_OpenVim" />

most of that should be self explanatory, the path is relative to the dw menus directory in C:\Program Files\Macromedia\Dreamweaver 8\Configuration\ That path will be defined by how you place the next 2 files That come next.

go to:

C:\Program Files\Macromedia\Dreamweaver 8\Configuration\Menus\MM

find the 2 files named:

copy both of those to their own folder, just so they are kept separate. I used AB as that is my alternative to MM.

so, mine are in:

C:\Program Files\Macromedia\Dreamweaver 8\Configuration\Menus\AB

I renamed mine to VI_Editor.htm and VI_Editor.js.

Open both of those up in vim.

Point VI_Editor.htm's script tag to the VI_Editor.js file like so.

<SCRIPT SRC="VI_Editor.js"></SCRIPT>

VI_Editor.js is where the fun happens:

// Copyright 2000, 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved.

function receiveArguments()
	var fileList = site.getSelection();
	for (i=0; i < fileList.length; i++)
		var fileName = fileList[i];
		//ab's new code, if we don't like somethin DW does.. we change it!
	return true;

function canAcceptCommand()
	var fileList = site.getSelection();
	for (i=0; i < fileList.length; i++)
		var fileName = fileList[i];
		// skip files we know we can't open (images,folders,etc...)
		if ( fileName.match( /[.]jpg$/i ) || 
			fileName.match( /[.]jpeg$/i ) || 
			fileName.match( /[.]gif$/i ) || 
			fileName.match( /[.]png$/i ) )
		return true;
	return false; // havn't found anything we can open...

basically, we edit the existing line that tells the app to open in DW, so it points to vim so:


gets changed to:


You can also hack some code out of the "canAcceptCommand()" function, so that DW is more liberal about what can be sent to Vim and what can't. I leave that to you to explore.

save all that stuff, check your paths one last time, and load DW!

That should be all there is to it. Sorry if my documentation skills are lacking or unclear, it should get you started though.

Dig around in those files. Seems like DW has provided us with unlimited potential for hackability.
Reference docs for DW's javascript DOM can be had here