From 9baf707465de96c28a5f3da8ce24dd71a9c586cc Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 30 May 2024 22:14:53 +0200 Subject: make NERDTree resizingf & moving more robust --- lua/functions.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lua/functions.lua b/lua/functions.lua index 1f088a8..3c19268 100644 --- a/lua/functions.lua +++ b/lua/functions.lua @@ -63,17 +63,18 @@ function _G.toggle_terminal() vim.g.term_win = vim.fn.win_getid() if vim.fn.exists("g:NERDTree") and vim.api.nvim_eval("g:NERDTree.IsOpen()") then - vim.cmd("NERDTreeFocus") + local nerdtree_win_num = vim.api.nvim_eval("g:NERDTree.GetWinNum()") - vim.cmd("wincmd H") + local nerdtree_win_id = vim.fn.win_getid(nerdtree_win_num) - local width_diff = vim.fn.winwidth(0) - vim.g.NERDTreeWinSize + vim.api.nvim_win_call( + nerdtree_win_id, + function() + vim.cmd("wincmd H") + end + ) - vim.cmd(width_diff .. "wincmd <") - - vim.cmd("wincmd p") - - vim.fn.feedkeys("A") + vim.api.nvim_win_set_width(nerdtree_win_id, vim.g.NERDTreeWinSize) end end end -- cgit v1.2.3-18-g5258