From bbc8784ecd0adae6acb092ba22cbb835ec80193a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 28 Jul 2024 11:40:22 -0300 Subject: Fix: rename nerdtree_workarounds plugin to session_workarounds --- vim.dot.link/plugin/nerdtree_workarounds.vim | 92 --------------------------- vim.dot.link/plugin/session_workarounds.vim | 93 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 92 deletions(-) delete mode 100644 vim.dot.link/plugin/nerdtree_workarounds.vim create mode 100644 vim.dot.link/plugin/session_workarounds.vim diff --git a/vim.dot.link/plugin/nerdtree_workarounds.vim b/vim.dot.link/plugin/nerdtree_workarounds.vim deleted file mode 100644 index 60e4a1c..0000000 --- a/vim.dot.link/plugin/nerdtree_workarounds.vim +++ /dev/null @@ -1,92 +0,0 @@ -" nedtree_workaroungs.vim - NERDTree and session restoration workarounds -" -" Author: Silvio Rhatto -" - -" 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 NERDTree width on all tabs -function FixAllNERDTreeWidths() - " Make sure to run this only once - if exists("did_fixed_nerdtree_widths") - return - endif - - " 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 - - let dir_fixed_nerdtree_widths=1 -endfunction - -" 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). -" -" We just want to quickly maximize the window and then restore it to -" it's original size, to ensure all windows are refreshed. -" -" Maybe this is not a NERDTree workaround itself, but more like a -" session workaround. -" -" https://superuser.com/questions/140419/how-to-start-gvim-maximized -" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size -"let lines_initial=&l:lines -function FixWindowHeights() - " Set the maximum available height - set lines=999 - - " Set the lines depending on the LINES environment variable - " or through tput. - if $LINES != "" - execute ':set lines=' . $LINES - else - let available_lines = system('tput lines') - execute ':set lines=' . available_lines - " Old, and not working approach that tries to reuse the initial height - "else - " execute ':set lines=' . lines_initial - " set lines=999 - " execute ':set lines=' . winheight(0) - 3 - endif -endfunction - -function RestoreWindowSizes() - call FixWindowHeights() - call FixAllNERDTreeWidths() -endfunction - -" Fix all window sizes -augroup workaround - autocmd! - " This tends to fire for every buffer - autocmd workaround SessionLoadPost * call RestoreWindowSizes() - - " This seems to fire only once, but even when there's no session to be - " restored. - "autocmd workaround VimEnter * call FixAllNERDTreeWidths() -augroup END diff --git a/vim.dot.link/plugin/session_workarounds.vim b/vim.dot.link/plugin/session_workarounds.vim new file mode 100644 index 0000000..be51942 --- /dev/null +++ b/vim.dot.link/plugin/session_workarounds.vim @@ -0,0 +1,93 @@ +" session_workarounds.vim - Session restoration workarounds +" +" Author: Silvio Rhatto +" + +" Fix NERDTree width +" +" Useful after restoring sessions between screen size changes (such +" as when you share sessions between different computers). +function FixWindowWidths() + " Make sure NERDTree is focused + execute ":NERDTreeFocus" + + " Set a fixed width + execute ":vertical resize 30" + + " Move to the left pane + wincmd l +endfunction + +" In case you want to invoke FixWindowWidths explicitly +command! -bang FixWindowWidths :call FixWindowWidths() + +" Fix window widths on all tabs +function FixAllWindowWidths() + " Make sure to run this only once + if exists("did_fixed_nerdtree_widths") + return + endif + + " Save the last active window + let l:current_win = win_getid() + + tabdo :call FixWindowWidths() + + " Restore the active window + call win_gotoid(l:current_win) + + " An additional, last move to the left pane + wincmd l + + let dir_fixed_nerdtree_widths=1 +endfunction + +" 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). +" +" We just want to quickly maximize the window and then restore it to +" it's original size, to ensure all windows are refreshed. +" +" Maybe this is not a NERDTree workaround itself, but more like a +" session workaround. +" +" https://superuser.com/questions/140419/how-to-start-gvim-maximized +" https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size +"let lines_initial=&l:lines +function FixWindowHeights() + " Set the maximum available height + set lines=999 + + " Set the lines depending on the LINES environment variable + " or through tput. + if $LINES != "" + execute ':set lines=' . $LINES + else + let available_lines = system('tput lines') + execute ':set lines=' . available_lines + " Old, and not working approach that tries to reuse the initial height + "else + " execute ':set lines=' . lines_initial + " set lines=999 + " execute ':set lines=' . winheight(0) - 3 + endif +endfunction + +" Restore all window sizes +function RestoreWindowSizes() + call FixWindowHeights() + call FixAllWindowWidths() +endfunction + +" Fix all window sizes +augroup workaround + autocmd! + " This tends to fire for every buffer + autocmd workaround SessionLoadPost * call RestoreWindowSizes() + + " This seems to fire only once, but even when there's no session to be + " restored. + "autocmd workaround VimEnter * call FixAllWindowWidths() +augroup END -- cgit v1.2.3