command for searching in current buffer/directory
what command for searching in current buffer/directory on Windows system? I use :TodoTrouble cwd=%:h but cannot get the result
+1 Would be really useful to have the option to view TODOs in the current buffer.
I don't believe it is currently possible to search the buffer because the search function expects a directory as input that would likely require a PR.
However, you can search the current directory of your buffer via:
vim.keymap.set('n', '<leader>ft', function()
vim.api.nvim_command("TodoTrouble cwd=" .. vim.fn.expand "%:p:h")
end)
@nmxiao I haven't tested this on windows, but you could give it a try.
Assuming default search config using rg, passing a filename and directory as cwd can be used to search in current file or directory of current file. The cwd values are passed as the PATH in ripgrep, so we can pass in filenames, directories, etc:
-- Find TODOs within directory for current buffer
vim.keymap.set('n', '<leader>td', function()
local command = "TodoQuickFix " .. vim.fn.expand("%:p:h")
vim.api.nvim_command(command)
end)
-- Find TODOs within current file
vim.keymap.set('n', '<leader>tt', function()
local command = "TodoQuickFix " .. vim.fn.expand("%")
vim.api.nvim_command(command)
end)
I believe the original issue with :TodoTrouble cwd=%:h is not expanding %:h beforehand
cc @nmxiao @felixkreuk