Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you open an external Vim editor containing the active Eclipse editor file

Tags:

vim

eclipse

I'm not looking for an "Vim Plugin" for Eclipse. Instead, I'd just want a keyboard-shortcut to open the current Eclipse file within a new Vim instance.

Is there a quick and easy way to do that?

like image 843
cmcginty Avatar asked Nov 03 '10 04:11

cmcginty


People also ask

How do I open a .INC file in eclipse?

If you right-click the file in the Package Explorer/Navigator, you will see an Open-With menu item where you can select how the file should be opened.

How do I open an Eclipse editor?

Just select Window→ Preferences→ Workbench→ File Associations, select the file type, and associate an editor or program with it (if nothing else, you can use Eclipse's default text editor). You also can run programs outside Eclipse as external tools, invoked by selecting Run→ External Tools.


1 Answers

There's two ways to do this, the canonical way, and the hack. First:

The Canonical Way

  1. Window > Preferences... Fold out General > Editors > File Associations.
  2. Choose the file type you want to edit
  3. Click the "Add" button beside the "Associated editors" box.
  4. Click "External programs" and "Browse...", then find gvim, or enter /usr/bin/gvim, or generally make it go to gvim.

Now, files of that type should show up in an external vim instance. Awesome, right? But that doesn't solve your problem of pushing the current buffer out to vim.


The Hack

Instead, we're going to set vim as a "build tool", and have eclipse send it the current file as arguments. This may have some unaffected side-effects, based on your project settings, but look into them carefully if you experience things like unexpected re-building of your files.

  1. Run > External Tools > External Tools Configuration...
  2. Select "Program" on the left and click the "New" icon.
  3. Enter "Send to vim" for the Name
  4. Enter "/usr/bin/gvim" (or whatever your path is) for the Location
  5. Under "Working Directory" enter ${project_loc} (this is a variable representing your project's top directory)
  6. Under arguments enter ${resource_loc} (this represents your current resource's path)
  7. On the "Build" tab, un-check "Build before Launch" (unless you really want that)
  8. On the Common tab, check "External Tools" under the "Display in favorites menu"

You should be all set! Now you can send your file to vim by using the menu

Run > External Tools > Send to vim 

If you want to get fancy, you can even add a button to your toolbar.

Be advised, I've used gvim in the examples. If you'd like to use terminal vim, you'll have to call it appropriately based on the terminal you're using. For xterm, this would be /usr/bin/xterm -e /usr/bin/vim, instead of /usr/bin/gvim

like image 56
sleepynate Avatar answered Sep 28 '22 01:09

sleepynate