开发者

Is there a way to click a link in Firefox and open a file in an existing VIM session?

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


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


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


To get tmxt:// links working with gedit, I had to use a bash script from @Rystraum's related answer instead of the Ruby, ~/bin/txmt_proto.bash:

#!/bin/bash
FILE=$1
FILE=$(echo $FILE | grep -o "file:/\/.\+" | cut -c 8- | sed -e 's/%2F/\//g')
LINE=$(echo $FILE | grep -o "\&line=[0-9]\+")
LINE=$(echo $LINE | grep -o "[0-9]\+")
FILE=$(echo $FILE | grep -o "\(.\+\)\&")
FILE=$(echo $FILE | cut -d'&' -f1)
gedit +$LINE $FILE

and change the Firefox config network.protocol-handler.app.txmt to point at the script:

network.protocol-handler.app.txmt             string    ~/bin/txmt_proto.bash
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜