Skip to content

Commit

Permalink
feat: grep cword|cWORD to match whole words (closes #968)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 26, 2023
1 parent f2083c5 commit a2271a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/fzf-lua/providers/grep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,17 @@ end

M.grep_cword = function(opts)
if not opts then opts = {} end
opts.search = vim.fn.expand("<cword>")
opts.no_esc = true
-- match whole words only (#968)
opts.search = [[\b]] .. utils.rg_escape(vim.fn.expand("<cword>")) .. [[\b]]
return M.grep(opts)
end

M.grep_cWORD = function(opts)
if not opts then opts = {} end
opts.search = vim.fn.expand("<cWORD>")
opts.no_esc = true
-- match neovim's WORD, match only surrounding space|SOL|EOL
opts.search = [[(^|\s)]] .. utils.rg_escape(vim.fn.expand("<cWORD>")) .. [[($|\s)]]
return M.grep(opts)
end

Expand Down

0 comments on commit a2271a2

Please sign in to comment.