nerdtree icon indicating copy to clipboard operation
nerdtree copied to clipboard

Zoom (key: A) with vertical split windows: When minimizing the NERDTree window, split windows not resized correctly

Open kahn-jms opened this issue 3 years ago • 4 comments

Environment

" Occurs with minimal NERDTree install, i.e.
set nocompatible              " be iMproved, required
filetype off                  " required
" set the runtime path to include Vundle and initialize
set rtp+=path/to//Vundle.vim
call vundle#begin()

Plugin 'preservim/nerdtree'

" All of your Plugins must be added before the following line
call vundle#end()            " required

Steps to Reproduce the Issue

  1. Open any file in vim
  2. Open a second file in a vertical split window
  3. Open NERDTree with :NERDTree
  4. Press A to Zoom (maximize NERDTree)
  5. Press A again (minimize NERDTree)

Current Behavior (Include screenshots where appropriate.)

When minimizing NERDTree, only the leftmost window is resized to occupy the entire window and all other split windows are left minimized.

Expected Result

All windows are resized, either back to previous sizes or at least equally split.

kahn-jms avatar Mar 24 '22 23:03 kahn-jms

All windows are resized, either back to previous sizes or at least equally split.

This can be done by setting equalalways

mark2185 avatar Mar 30 '22 05:03 mark2185

All windows are resized, either back to previous sizes or at least equally split.

This can be done by setting equalalways

Thank you for the response. Unfortunately setting this in .vimrc doesn't resolve this as it only applies after splitting or closing a window. The A (zoom) of NERDTree is simply resizing the NERDTree browser to occupy the entire screen (when maximising) and back to it's normal width (when minimising).

kahn-jms avatar Mar 31 '22 10:03 kahn-jms

Yeah I'm having issues with vertical splits with A too and was able to verify the behavior you're describing. Interestingly, after using NERDTree A, the <C-w>= command to evenly resize splits fails to adjust vertical splits to even width. I'll see if I can dig in and see what's going on.

ds2606 avatar Apr 12 '22 02:04 ds2606

Hey so I figured out that this issue is in lib/nerdtree/ui.vim, in the function UI.toggleZoom().

Problem:

  • During the zoom-ing, the function simply calls vertical resize on the window, which by default maximizes the window to the greatest possible vertical width (squishing all other vertical splits to zero-width)
  • During the unzooming, the function simply calls vertical resize g:NERDTreeWinSize, which restores the NERDTree but doesn't specify what to do for the other splits. In the case you're describing, the split with the lowest window number is by default getting all of the available leftover window space.

Solution:

  • Simply equalize split widths during un-zooming. This is made a little more complicated by the fact that winfixwidth is on by default for the NERDTree buffer, preventing split equalization with <C-w>=. However, this can be solved by simply:
    • Unsetting winfixwidth
    • equalizing the panes
    • Restoring winfixwidth
    • Resizing NERDTree to g:NERDTreeWinSize as usual.

This patch fixes the issue for me:

diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim
index a481ba4..d8b60c6 100644
--- a/lib/nerdtree/ui.vim
+++ b/lib/nerdtree/ui.vim
@@ -516,6 +516,9 @@ endfunction
 " zoom (maximize/minimize) the NERDTree window
 function! s:UI.toggleZoom()
     if exists('b:NERDTreeZoomed') && b:NERDTreeZoomed
+        setlocal nowinfixwidth
+        exe "norm! \<C-w>="
+        setlocal winfixwidth
         call nerdtree#exec('silent vertical resize '. g:NERDTreeWinSize, 1)
         let b:NERDTreeZoomed = 0
     else

I only wish I didn't need to invoke "norm!", but it doesn't seem that there's any associated Ex command for the <C-w>= binding.

I'll submit a PR and folks can share suggestions.

EDIT: Addressed in #1308

ds2606 avatar Apr 12 '22 03:04 ds2606