-
I want to ask whether the following is an optimal way to grep a project (by providing the project root as local fzf_lua = require 'fzf-lua'
local actions = fzf_lua.actions
local utils = fzf_lua.utils
local fzf_grep_project = fzf_lua.grep_project
nnmap('<leader>G', function() fzf_grep_project({search=utils.input('Grep For❯ ')}) end, {desc="Fzf-Lua grep"})
nnmap('<leader>gr', function() fzf_grep_project({continue_last_search = true}) end, {desc="Fzf-Lua grep continue last"})
xnmap('<leader>gv', function() fzf_grep_project({search=utils.get_visual_selection()}) end, {desc="Fzf-Lua grep visual"})
local root_markers = {
'.gitignore',
'CMakeLists.txt',
'compile_commands.json',
'compile_flags.txt',
'configure.ac', -- AutoTools
'cmake',
'setup.py',
'requirements.txt',
'build',
'.clangd',
'.clang-tidy',
'.clang-format',
}
local root_dir = function(fname, rm)
fname = fname or 0
rm = rm or root_markers
return vim.fs.root(fname, rm)
end
nnmap('<leader>gp', function() fzf_grep_project({search=utils.input('Grep For❯ '), cwd=root_dir(vim.api.nvim_buf_get_name(0))}) end, {desc="Fzf-Lua grep project"}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Yes, your code is great, if you’re only using this in git repos you can also fzf-lua path utils to get the git root (uses :lua FzfLua.grep_project({ cwd = FzfLua.path.git_root({}) }) |
Beta Was this translation helpful? Give feedback.
Yes, your code is great, if you’re only using this in git repos you can also fzf-lua path utils to get the git root (uses
git rev-parse …
behind the scenes):