Closed hernancerm closed 1 month ago
Ty @hernancerm but I don’t wish to add actions for every single flag possible, you can achieve this customization easily for any flag as below:
require("fzf-lua").setup({
grep = {
actions = {
["alt-g"] = {
fn = function(_, opts)
require("fzf-lua").actions.toggle_flag(_, vim.tbl_extend("force", opts, {
toggle_flag = "--ignore-case"
}))
end,
desc = "toggle-ignore-case",
header = "Toggle Ignore Case",
},
},
},
})
I figured that might be a concern, I understand. Thank you for the snippet! The only thing it's missing is alternating the header between "Respect special regex chars" and "Disable special regex chars" depending on the presence of the flag. I'll try to tweak what you provided to get this behavior.
I figured that might be a concern, I understand. Thank you for the snippet! The only thing it's missing is alternating the header between "Respect special regex chars" and "Disable special regex chars" depending on the presence of the flag. I'll try to tweak what you provided to get this behavior.
Change the header to a function and you can have that too:
header = function(o)
local flag = o.toggle_hidden_flag or "--hidden"
if o.cmd and o.cmd:match(utils.lua_regex_escape(flag)) then
return "Exclude hidden files"
else
return "Include hidden files"
end
end,
That works like a charm. Thanks for the follow up @ibhagwan!
For future reference, here is the full action mapping I'm using to toggle --fixed-strings
on grep
:
["ctrl-x"] = {
fn = function(_, opts)
actions.toggle_flag(_, vim.tbl_extend("force", opts, {
toggle_flag = "--fixed-strings"
}))
end,
desc = "toggle-fixed-strings",
header = function(o)
local flag = "--fixed-strings"
if o.cmd and o.cmd:match(utils.lua_regex_escape(flag)) then
return "Respect regex chars"
else
return "Disable regex chars"
end
end,
}
Ty for the update and snippet @hernancerm!
Problem
Solution
toggle_fixed_strings
to toggle the flag--fixed-strings
. This flag is supported by grep, ripgrep and ag. I coded this action following the implementation oftoggle_ignore
; so it was mostly an imitation game. Now toggling between regex and literal search is as simple as adding one line in the actions config of the provider:Other solutions I considered
--fixed-strings
flag in the grep provider. For the simple use case of just toggling between regex and literal search, I found the code provided by deponian to be too complicated. If possible, I would appreciate if fzf-lua provides built-in support for this flag so the user-side configuration is easy.781
Thanks.