junegunn / fzf.vim

fzf :heart: vim
MIT License
9.59k stars 582 forks source link

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

Open ragcatshxu opened 4 years ago

ragcatshxu commented 4 years ago

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?

nabaco commented 4 years ago
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)

junyixu commented 3 years ago

hi, Is there a way to find the reference

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

mamegek commented 2 years ago

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)