Skip to content

Instantly share code, notes, and snippets.

@piouPiouM
Created December 10, 2017 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piouPiouM/04135dcc35279ffc644af8f3c7b75a7b to your computer and use it in GitHub Desktop.
Save piouPiouM/04135dcc35279ffc644af8f3c7b75a7b to your computer and use it in GitHub Desktop.
" vim-plug
" Press `gx` to open the GitHub URL for a plugin or a commit with the default browser.
" From https://github.com/junegunn/vim-plug/wiki/extra#gx-to-open-github-urls-on-browser
function! s:plug_gx()
let line = getline('.')
let sha = matchstr(line, '^ \X*\zs\x\{7,9}\ze ')
let name = empty(sha) ? matchstr(line, '^[-x+] \zs[^:]\+\ze:')
\ : getline(search('^- .*:$', 'bn'))[2:-2]
let uri = get(get(g:plugs, name, {}), 'uri', '')
if uri !~ 'github.com'
return
endif
let repo = matchstr(uri, '[^:/]*/'.name)
let url = empty(sha) ? 'https://github.com/'.repo
\ : printf('https://github.com/%s/commit/%s', repo, sha)
call netrw#BrowseX(url, 0)
endfunction
augroup PlugGx
autocmd!
autocmd FileType vim-plug nnoremap <buffer> <silent> gx :call <sid>plug_gx()<cr>
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment