]> gitweb.fluxo.info Git - rhatto/dotfiles/vim.git/commitdiff
Fix: NERDTree and session restoration workarounds: use VimEnter instead of SessionLoa...
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jul 2024 04:52:07 +0000 (01:52 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 28 Jul 2024 04:52:07 +0000 (01:52 -0300)
vimrc.dot.link

index d7389dc89751948205262a08f4711d5d08bafc49..94bb0587c231a15cbd647d13ed280ae43ad492b5 100644 (file)
@@ -435,6 +435,10 @@ set sessionoptions-=winpos
 " See https://github.com/vim-scripts/vim-auto-save
 "let g:auto_save = 1
 
+"
+" NERDTree and session restoration workarounds
+"
+
 " Ensure the window has maximized height
 "
 " This helps restoring the window size after reopening sessions after
@@ -462,8 +466,26 @@ endfunction
 " In case you want to invoke FixNERDTreeWidth explicitly
 command! -bang FixNERDTreeWidth :call FixNERDTreeWidth()
 
+" Fix NERDTree width on all tabs
+function FixAllNERDTreeWidths()
+  " Save the last active window
+  let l:current_win = win_getid()
+
+  tabdo :call FixNERDTreeWidth()
+
+  " Restore the active window
+  call win_gotoid(l:current_win)
+
+  " An additional, last move to the left pane
+  wincmd l
+endfunction
+
 " Fix all NERDTree widths afert session load
 augroup workaround
   autocmd!
-  autocmd workaround SessionLoadPost * tabdo call FixNERDTreeWidth()
+  " This tends to fire for every buffers
+  "autocmd workaround SessionLoadPost * call FixAllNERDTreeWidths()
+
+  " This seems to fire only once
+  autocmd workaround VimEnter * call FixAllNERDTreeWidths()
 augroup END