Skip to content

Instantly share code, notes, and snippets.

@awinograd
Last active January 30, 2018 22:54
Show Gist options
  • Save awinograd/4699980 to your computer and use it in GitHub Desktop.
Save awinograd/4699980 to your computer and use it in GitHub Desktop.
cvim file for opening links from better_error and RailsPanel in vim on ubuntu.
#! /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}`
# /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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment