How do you open an external Vim editor containing the active Eclipse editor file
I'm not looking for an "Vim Plugin" for Eclipse. Instead, I'd just want a keyboard-shortcut to open the curr开发者_如何学运维ent Eclipse file within a new Vim instance.
Is there a quick and easy way to do that?
There's two ways to do this, the canonical way, and the hack. First:
The Canonical Way
- Window > Preferences... Fold out General > Editors > File Associations.
- Choose the file type you want to edit
- Click the "Add" button beside the "Associated editors" box.
- 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.
- Run > External Tools > External Tools Configuration...
- Select "Program" on the left and click the "New" icon.
- Enter "Send to vim" for the Name
- Enter "/usr/bin/gvim" (or whatever your path is) for the Location
- Under "Working Directory" enter
${project_loc}
(this is a variable representing your project's top directory) - Under arguments enter
${resource_loc}
(this represents your current resource's path) - On the "Build" tab, un-check "Build before Launch" (unless you really want that)
- 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
You can also create a small shell script that simply opens whatever options are passed to it in named vim instance. For example, the shell script I use is simply:
#!/bin/bash
gvim --servername eclipse --remote-tab-silent "$@"
Then make the script executable and follow the canonical method described by sleepynate, using your script as the external editor.
I'm aware there is a highly upvoted answer but I should say that what I found most convienent on OSX was to use QuickCursor to let me open any text in macVim.
精彩评论