Last Updated: February 25, 2016
·
341
· jtai

githublink.vim Plugin

I use Vim as my primary editor. I also use GitHub for a lot of my projects. On more than one occasion, I have found myself wanting to share the line under my Vim cursor with a collaborator in the form of a github.com link. The manual process went something like this:

  • Go to github.com in a browser
  • Navigate to the correct repository and branch
  • Drill down to the file I was working on
  • Find the line in the file and click on the line number
  • Copy the URL and paste it in the email or instant message

Wouldn’t it be nice if you could just hit a hotkey and have Vim figure out the URL for you? I thought so too, so I started hacking on Vim plugin to do exactly that.

To use the plugin, install it, then start editing a file that’s part of a GitHub-hosted repository. Press \ g (backslash, followed by g) to display the URL of the current line. The plugin also copies the URL to the clipboard for you if pbcopy is available.

Some of the constructs for the plugin are borrowed from rubytest.vim, so thanks to janx for the rubytest plugin. This is my first foray into Vim script, so if there are better ways of doing things, please share!

This tip was reposted from my blog, jontai.me