-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
extra
Junegunn Choi edited this page Feb 29, 2016
·
22 revisions
autocmd VimEnter *
\| if !empty(filter(copy(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall | q
\| endif
Press gx
to open the GitHub URL for a plugin or a commit with the default browser.
function! s:plug_gx()
let line = getline('.')
let sha = matchstr(line, '^ \zs[0-9a-f]\{7}\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
(suggested by @sodapopcan)
-
J
/K
to scroll the preview window -
CTRL-N
/CTRL-P
to move between the commits -
CTRL-J
/CTRL-K
to move between the commits and synchronize the preview window -
CTRL-G
to browse the diff using gv.vim
function! s:scroll_preview(down)
silent! wincmd P
if &previewwindow
execute 'normal!' a:down ? "\<c-e>" : "\<c-y>"
wincmd p
endif
endfunction
" Browsing diff in gv.vim (https://github.com/junegunn/gv.vim)
function! s:diff_in_gv()
let plug = matchstr(get(filter(getline(1, '.'), 'v:val =~ "^-"'), -1, ''), '- \zs\S\+\ze:')
if !empty(plug)
execute 'cd' g:plugs[plug].dir
GV HEAD@{1}..
cd -
endif
endfunction
function! s:setup_extra_keys()
nnoremap <silent> <buffer> J :call <sid>scroll_preview(1)<cr>
nnoremap <silent> <buffer> K :call <sid>scroll_preview(0)<cr>
nnoremap <silent> <buffer> <c-n> :call search('^ \zs[0-9a-f]')<cr>
nnoremap <silent> <buffer> <c-p> :call search('^ \zs[0-9a-f]', 'b')<cr>
nnoremap <silent> <buffer> <c-g> :call <sid>diff_in_gv()<cr>
nmap <silent> <buffer> <c-j> <c-n>o
nmap <silent> <buffer> <c-k> <c-p>o
endfunction
augroup PlugDiffExtra
autocmd!
autocmd FileType vim-plug call s:setup_extra_keys()
augroup END