Hi,
the goal is to have a handy search feature similar to VSCode, without need to manual specify current workspace.
Current approach:
:lua vim.keymap.set('n', '<leader>f',
":vimgrep //j " .. vim.lsp.buf.list_workspace_folders()[1] .. '/**')
Result: :vimgrep //j path/to/root/**.
Having cursor position auto-placed at the missing pattern lead me to
:lua vim.keymap.set('n', '<leader>f',
":vimgrep //j " .. vim.lsp.buf.list_workspace_folders()[1] .. '/**
<c-b><right><right><right><right><right><right><right><right><right>')
Result: :vimgrep /<CURSOR_POS>/j path/to/root/**.
Next stop, I tried to persist said keybinding in init.lua as is. But realized that workspace expression is evaluated eagerly and cannot work.
Where I am struggling now:
vim.keymap.set('n','<leader>f', function() return ":vimgrep ..." end)
This just returns the string. These alternatives aren’t suited either:
print()echoes expression non-interactivelyvim.cmd()executes string immediately
1.) Instead I’d like to have a “prefilled” ex-command template in command line as shown above (command being not directly executed). How might I do this?
2.) Is there a way to adjust cursor position more elegantly than <c-b><right>...?
3.) I thought to exclude directories from .gitignore by using git ls-files instead of vim.lsp.buf.list_workspace_folders()[1]. How could I pass the path results of this external command to vimgrep?
Thanks for help !