-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
extra
Junegunn Choi edited this page Mar 3, 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, '^ \X*\zs\x\{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
function! s:plug_doc()
let name = matchstr(getline('.'), '^- \zs\S\+\ze:')
if has_key(g:plugs, name)
for doc in split(globpath(g:plugs[name].dir, 'doc/*.txt'), '\n')
execute 'tabe' doc
endfor
endif
endfunction
augroup PlugHelp
autocmd!
autocmd FileType vim-plug nnoremap <buffer> <silent> H :call <sid>plug_doc()<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('^ \X*\zs\x')<cr>
nnoremap <silent> <buffer> <c-p> :call search('^ \X*\zs\x', '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