diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index f6eb5a44..4ed1fa33 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -84,8 +84,11 @@ local get_grep_cmd = function(opts, search_query, no_esc) end search_query = search_query or "" - if not (no_esc or opts.no_esc) then - search_query = utils.rg_escape(search_query) + if #search_query > 0 and not (no_esc or opts.no_esc) then + -- For UI consistency, replace the saved search query with the regex + opts.no_esc = true + opts.search = utils.rg_escape(search_query) + search_query = opts.search end -- remove column numbers when search term is empty diff --git a/lua/fzf-lua/utils.lua b/lua/fzf-lua/utils.lua index 014523a9..228e0da3 100644 --- a/lua/fzf-lua/utils.lua +++ b/lua/fzf-lua/utils.lua @@ -209,7 +209,9 @@ function M.rg_escape(str) end function M.regex_to_magic(str) - return [[\v]] .. str:gsub([[\\]], [[\]]):gsub("=", [[\=]]) + -- Convert regex to "very magic" pattern, basically a regex + -- with special meaning for "=&<>", `:help /magic` + return [[\v]] .. str:gsub("[=&<>]", function(x) return [[\]] .. x end) end function M.sk_escape(str)