From 21b3eeaa4f4d3761c40e660b0a72b4a7a4f1b6d6 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Fri, 15 Sep 2023 22:40:48 +0200 Subject: [PATCH] Do not focus NvimTree upon VimEnter --- lua/core/autocommands.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/core/autocommands.lua b/lua/core/autocommands.lua index 556ad90..0a9394f 100644 --- a/lua/core/autocommands.lua +++ b/lua/core/autocommands.lua @@ -22,7 +22,15 @@ local function term_close() end local function open_file_tree() - require("nvim-tree.api").tree.open() + local ok, mod = pcall(require, "nvim-tree.api") + if ok then + -- get current window id + local win = vim.api.nvim_get_current_win() + -- open NvimTree + mod.tree.open() + -- switch back focus to previous window + vim.api.nvim_set_current_win(win) + end end vim.api.nvim_create_autocmd("TermClose", {