aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-07-28 01:33:23 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-07-28 01:33:23 -0300
commite9f116c6bcf8683a5aacb419b8283c7c95584f6a (patch)
treed25c2db021e6ddc9a271fa2dc0be3b2fa007136b
parentbec1a732f9db269f93419ecb4e9ca247b1a188a9 (diff)
downloadvim-e9f116c6bcf8683a5aacb419b8283c7c95584f6a.tar.gz
vim-e9f116c6bcf8683a5aacb419b8283c7c95584f6a.tar.bz2
Fix: NERDTree and session restoration workarounds
-rw-r--r--vimrc.dot.link39
1 files changed, 38 insertions, 1 deletions
diff --git a/vimrc.dot.link b/vimrc.dot.link
index 4179a91..d7389dc 100644
--- a/vimrc.dot.link
+++ b/vimrc.dot.link
@@ -423,10 +423,47 @@ let g:session_autosave='yes'
let g:session_autoload='no'
let g:session_directory='~/.local/share/vim/sessions'
-" Don't save hidden and unloaded buffers in sessions.
+" Session options
" https://github.com/xolox/vim-session?tab=readme-ov-file#options
set sessionoptions-=buffers
+set sessionoptions-=blank
+set sessionoptions-=resize
+set sessionoptions-=winsize
+set sessionoptions-=winpos
" Autosave
" See https://github.com/vim-scripts/vim-auto-save
"let g:auto_save = 1
+
+" Ensure the window has maximized height
+"
+" This helps restoring the window size after reopening sessions after
+" switching monitors (like from laptop screen to external HDMI monitor).
+"
+" https://superuser.com/questions/140419/how-to-start-gvim-maximized
+" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size
+set lines=999
+
+" Fix NERDTree width
+"
+" Useful after restoring sessions between screen size changes (such
+" as when you share sessions between different computers).
+function FixNERDTreeWidth()
+ " Make sure NERDTree is focuses
+ execute ":NERDTreeFocus"
+
+ " Set a fixed width
+ execute ":vertical resize 30"
+
+ " Move to the left pane
+ wincmd l
+endfunction
+
+" In case you want to invoke FixNERDTreeWidth explicitly
+command! -bang FixNERDTreeWidth :call FixNERDTreeWidth()
+
+" Fix all NERDTree widths afert session load
+augroup workaround
+ autocmd!
+ autocmd workaround SessionLoadPost * tabdo call FixNERDTreeWidth()
+augroup END