views:

73

answers:

2

Hi there,

I know it's possible to open links in an html page (let's say, if you're using Firefox) with TextMate if the link has this format:

<a href="txmt://open?url=file:///home/.../index.html.haml">View</a>

But is it possible to do a similar thing with VIM? Perhaps like so:

<a href="vim://open?url=file:///home/.../index.html.haml">View</a>

Ideally this would use an existing VIM session.

Cheers,

Bernie

+1  A: 

http://www.mozilla.org/projects/netlib/new-handler.html

Wrikken
Thanks Wrikken, this got me on the right track.
btelles
+3  A: 

Found a way to do it:

Add a Protocol handler to Firefox

Open firefox and navigate to about:config

Add the following keys

    network.protocol-handler.warn-external.txmt   boolean   false

    network.protocol-handler.external.txmt        boolean   true

    #the last one is the path to the script we're about to create
    network.protocol-handler.app.txmt             string    ~/protocol_handler/prot.sh

    # I ended up needing this one as well on another machine, (no idea why)
    network.protocol-handler.expose.txmt          boolean   false

Create the script ~/protocol_handler/prot.sh

Copy and paste the following into the file:

#! /usr/bin/env ruby


file_result = ARGV[0].scan(/file\:\/\/((\w|\/|\.)*).*/)
file_path = file_result[0][0]


line_result = ARGV[0].scan(/\&amp\;line\=(\d*).*/)

if line_result
  line = line_result[0][0]
  system "gvim --remote-silent +#{line} #{file_path}"
else
  system "gvim --remote-silent #{file_path}"
end

Save the file.

Change the file mode to be executable:

$ chmod +x ~/protocol_handler/prot.sh

I'm not sure if you have to restart Firefox or not.

If you actually want to use the "vim://" protocol just change the ending on the network keys from txmt to vim. Since several Rails plugins (rails-footer, namely) out there already use txmt, I just used that to avoid recoding.

Have fun! Berns

btelles
Wrikken