junegunn / fzf.vim

fzf :heart: vim
MIT License
9.62k stars 584 forks source link

[Question] How to configure live grep with `--glob` support? #1473

Closed linrongbin16 closed 1 year ago

linrongbin16 commented 1 year ago

Hi,

I want to configure live grep (just like fzf-lua and telescope.nvim) with --glob support. Because search text with filetype filter is a big needs to me, how could I do that?

There're two relate plugins support this mode:

  1. fzf-lua - live_grep_glob
  2. telescope-live-grep-args.nvim
crvdgc commented 1 year ago

You can define a new function similar to the built-in :Rg and pass the glob pattern to the rg command.

Concretely, notice the :Rg definition: fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>), fzf#vim#with_preview(), <bang>0). You can break up the <q-args> to use the first as the glob pattern and the rest to fzf#vim#grep. See :help <q-args>.

Alternatively, from Lua, you can abstract the glob as a function argument and call fzf#vim#grep with vim.fn like this. (Note the glob pattern is not abstracted in the example and the second argument has_column is deprecate. You might need to change it according to your version of fzf.vim.)

linrongbin16 commented 1 year ago

https://github.com/linrongbin16/fzfx.vim

finally support in this plugin

junegunn commented 1 year ago

Also notice that we now have grep2.

https://github.com/junegunn/fzf.vim/commit/87b60bb133032056fda105e0ce6f5d64436926dd