Vim / Opera tip: Open highlighted text in Vim

December 22, 2009 – 6:50 pm Tags: ,

Here’s a quick tip for Opera and Vim users: How to add a menu item which allows you to quickly open highlighted text on a web page in Vim.

This trick can be applied with any other application too, like <insert your favorite editor>

Step 1: Create copy of the standard menu configuration

First, you need to create a copy of the standard menu configuration so you can go back if something goes wrong.

This can be achieved by going to preferences (Ctrl+F12), Advanced, Toolbars. Now choose “Opera Standard” from under “Menu Setup”, hit Duplicate and then click on the newly duplicated setup. Hit OK and you’re done with this step

Step 2: Edit menu configuration

Now, you need to find the menu configuration file. It’s located in the directory where Opera stores your profile - typically in Documents and Settings, but the easiest way to find it is by going to opera:about.

The path to your profile is displayed under “Paths”, as shown below:

In my case the profile directory is the one highlighted in the image. Find yours, and you should see a directory called Menu under it.

In the menu dir, you should have a file called standard_menu (1).ini. Open it and find the line which says Hotclick Popup Menu

Under it, you should see lines such as “Item, M_COPY_TO_NOTE=Copy to note”

To add a new Copy to Vim item, insert the following line:

Item, Copy to Vim = Go to page, “data:text/open-in-vim,%t”

Here we are essentially adding a new command to go to a specific URL. In this case, it’s a Data URI, using mime-type text/open-in-vim, which is something we made up, and then including the text highlighted with the identifier %t

Step 3: Add new mime-type handler

Now that we have modified the menu configuration, the last thing we need to do is add a handler for our own text/open-in-vim mime-type.

Go back to Opera’s preferences, but this time choose Advanced, Downloads.

Click on Add… and fill in the dialog:

Mime-Type: text/open-in-vim
Extension: openinvim (this can be anything you want actually)
Action: Open in Other Application, fill in path to vim’s executable.

Done!

If you didn’t restart Opera yet, do that now. You should now get a new Copy to Vim menu option whenever you highlight text and right click.

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • description
  • E-mail this story to a friend!
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • Technorati

RSS feed Subscribe to my RSS feed

  1. 2 Responses to “Vim / Opera tip: Open highlighted text in Vim”

  2. That’s neat.

    Do you happen to know how to enable passing right-clicked urls into external programs? Like if you want to open videos or audio files in different programs (so you don’t always have to rely on the associated program). Only way I manage to do it is adding following under [Link Popup Menu] but then it shows the item in every link:

    Item, “Open in VLC”=”Execute program, “vlc”, “%l”

    PS. For quickly opening images in TinEye I have made the following under [Image Link Popup Menu]:

    Item, “Open in TinEye”=”Copy image address,,,,”UTI” & Go to page, “http://tineye.com/search?pluginver=bookmark_1.0&url=%c”"

    Downsize is that it copies the address in the clipboard.

    By Joonas on Jan 1, 2010

  3. I don’t know if it’s possible to do that for only specific types of links. I think it’s always the same for all kinds of links.

    By Jani Hartikainen on Jan 1, 2010

Post a Comment