public
Last active

cvim file for opening links from better_error and RailsPanel in vim on ubuntu.

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#! /usr/bin/env ruby
 
# Modified from : http://www.tkalin.com/blog_posts/using-console-vim-as-vim-protocol-handler-in-ubuntu
# NOTE: This opens with a link to the mvim protocol for compatibility with RailsPanel
# goes to /usr/local/bin/cvim
 
require 'uri'
require 'cgi'
 
full_path = ARGV[0]
 
# for better_error which encodes the /'s
full_path = full_path.gsub("%2F", "/")
 
if full_path
full_path = full_path.sub("mvim:\/\/open?url=","")
 
uri = URI::parse(full_path)
 
path = uri.path
 
if path.index('&') > 0
path = path.split('&')[0]
params = CGI::parse(uri.path)
line = params["line"][0]
else
path = path
end
vim_params = %Q["#{path}"]
vim_params << " +#{line}" if line
end
 
`gnome-terminal -x vim #{vim_params}`
gistfile2.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# /usr/share/applications/cvim.desktop
 
[Desktop Entry]
Encoding=UTF-8
Name=Vim (Console)
Comment=Edit text files in a console using Vim
Exec=/usr/local/bin/cvim %U
Terminal=false
Type=Application
Icon=/usr/src/vim/runtime/vim48x48.xpm
Categories=Application;Utility;TextEditor;
MimeType=text/plain;x-scheme-handler/mvim;
StartupNotify=true
StartupWMClass=CVIM

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.