todo-comments.nvim icon indicating copy to clipboard operation
todo-comments.nvim copied to clipboard

command for searching in current buffer/directory

Open nmxiao opened this issue 4 years ago • 4 comments

what command for searching in current buffer/directory on Windows system? I use :TodoTrouble cwd=%:h but cannot get the result

nmxiao avatar Sep 24 '21 17:09 nmxiao

+1 Would be really useful to have the option to view TODOs in the current buffer.

felixkreuk avatar Jan 26 '22 16:01 felixkreuk

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.

logan-connolly avatar Apr 20 '22 08:04 logan-connolly

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

leoshimo avatar Jun 18 '22 19:06 leoshimo