Open Line on GitHub

Felix Geisendörfer recently wrote Vim Trick: Open current line on GitHub. The idea is to open a repository with GitHub in a browser for the current file and line number in Vim.

GitHub allows you to link directly to line numbers using fragment identifiers. For example, if I wanted to link to line 7 of index.jade which is used to generate this blog, I can share index.jade#L7.

Felix's tip uses a Git alias and xargs and open, along with nnoremap, to figure out the URL of the current file and open it. He also notes that fugitive.vim includes :Gbrowse for doing the same thing.

Fugitive's approach uses more Vim script to figure out the URL. Take a look at github_url() to see how that works. It seems complicated, but it's more generic and portable.

blog comments powered by Disqus