live_grep config to: set glob, toggle case-sensitivity and toggle regex #2312
hernancerm
started this conversation in
Show and tell
Replies: 1 comment
-
|
Looks great, ty for sharing @hernancerm!! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the picker
live_grepI like having dedicated keymaps to toggle case-sensitivity, regex, and also to set a glob. Below is a short video showing what I mean. This behavior aligns more closely thanrequire("fzf-lua").actions.grep_lgrepto what is offered in most editors.fzf-lua_live_grep.mp4
Here is the excerpt of my lazy.nvim config used for the video. It's brittle in a way since I'm using non-public code from fzf-lua:
{ "ibhagwan/fzf-lua", event = "VeryLazy", opts = function() local utils = require("fzf-lua.utils") local actions = require("fzf-lua.actions") return { defaults = { header_separator = " | " }, grep = { rg_opts = "--column --line-number --no-heading --color=always" .. " --fixed-strings --ignore-case --max-columns=4096 -e", formatter = "path.filename_first", winopts = { backdrop = 100, border = "single", preview = { border = "single", title_pos = "left", layout = "vertical" }, }, actions = { ["ctrl-g"] = { fn = function(_, opts) vim.ui.input({ prompt = "Enter glob pattern: " }, function(input) vim.g._fzf_lua_glob_previous = vim.g._fzf_lua_glob_current or input vim.g._fzf_lua_glob_current = input end) -- It's ok to always remove the previous glob since `utils.toggle_cmd_flag()` -- internally does a `gsub` to the empty string ("") when arg `enabled` == false. local cmd = utils.toggle_cmd_flag( utils.toggle_cmd_flag( opts._cmd or opts.cmd, "--glob=" .. vim.g._fzf_lua_glob_previous, false), "--glob=" .. vim.g._fzf_lua_glob_current, true) -- See function actions.toggle_flag in fzf-lua repo. local o = vim.tbl_deep_extend("keep", { cmd = cmd, resume = true }, opts.__call_opts) opts.__call_fn(o) end, desc = "set-glob-pattern", header = function(o) local no_glob = "[] Glob" if vim.g._fzf_lua_glob_current == nil then return no_glob end local flag = "--glob=" .. vim.g._fzf_lua_glob_current if o.cmd and o.cmd:match(utils.lua_regex_escape(flag)) then return "[" .. vim.g._fzf_lua_glob_current .. "] Glob" else return no_glob end end }, ["ctrl-r"] = { 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" local cmd = o.cmd or o._cmd if cmd and cmd:match(utils.lua_regex_escape(flag)) then return "[ ] Regex" else return "[x] Regex" end end }, ["ctrl-s"] = { fn = function(_, opts) actions.toggle_flag(_, vim.tbl_extend("force", opts, { toggle_flag = "--ignore-case" })) end, desc = "toggle-ignore-case", header = function(o) local flag = "--ignore-case" local cmd = o.cmd or o._cmd if cmd and cmd:match(utils.lua_regex_escape(flag)) then return "[ ] Case-sensitive" else return "[x] Case-sensitive" end end } } } } end },Changelog:
Beta Was this translation helpful? Give feedback.
All reactions