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

[help] How to send all results—selected or not—to quickfix? #546

Closed
bravoecho opened this issue Oct 17, 2022 · 12 comments
Closed

[help] How to send all results—selected or not—to quickfix? #546

bravoecho opened this issue Oct 17, 2022 · 12 comments
Labels
duplicate This issue or pull request already exists

Comments

@bravoecho
Copy link

Hi, I was looking in the docs and in actions.lua, to see if I could change the default action for the non-interactive :FzfLua grep. I would like to reproduce vim-grepper's behaviour, that is, directly send all the results to the quickfix. Is it possible? Thanks!

@ibhagwan
Copy link
Owner

Duplicate of #324, take a look and see if that solves your issue.

@ibhagwan ibhagwan added the duplicate This issue or pull request already exists label Oct 17, 2022
@bravoecho
Copy link
Author

Thank you @ibhagwan!
I've tried the following setup:

local fzf_lua = require('fzf-lua')
fzf_lua.setup({
  winopts = {
    split = "botright new",
  },
  grep = {
    actions = {
      ["default"] = "select-all+accept"
    },
  },
})

but when I press enter in the Grep For> prompt, I still get the results in a terminal.

@ibhagwan
Copy link
Owner

Not sure if I understand what you mean, can you elaborate or better yet post a screenshot so I can understand what you mean by:

but when I press enter in the Grep For> prompt, I still get the results in a terminal.

@bravoecho
Copy link
Author

Sure, thanks!

I enter my search:

image

and when I press enter a window named :term//... opens

image

instead, I need the quickfix to open, as if I had used :vimgrep foo **/* followed by :copen.

@ibhagwan
Copy link
Owner

ibhagwan commented Oct 19, 2022

instead, I need the quickfix to open, as if I had used :vimgrep foo **/* followed by :copen

The terminal window that opens is fzf-lua’s grep window, it lets you fuzzy match the results and then you can select a few items and press enter to send the selected items to quick fix (default behavior), with the setup you added you made it so the default action sends all items to quickfix, but you still need to press enter again (after the interface is open with the results).

If you wish to skip the fzf-lua terminal window then you can use vimgrep directly as there is no added value in doing so with fzf-lua, am I missing something here?

Also, something is off with the preview in your screenshot, or should align perfectly on the bottom right side of the split but the layout is totally off, can you post your full setup so I can reproduce this bug?

@bravoecho
Copy link
Author

bravoecho commented Oct 20, 2022

I see now, you are right! I'm just primed into thinking in terms of "command > output > quickfix", and then operate on it, by jumping or by :cfdo 🤦‍♂️ Sorry about the confusion.

You are right, in this case I could just use the right combination of :grep, grepprg, a custom command and :copen | wincmd J. In both cases populating the quickfix would be synchronous.

Synchronous used to be OK, but when I started working on embarrassingly large repositories, that no longer cut it. So I found that https://github.com/mhinz/vim-grepper solved the issue, because it populates the quickfix asynchronously.

I guess I'll stick to it for a little longer—even it's not in Lua 😉—and use fzf-lua as a replacement for fzf.vim.

Regarding the wonky preview in the screenshot, the one I posted above is my full setup, it's only wonky because for some reason I resized the term window with the mouse, but they were initially the same height, so no problem there 🙂

@bravoecho
Copy link
Author

PS: thank you so much for your friendly feedback, hugely appreciated!

@ibhagwan
Copy link
Owner

use fzf-lua as a replacement for fzf.vim.

Yes.

Regarding the wonky preview in the screenshot, the one I posted above is my full setup, it's only wonky because for some reason I resized the term window with the mouse, but they were initially the same height, so no problem there 🙂

Happy to know it’s not a bug :)

@jsbmg
Copy link

jsbmg commented Sep 26, 2023

Hello, it seems this isn't working in the latest version - the syntax has changed.

I'm attempting to accomplish the above with this:

        grep = {
          actions = {
            ["enter"] = { prefix = "select-all+", fn = actions.file_edit_or_qf } 
          }
        },

But it seems that "select-all+" isn't actually working. Am I doing this incorrectly? I don't see an action for select_all.

@ibhagwan
Copy link
Owner

But it seems that "select-all+" isn't actually working. Am I doing this incorrectly? I don't see an action for select_all.

There isn’t an fzf-lua action to select all, this is an fzf (the binary) action, this prefix’s the fzf-lua action with a “select all”.

@ibhagwan
Copy link
Owner

@jsbmg, you're mixing up a few things, if you wish to send all results to quickfix, take a look at #324, use :

  grep = {
    keymap = { fzf = { ["enter"] = "select-all+accept" } },
    actions = { ["default"] = { actions.file_edit_or_qf },
  },

The reason this works is because the keys are first interpreted by fzf which in turns selects all items and "accepts" (i.e. fzf exits and sends all selected items as output), fzf-lua will then interpret the action with "enter" being the default action, edit_or_qf will then see more than one file was selected and send it all to the quickfix.

@jsbmg
Copy link

jsbmg commented Sep 26, 2023

@ibhagwan makes perfect sense now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants