From a2271a239646ecffa2fbaa6004614b9ac82f6bb4 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Mon, 25 Dec 2023 16:35:15 -0800 Subject: [PATCH] feat: grep cword|cWORD to match whole words (closes #968) --- lua/fzf-lua/providers/grep.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 06dc91592..628c3aa1e 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -344,13 +344,17 @@ end M.grep_cword = function(opts) if not opts then opts = {} end - opts.search = vim.fn.expand("") + opts.no_esc = true + -- match whole words only (#968) + opts.search = [[\b]] .. utils.rg_escape(vim.fn.expand("")) .. [[\b]] return M.grep(opts) end M.grep_cWORD = function(opts) if not opts then opts = {} end - opts.search = vim.fn.expand("") + opts.no_esc = true + -- match neovim's WORD, match only surrounding space|SOL|EOL + opts.search = [[(^|\s)]] .. utils.rg_escape(vim.fn.expand("")) .. [[($|\s)]] return M.grep(opts) end