Following works for me:
vim.keymap.set('n','<leader>f', function()
local pattern = vim.fn.input("Search pattern: ")
local cmd = [[vimgrep /]].. pattern .. [[/j `git ls-files --full-name :/ \| sed "s;^;$(git rev-parse --show-toplevel)/;"` | copen]]
return vim.cmd(cmd)
end,opts)
EDIT: Ensured absolute path file patterns, so that vimgrep
has no issues when cwd
is somewhere inside the project.
EDIT 2: The only requirement for this method is an initialized Git repository. It doesn’t need Language Server Protocol features. .gitignore
will be respected.