Is there a way to set the root directory to the directory of the currently focused buffer? #1932
-
Sometimes i open a file with nvim like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can try something like this: local function my_startup(data)
-- is the buffer a real file?
if vim.fn.filereadable(data.file) ~= 1 then
return
end
-- is it in a real directory
local dir = vim.fn.fnamemodify(data.file, ":h")
if vim.fn.isdirectory(dir) == 0 then
return
end
-- change directory
vim.cmd.cd(dir)
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = my_startup }) See #1669 (comment) for more ideas. |
Beta Was this translation helpful? Give feedback.
You can try something like this:
See #1669 (comment) for more ideas.