2011-03-31

Running Vim from Eclipse IDE

I needed to jump from Eclipse to Vim sometimes.

Although there are lots of ways to do this, my way is simple, I will just add a menu item to Eclipse to open the current file/resource in Vim, save it in Vim, and see the effect in Eclipse.

You can find some links to alternative methods and programs at the end of this blog according to your needs. By using these more powerful solutions, you will be able to emulate Vim in Eclipse, or you will have the Vi keys in Eclipse or even you can contain the Vim itself in Eclipse.

By the time, my Eclipse version is Helios Service Release 1 and I'm using the gVimPortable from PortableApps.

Now it is time to launch Eclipse. Eclipse has an external tools feature which we will be using. First, click Run and then External Tools and External Tools Configurations... as in the following figure.



This will open a dialog titled External Tools Configurations. Since we will be adding a new program configuration, choose Program and then click on the icon of New launch configuration at the top left as in the following figure.



Now, give a descriptive Name for the task. Here, I will use the name "Open with Vim". Also we need to indicate the Location which is the path to the executable. In my system, it was "C:\PortableApps\PortableApps\gVimPortable\gVimPortable.exe", but it can be different on your system. Set the Working Directory to "${container_loc}" and Arguments to "${resource_loc}". You can also have the same effect of changing working directory by using "set autochdir" in your vimrc. Sadly, I could not find a way to send the line number of the cursor from Eclipse. If I could, Vim could directly jump to that line like in my blog entry Running Vim from Lazarus IDE. The tab Main should look like as follows:



By the way, clicking on Variables will give you more options as follows. Keep in mind that you can use all of these options.



Now, jump to the tab Refresh and activate the option Refresh resources upon completion.. This way, you can also open other files of the project in Vim and Eclipse will refresh them. I also recommend to keep the option Recursively include sub-folders activated like this:



Now, apply and close the External Tools Configurations dialog. Open a file from your workspace, and click Run and Open with Vim (or whatever you have named it) to open your file in Vim as in the following figures:





This is a very very simple way to connect Eclipse and Vim. There are more approaches here:

Eclim

The primary goal of eclim is to bring Eclipse functionality to the Vim editor. The initial goal was to provide Eclipse’s java functionality in vim, but support for various other languages (c/c++, php, python, ruby, css, html, xml, etc.) have been added and several more are planned. That is where eclim comes into play. Instead of trying to write an IDE in Vim or a Vim editor in Eclipse, eclim provides an Eclipse plug-in that exposes Eclipse features through a server interface, and a set of Vim plug-ins that communicate with Eclipse over that interface.


Vimplugin

Vimplugin is an attempt to use the vim editor inside the eclipse IDE. This is handy especially for longtime vim users. But other users (say occasional vim users) can also profit: macros, regexes, syntax-highlighting for 1001 languages etcpp.


Vrapper - Vim-like editing in Eclipse

Vrapper is an eclipse plugin which acts as a wrapper for eclipse text editors to provide a Vim-like input scheme for moving around and editing text. Unlike other plugins which embed Vim in Eclipse, Vrapper imitates the behaviour of Vim while still using whatever editor you have opened in the workbench. The goal is to have the comfort and ease which comes with the different modes, complex commands and count/operator/motion combinations which are the key features behind editing with Vim, while preserving the powerful features of the different Eclipse text editors, like code generation and refactoring.

No comments:

Post a Comment