-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Question. How to include dynamic args to live_grep #167
Comments
You can modify :lua require'fzf-lua'.live_grep({ rg_opts = “…” }) Another example: :lua require'fzf-lua'.live_grep({ cmd = “rg …” }) You can even provide |
Okay, but |
I see, I think you might need a custom script for that, see this discussion about using the |
Yeah, I guess that's the only way for now, thanks. |
In the latest commit I added the option to supply BUT require'fzf-lua'.setup {
grep = {
cmd_fn = function(opts, query, _)
local parts = vim.split(query, ">")
local iglob = ""
if #parts > 1 then
for i=1,#parts-1 do
iglob = iglob .. (" --iglob %s"):format(vim.fn.shellescape(parts[i]))
end
end
local cmd = ("rg %s %s -- %s"):format(opts.rg_opts, iglob,
vim.fn.shellescape(require'fzf-lua.utils'.rg_escape(parts[#parts])))
-- print(cmd)
return cmd
end,
},
}
|
Btw, this is just a quick proof of concept code, tomorrow I’ll add something a bit more robust with customization under a new provider: |
b9c0322 this adds the grep = {
glob_flag = "--iglob", -- for case sensitive globs use '--glob'
glob_separator = "%s%-%-" -- query separator pattern (lua): ' --'
} The default separator is ' --' (space, dash, dash), glob parsing only starts after it detects the full 3 character pattern (so you can still search for dashes or spaces), can be easily modified, just remember it's a lua string pattern so special characters have to be specified the lua way. Below is a demo of how it works, I printed the command below the status line so you can see how the command is dynamically modified with each keypress and the corresponding |
@LoydAndrew, @fanliver I'll leave this issue open for now until you guys let me know if this works fine and covers all use cases (including customization)? |
@ibhagwan |
You don’t have to escape dash as a separator (see my screencast, it’s not escaped), but you do have to escape it to search for it literally as it’s a regex special character like EDIT: actually if you wanna add dash into the glob I can make sure the glob arguments are escaped, lmk. |
Works great for me. |
Great!
Before I close this, @fanliver can you let me know which character's you'd like escaped inside the glob and what is the use case? what is the exact use case for adding |
Sometimes, I look for the command line argument in shell script or some text in the code with hyphen in the name. |
Alright, then I guess we can close this. |
Could we have something like |
Don't need a special command for that, just change your mapping to: :lua require'fzf-lua'.live_grep_glob({ continue_last_search = true })
-- live_grep_resume is just a shortcut too:
:lua require'fzf-lua'.live_grep({ continue_last_search = true }) |
@ibhagwan Thank you! (and I just notice that this option is not shown on README.md.) |
@ibhagwan How to use glob without manually adding |
You’d have to create your own custom implementation, the |
@ibhagwan My idea is that this can be done without changing the syntax of |
Then we can further design a syntax (as a quick example)
Indeed the current
instead of this:
You can see that most of the time we need wildcard, so why not wrap the keyword with it for the users? On the contrary, the current one is buggy: |
I understood what you meant and of course it can be done, anything can be done and you can make the parser do whatever you want and adjust to I just personally think it's too much of a narrow use case and also very specific, it requires knowing how the format works and additonal "manual", I prefer to stay with the default syntax, as long as users know the argument passes "as is" into an
I'm not even sure if this is possible, I think
Once the matches stop and the command returns no results I think the last known result is still displayed, use |
I want to include dynamic args for live_grep, for example in vim-clap plugin in grep provider input you can specify
actions *.ts
and it will translate query torg -g "*.ts" "actions"
. Or in emacs world there is an ivy-plugin where in rg you can specifyactions -- -t ts
and achieve the same behaviour. Can we have something like this?The text was updated successfully, but these errors were encountered: