Skip to content

Instantly share code, notes, and snippets.

@callahanrts
Last active November 25, 2021 09:14
Show Gist options
  • Save callahanrts/9274ad952b3e79cccc44 to your computer and use it in GitHub Desktop.
Save callahanrts/9274ad952b3e79cccc44 to your computer and use it in GitHub Desktop.
Vim command to open a browser tab at the selected line of any git project.
function! ShowOnGithub()
let u = system("echo ${${${$(git --git-dir=.git config --get remote.origin.url)#git@github.com:}%.git}#https://github.com/} | xargs echo -n")
silent exec "!open "."https://github.com/".u."/blob/master/".@%.'\#L'.line(".")
endfunction
command! -nargs=0 ShowOnGithub call ShowOnGithub()
nnoremap <Leader>gh :ShowOnGithub<CR>
@dstokes
Copy link

dstokes commented Feb 28, 2015

https://github.com/tpope/vim-fugitive does this pretty well via :Gbrowse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment