Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ 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",
function() require('fff').live_grep({ query = vim.fn.expand("<cword>") }) end,
desc = 'Search current word',
{ "fw",
function() require('fff').live_grep_under_cursor() end,
mode = { 'n', 'x' },
desc = 'Search current word / selection',
},
},
}
Expand Down Expand Up @@ -183,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 <cword> 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
Expand Down
21 changes: 21 additions & 0 deletions lua/fff/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ 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
-- Exit visual so '< / '> marks settle, then read the range directly —
-- no yank, no register clobber.
vim.cmd('normal! ' .. vim.api.nvim_replace_termcodes('<Esc>', 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('<cword>')
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()
Expand Down
Loading