代码之家  ›  专栏  ›  技术社区  ›  btelles

有没有方法可以点击火狐中的链接并在现有的VIM会话中打开一个文件?

  •  3
  • btelles  · 技术社区  · 15 年前

    我知道,如果链接的格式为:

    <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 回复  |  直到 11 年前
        1
  •  7
  •   btelles    15 年前

    找到了一种方法:

    向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
    

    我不确定你是否需要重启火狐。

    如果您真的想使用“vim://”协议,只需将网络密钥的结尾从txmt更改为vim即可。因为有几个Rails插件(Rails页脚,即)已经使用了txmt,所以我只是使用它来避免重新编码。

    玩得高兴! 伯恩斯

        3
  •  0
  •   Community CDub    8 年前

    得到 tmxt:// 与gedit合作的链接,我不得不使用@rystraum的bash脚本 related answer 不是红宝石, ~/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