vim-nerdtree-tabs icon indicating copy to clipboard operation
vim-nerdtree-tabs copied to clipboard

Remember width of the NERDTree window

Open EinfachToll opened this issue 13 years ago • 4 comments
trafficstars

Currently, if you change the width of the NERDTree in one tab (and I do that regularly), the width in every other tab remains the old value. I find this quite annoying and confusing since it breaks the illusion of having the identical NERDTree in every tab.

The solution is really easy, it's just 3 lines of code (plus comments). I didn't want to make a pull request, so here is the diff:

235a236,237
>       " save NERDTree window width
>       let s:nerdtree_width = winwidth(0)
242c244
<   if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1 && exists('s:nerdtree_view')

---
>   if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1 && exists('s:nerdtree_view') && exists('s:nerdtree_width')
253c255
<     " restore cursor and scroll

---
>     " restore cursor, scroll, and window width
254a257
>       exe "vertical resize " . s:nerdtree_width

EinfachToll avatar Jul 17 '12 08:07 EinfachToll

Hi, this looks useful, thanks :) I hope to dive into this shortly.

jistr avatar Jul 17 '12 19:07 jistr

Released in v1.4.0. Thanks.

jistr avatar Sep 01 '12 22:09 jistr

I think the following works more accurately:


fun! s:SaveNERDTreeViewIfPossible()
  if exists("t:NERDTreeBufName")
    if  bufwinnr(t:NERDTreeBufName) == winnr()
      " save scroll and cursor etc.
      let s:nerdtree_view = winsaveview()

      " save buffer name (to be able to correct desync by commands spawning
      " a new NERDTree instance)
      let s:nerdtree_buffer = bufname("%")
    endif
    " Save NERDTree window width even if not the current window.
    " The user may resize even when not focused in the NERDTree side window,
    " then cause a WinLeave from that non-NERDTree window.
    let s:nerdtree_width = winwidth(bufwinnr(t:NERDTreeBufName))
  endif
endfun


I noticed an issue with what's in the latest version, where resizing using the mouse before jumping to a new tab would not record the width unless you were focused in the NERDTree. Does this snippet look correct to you?

jordwalke avatar Sep 04 '12 07:09 jordwalke

Reopening.

jistr avatar Sep 04 '12 12:09 jistr