fzf.vim icon indicating copy to clipboard operation
fzf.vim copied to clipboard

How to use fzf#run search current file or all current buffer gtags?

Open ragcatshxu opened this issue 5 years ago • 3 comments

  • Category
    • [x ] Question
    • [ ] Bug
    • [ ] Suggestion
  • OS
    • [x] Linux
    • [ ] macOS
    • [ ] Windows
    • [ ] Etc.
  • Vim
    • [ ] Vim
    • [ ] Neovim

I use vim8.1 and the newest fzf and fzf.vim and I use gnu global tag system to explore huge code base. Under shell I can run global -f xxxx.c | fzf then can fuzzy search . Now I want to use it under vim to search current file or all buffer files tag also with preview at same time , how to use fzf#run or fzf#wrap achieve my goal ? call fzf#run({ \ 'source': 'global -f %', \ 'down':'40%' , \ \ 'options': fzf#vim#with_preview('down:60%'),})

can any one give some suggestion?

ragcatshxu avatar Sep 19 '19 14:09 ragcatshxu

function s:gtags_search(line)
     let l:line = split(a:line)[1]
     let l:file = split(a:line)[2]
     execute 'edit +'.l:line l:file
endfunction

 nnoremap <silent> <Leader>t :call fzf#run(fzf#wrap({'source':'global -x .', 'sink':function('<sid>gtags_search'),
             \ 'options': ['-m', '-d', '\t', '--with-nth', '1,2', '-n', '1', '--prompt', 'Tags> ']}))<CR>

It works quite well for searching tags globally.

It's not the prettiest and I'm still trying to figure out how to preview properly (need to get the filename and line number to preview.sh that comes with the plugin)

nabaco avatar Jun 07 '20 14:06 nabaco

hi, Is there a way to find the reference

eg: :Gtags -r PATTERN To go to the referenced point of 'func'

junyixu avatar Oct 14 '20 10:10 junyixu

By converting the output of global command to grep format, I can use the preview.

function! GtagsFzf(query, fullscreen)
    let command_fmt = ' global -x -- %s | awk ''{printf  $3 ":" $2 "\t"}{$1=$2=$3=""; print $0}'' '
    let command = printf(command_fmt, a:query)
    call fzf#vim#grep(command, 0, fzf#vim#with_preview(), a:fullscreen)
endfunction

command! -nargs=* -bang Gtfzf call GtagsFzf(<q-args>, <bang>0)

mamegek avatar Aug 10 '22 11:08 mamegek