Skip to content
Junegunn Choi edited this page Mar 30, 2024 · 22 revisions

Automatically install missing plugins on startup

autocmdVimEnter*\ iflen(filter(values(g:plugs), '!isdirectory(v:val.dir)')) \| PlugInstall --sync | q\|endif

H to open help docs

function!s:plug_doc() let name =matchstr(getline('.'), '^- \zs\S\+\ze:') ifhas_key(g:plugs, name) for doc insplit(globpath(g:plugs[name].dir, 'doc/*.txt'), '\n') execute'tabe' doc endforendifendfunctionaugroupPlugHelpautocmd!autocmdFileTypevim-plugnnoremap<buffer><silent>H :call <sid>plug_doc()<cr>augroupEND

gx to open GitHub URLs on browser

Press gx to open the GitHub URL for a plugin or a commit with the default browser.

function!s:plug_gx() letline=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'returnendiflet repo =matchstr(uri, '[^:/]*/'.name) let url =empty(sha) ? 'https://github.com/'.repo \ : printf('https://github.com/%s/commit/%s', repo, sha) callnetrw#BrowseX(url, 0) endfunctionaugroupPlugGxautocmd!autocmdFileTypevim-plugnnoremap<buffer><silent>gx :call <sid>plug_gx()<cr>augroupEND

Browse help files and README.md

Requires fzf.

function!s:plug_help_sink(line) letdir=g:plugs[a:line].dirfor pat in ['doc/*.txt', 'README.md'] letmatch=get(split(globpath(dir, pat), "\n"), 0, '') iflen(match) execute'tabedit'matchreturnendifendfortabnewexecute'Explore'direndfunctioncommand! PlugHelp callfzf#run(fzf#wrap({\ 'source': sort(keys(g:plugs)), \ 'sink': function('s:plug_help_sink')}))

A more sophisticated version with preview support:

function!s:plug_help_source() letlines= [] let longest =keys(g:plugs)->map({_, v-> strlen(v)})->max() for [name, plug] initems(g:plugs) let matches = [] for pat in ['doc/*.txt', 'README.md'] letmatch=get(split(globpath(plug.dir, pat), "\n"), 0, '') iflen(match) calladd(lines, printf("%-"..longest.."s\t%s\t%s", name, fnamemodify(match, ':t'), match)) endifendforendforreturnsort(lines) endfunctioncommand! PlugHelp callfzf#run(fzf#wrap({\ 'source': s:plug_help_source(), \ 'sink':{line-> execute('tabedit '..split(line)[-1]) }, \ 'options': ['--reverse', '--delimiter=\t', '--with-nth=1..2', '--preview', 'bat --style=numbers --color=always{-1}']}))

Extra key bindings for PlugDiff

(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
function!s:scroll_preview(down) silent!wincmdPif &previewwindowexecute'normal!'a:down ? "\<c-e>" : "\<c-y>"wincmdpendifendfunctionfunction!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>nmap<silent><buffer><c-j><c-n>onmap<silent><buffer><c-k><c-p>oendfunctionaugroupPlugDiffExtraautocmd!autocmdFileTypevim-plugcalls:setup_extra_keys() augroupEND

Plugin completion using VimAwesome

https://gist.github.com/junegunn/5dff641d68d20ba309ce

Clone this wiki locally