有没有一种方法可以在Firefox中单击链接并在现有的VIM会话中打开文件?

3

如果您使用Firefox浏览器,可以通过TextMate打开html页面中的链接,只要该链接具有以下格式:

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

但是是否可以使用VIM来做类似的事情呢?也许像这样:
<a href="vim://open?url=file:///home/.../index.html.haml">View</a>

理想情况下,这将使用现有的VIM会话。
祝好,
伯尼
3个回答

7

我找到了一种方法:

在Firefox中添加协议处理程序

打开Firefox并导航到about:config

添加以下键:

    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

创建脚本~/protocol_handler/prot.sh

将以下内容复制并粘贴到文件中:

#! /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

保存文件。

将文件模式更改为可执行:

$ chmod +x ~/protocol_handler/prot.sh

我不确定是否需要重新启动Firefox。
如果您确实想使用“vim://”协议,请将网络密钥的结尾从txmt更改为vim。由于已经有几个Rails插件(特别是rails-footer)使用了txmt,我只是使用了它来避免重新编码。
玩得开心! Berns

啊,比起从头开始像我链接中那样,这要好得多且更容易,现在正在尝试! - Wrikken

1
为了让 gedit 能够使用 tmxt:// 链接,我不得不使用 @Rystraum 的 相关答案 中的一个 bash 脚本,而不是 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

并将Firefox配置中的network.protocol-handler.app.txmt更改为指向该脚本:

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接