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

Nvim lua custom source?

Open alex-popov-tech opened this issue 5 years ago • 3 comments

  • [x] I have fzf 0.23.0 or above
  • [x] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
  • [x] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
  • [x] I have read through the manual page of fzf (man fzf)
  • [x] I have searched through the existing issues

I wasn't able to find any examples of filtering results returned from the nvim's lua api... Can someone please point me to any source or example integrationg fzf with lua? The actual point is - I'm using fzf#vim all the time, and would like to search through vim.lsp.diagnostic.get_all()

alex-popov-tech avatar Dec 04 '20 21:12 alex-popov-tech

I have developed a Neovim plugin in Lua that makes the LSP client use FZF: nvim-lspfuzzy. If you're interested only in the part where I integrate FZF, here are the relevant functions.

There are basically two functions: fzf() calls FZF and feeds it with lines and jump() is the sink function that gets called when the user has made its selection. Hope that'll help.

ojroques avatar Dec 10 '20 18:12 ojroques

thanks! but i would wait for maybe solution from fzf, cause if choosing new plugin i can use something like telescope :)

alex-popov-tech avatar Dec 12 '20 00:12 alex-popov-tech

Sorry to resurrect a zombie issue. I recently encountered the same problem and ended up with a solution that's good enough for me.

local function fzf_table(sources)
    table.foreach(sources, function (k, v) sources[k] = vim.fn.shellescape(v) end)
    local query = table.concat(sources, ' ')
    vim.fn['fzf#vim#grep']("rg --column --line-number --no-heading --color=always --smart-case -g '*.lean' -- '' " .. query, 1, vim.fn['fzf#vim#with_preview'](), 0)
end

The gist is that vim.fn can call a Vim function from Lua. The command is adapted from the built-in :Rg. This function accepts a list of directories from Lua and run fzf#vim#with_preview similar to :Rg.

Note that:

  1. A -g filter is used for globbing files. You might want to change/abstract it for your use case.
  2. The second argument to fzf#vim#grep, has_column, is deprecate. You might need to change it according to your version.

crvdgc avatar Jun 22 '23 20:06 crvdgc