From e03e7e97d66524eca75a1d930b28eb9f170ba7e5 Mon Sep 17 00:00:00 2001 From: gustav-fff <286169375+gustav-fff@users.noreply.github.com> Date: Fri, 26 Jun 2026 09:59:35 -0700 Subject: [PATCH 1/4] docs(nvim): add visual-mode example for fc keymap (#631) Refs #631 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 994d7a938..a257656a2 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,17 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb function() require('fff').live_grep({ query = vim.fn.expand("") }) end, desc = 'Search current word', }, + { "fc", + function() + local saved = vim.fn.getreg('v') + vim.cmd('normal! "vy') + local query = vim.fn.getreg('v'):gsub('\n', '') + vim.fn.setreg('v', saved) + require('fff').live_grep({ query = query }) + end, + mode = 'x', + desc = 'Search visual selection', + }, }, } ``` From 71aeaea54b53ea1aa6f955b80890a5168da98087 Mon Sep 17 00:00:00 2001 From: gustav-fff <286169375+gustav-fff@users.noreply.github.com> Date: Fri, 26 Jun 2026 10:16:37 -0700 Subject: [PATCH 2/4] feat(api): add live_grep_under_cursor for normal/visual mode --- README.md | 17 ++++------------- lua/fff/main.lua | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a257656a2..a02efc9fd 100644 --- a/README.md +++ b/README.md @@ -148,19 +148,9 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb desc = 'Live fffuzy grep', }, { "fc", - function() require('fff').live_grep({ query = vim.fn.expand("") }) end, - desc = 'Search current word', - }, - { "fc", - function() - local saved = vim.fn.getreg('v') - vim.cmd('normal! "vy') - local query = vim.fn.getreg('v'):gsub('\n', '') - vim.fn.setreg('v', saved) - require('fff').live_grep({ query = query }) - end, - mode = 'x', - desc = 'Search visual selection', + function() require('fff').live_grep_under_cursor() end, + mode = { 'n', 'x' }, + desc = 'Search current word / selection', }, }, } @@ -194,6 +184,7 @@ vim.keymap.set('n', 'ff', function() require('fff').find_files() end, { desc = ' ```lua require('fff').find_files() -- find files in current repo require('fff').live_grep() -- live content grep +require('fff').live_grep_under_cursor() -- grep in normal, selection in visual require('fff').scan_files() -- force rescan require('fff').refresh_git_status() -- refresh git status require('fff').find_files_in_dir(path) -- find in a specific dir diff --git a/lua/fff/main.lua b/lua/fff/main.lua index 1418a2d71..9f577967d 100644 --- a/lua/fff/main.lua +++ b/lua/fff/main.lua @@ -56,6 +56,24 @@ function M.live_grep(opts) picker_ui.open(picker_opts) end +--- Live grep prefilled with the current word (normal mode) or the visual selection (visual mode). +--- @param opts? table Forwarded to `live_grep`; `query` is overwritten by the resolved text. +function M.live_grep_under_cursor(opts) + local mode = vim.fn.mode() + local query + if mode == 'v' or mode == 'V' or mode == '\22' then + local saved = vim.fn.getreg('v') + vim.cmd('normal! "vy') + query = (vim.fn.getreg('v') or ''):gsub('\n', ' ') + vim.fn.setreg('v', saved) + else + query = vim.fn.expand('') + end + + opts = vim.tbl_deep_extend('force', opts or {}, { query = query }) + M.live_grep(opts) +end + --- Changes the directory indexed by the file picker to the git root and opens the file picker --- @deprecated Use `find_files` instead function M.find_in_git_root() From 7d44fd8fe59255a6dea7b932edffbdff312ef097 Mon Sep 17 00:00:00 2001 From: gustav-fff <286169375+gustav-fff@users.noreply.github.com> Date: Fri, 26 Jun 2026 11:00:54 -0700 Subject: [PATCH 3/4] refactor(nvim): live_grep_under_cursor reads visual region without yank Use getpos('<)/getpos('>) + getregion() instead of yanking into the v register. Avoids touching the user's registers entirely. --- lua/fff/main.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/fff/main.lua b/lua/fff/main.lua index 9f577967d..1bc1ca832 100644 --- a/lua/fff/main.lua +++ b/lua/fff/main.lua @@ -62,10 +62,13 @@ function M.live_grep_under_cursor(opts) local mode = vim.fn.mode() local query if mode == 'v' or mode == 'V' or mode == '\22' then - local saved = vim.fn.getreg('v') - vim.cmd('normal! "vy') - query = (vim.fn.getreg('v') or ''):gsub('\n', ' ') - vim.fn.setreg('v', saved) + -- Exit visual so '< / '> marks settle, then read the range directly — + -- no yank, no register clobber. + vim.cmd('normal! ' .. vim.api.nvim_replace_termcodes('', true, false, true)) + local s = vim.fn.getpos("'<") + local e = vim.fn.getpos("'>") + local lines = vim.fn.getregion(s, e, { type = mode }) + query = table.concat(lines, ' ') else query = vim.fn.expand('') end From f80bfed89bcc2ec77b56861884448f52049964b7 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Fri, 26 Jun 2026 16:26:07 -0700 Subject: [PATCH 4/4] chore: improve default binding --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a02efc9fd..5cbcd8170 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb function() require('fff').live_grep({ grep = { modes = { 'fuzzy', 'plain' } } }) end, desc = 'Live fffuzy grep', }, - { "fc", + { "fw", function() require('fff').live_grep_under_cursor() end, mode = { 'n', 'x' }, desc = 'Search current word / selection',