aboutsummaryrefslogtreecommitdiff
path: root/lua/custom-autocmd.lua
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2024-01-07 15:22:13 +0100
committerjdhao <jdhao@hotmail.com>2024-01-07 15:24:47 +0100
commit841650868606299bdebd09c9cdca5c9604ab9f09 (patch)
treee8f83bee046a270160eeb3aab708aad6c65a515c /lua/custom-autocmd.lua
parentdf9491b05bd3c51366185a653850a72acf2f16cb (diff)
Enable nvim-tree to open dir during startup
Now when you open a directory when starting nvim, nvim-tree will be opened to handle the directory correctly, see also issue #257.
Diffstat (limited to 'lua/custom-autocmd.lua')
-rw-r--r--lua/custom-autocmd.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/lua/custom-autocmd.lua b/lua/custom-autocmd.lua
index 83a1a48..21fa15c 100644
--- a/lua/custom-autocmd.lua
+++ b/lua/custom-autocmd.lua
@@ -83,3 +83,23 @@ api.nvim_create_autocmd("VimResized", {
desc = "autoresize windows on resizing operation",
command = "wincmd =",
})
+
+local function open_nvim_tree(data)
+ -- check if buffer is a directory
+ local directory = vim.fn.isdirectory(data.file) == 1
+
+ if not directory then
+ return
+ end
+
+ -- create a new, empty buffer
+ vim.cmd.enew()
+
+ -- wipe the directory buffer
+ vim.cmd.bw(data.buf)
+
+ -- open the tree
+ require("nvim-tree.api").tree.open()
+end
+
+vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })