Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 8 tasks
ragcatshxu opened this issue Sep 19, 2019 · 3 comments
Open
1 of 8 tasks

Comments

@ragcatshxu
Copy link

  • Category
    • [x ] Question
    • Bug
    • Suggestion
  • OS
    • 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?

@nabaco
Copy link

nabaco commented Jun 7, 2020

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
Copy link

junyixu commented Oct 14, 2020

hi, Is there a way to find the reference

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

@mamegek
Copy link

mamegek commented Aug 10, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants