Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
8 tasks
kahn-jms opened this issue Mar 24, 2022 · 4 comments · Fixed by #1395
Labels

Comments

@kahn-jms
Copy link

kahn-jms commented Mar 24, 2022

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 kahn-jms added the bug label Mar 24, 2022
@mark2185
Copy link

mark2185 commented Mar 30, 2022

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

This can be done by setting equalalways

@kahn-jms
Copy link
Author

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).

@ds2606
Copy link
Contributor

ds2606 commented Apr 12, 2022

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
Copy link
Contributor

ds2606 commented Apr 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants