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

I know that you can open links on an html page (say if you use 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 something similar with VIM? Perhaps so:

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

Ideally, this will use an existing VIM session.

Greetings

Burnie

+3
source share
3 answers

Found a way to do this:

Add protocol handler in Firefox

Open firefox and go 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 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.

Modify the executable file:

$ chmod +x ~/protocol_handler/prot.sh

, Firefox .

"vim://", txmt vim. Rails (rails-footer, ) txmt, , .

! Berns

+7

tmxt:// , gedit, bash script @Rystraum 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, script:

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

Source: https://habr.com/ru/post/1748678/


All Articles