~gpanders/dotfiles

0a8935ccdd01d684dc1027dd5ac7dac2d7eca2c8 — Greg Anders 2 years ago 58f0d9c
Add fzf :Tags command
2 files changed, 39 insertions(+), 12 deletions(-)

M vim/.vim/after/plugin/fzf.vim
M vim/.vim/autoload/fzf.vim
M vim/.vim/after/plugin/fzf.vim => vim/.vim/after/plugin/fzf.vim +6 -0
@@ 18,5 18,11 @@ nnoremap <silent> <C-P> :FZF<CR>
command! -bang Helptags call fzf#helptags(<bang>0)
nnoremap <silent> <C-H> :<C-U>Helptags<CR>

command! -bang -nargs=? Tags call fzf#tags(<bang>0, '<args>', '')
nnoremap <Space>] :<C-U>Tags<CR>

command! -bang -nargs=? Ptags call fzf#tags(<bang>0, '<args>', 'p')
nnoremap <Space>} :<C-U>Ptags<CR>

" Hide statusline in FZF buffers
autocmd! FileType fzf set laststatus=0 noruler | autocmd BufLeave <buffer> set laststatus=2 ruler

M vim/.vim/autoload/fzf.vim => vim/.vim/autoload/fzf.vim +33 -12
@@ 3,17 3,38 @@
" Date: 2019-05-07

function! fzf#helptags(bang)
  if !exists('*fzf#run')
    echohl ErrorMsg
    echom 'FZF installation not found'
    echohl None
    return
  endif
    if !exists('*fzf#run')
        echohl ErrorMsg
        echom 'FZF installation not found'
        echohl None
        return
    endif

  let tags = uniq(sort(globpath(&rtp, 'doc/tags', 0, 1)))
  call fzf#run(fzf#wrap('Helptags', {
        \ 'source': 'grep -ho "^\S\+" ' . join(tags),
        \ 'sink': 'help',
        \ 'options': '+m'
        \ }, a:bang))
    let tags = uniq(sort(globpath(&runtimepath, 'doc/tags', 0, 1)))
    call fzf#run(fzf#wrap('Helptags', {
                \ 'source': 'grep -ho "^\S\+" ' . join(tags),
                \ 'sink': 'help',
                \ 'options': '--no-multi',
                \ }, a:bang))
endfunction

function! fzf#tags(bang, query, mod)
    if !exists('*fzf#run')
        echohl ErrorMsg
        echom 'FZF installation not found'
        echohl None
        return
    endif

    let tags = map(taglist('.'), {_, v -> printf('%-40s %-10s %s', v.name, v.kind, v.filename)})
    let options = '--select-1 --no-multi'
    if !empty(a:query)
        let options .= ' --query=' . a:query
    endif

    call fzf#run(fzf#wrap('Tags', {
                \ 'source': tags,
                \ 'sink': {t -> execute(a:mod . 'tag ' . split(t)[0])},
                \ 'options': options,
                \ }, a:bang))
endfunction