nerdtree
nerdtree copied to clipboard
Zoom (key: A) with vertical split windows: When minimizing the NERDTree window, split windows not resized correctly
Environment
- Operating System: Red Hat Enterprise Linux release 8.2 (Ootpa)
- Vim/Neovim version
:version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug 19 2021 13:59:56) - NERDTree version, found on first line of quickhelp
?: 6.10.16 - Are you using any of these NERDTree-dependent plugins?
- [ ] Xuyuanp/nerdtree-git-plugin
- [ ] ryanoasis/vim-devicons
- [ ] tiagofumo/vim-nerdtree-syntax-highlight
- [ ] scrooloose/nerdtree-project-plugin
- [ ] PhilRunninger/nerdtree-buffer-ops
- [ ] PhilRunninger/nerdtree-visual-selection
- [ ] jistr/vim-nerdtree-tabs
- [ ] Others (specify):
- Provide a minimal .vimrc file that will reproduce the issue.
" 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
- Open any file in vim
- Open a second file in a vertical split window
- Open NERDTree with
:NERDTree - Press
Ato Zoom (maximize NERDTree) - Press
Aagain (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.
All windows are resized, either back to previous sizes or at least equally split.
This can be done by setting equalalways
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).
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.
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 resizeon 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 theNERDTreebut 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
winfixwidthis on by default for theNERDTreebuffer, preventing split equalization with<C-w>=. However, this can be solved by simply:- Unsetting
winfixwidth - equalizing the panes
- Restoring
winfixwidth - Resizing
NERDTreetog:NERDTreeWinSizeas usual.
- Unsetting
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