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.
You still have to copy and paste the URL, but everything else is done for you. Update: the plugin now 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!