Created
December 10, 2017 17:13
-
-
Save piouPiouM/04135dcc35279ffc644af8f3c7b75a7b to your computer and use it in GitHub Desktop.
`gx` to open GitHub URLs on browser. https://github.com/junegunn/vim-plug/wiki/extra#gx-to-open-github-urls-on-browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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