Skip to content

Instantly share code, notes, and snippets.

@jmarceli
Forked from awinograd/gist:4699980
Last active August 29, 2015 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jmarceli/818f44f98557a46049e7 to your computer and use it in GitHub Desktop.
#! /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