After recently switching to a split keyboard, I’ve found myself using NeoVim more and more. I only have a very basic configuration at the moment, as I still find it very overwhelming.
I haven’t really used it yet as an IDE replacement for VSCode, but I’ve been slowly adding features to my configuration, like Telescope for fuzzy finding.
But by default its find_files
function searches the entire hard drive, which
really is not helpful, slow and full of bad matches.
To set it to only find files in the currently opened directory I’ve configured
the functionality in my telescope.lua
like so:
vim.keymap.set("n", "<leader>fd", function()
local dir = vim.fn.argv(0)
if dir ~= "" and vim.fn.isdirectory(dir) == 1 then
require('telescope.builtin').find_files({ cwd = dir })
else
require('telescope.builtin').find_files()
end
end)
So now when I open a folder using nvim /path/to/project
, my <leader>fd
command will search only files in the opened directory and its subdirectories.
Super helpful and took me a surprising amount of time to get to work correctly.