Search code examples
vimnerdtree

Programmatically change NERDTreeWinSize


I like to change the vim-plugin NERDTreeWinSize variable programmatically.

I added the following function to my vimrc but nothing is happening when I call the function. Any hints?

fun! NerdTreeWinSize( arg )
  let g:NERDTreeWinSize=a:arg
endfunction
command! -nargs=* Ntws call NerdTreeWinSize( '<args>' )

I can call the function via :Ntws 200 and wish that the NERDTreeWinSize changes to 200 then.

I also realized that nothing is happening when i run let g:NERDTreeWinSize=100 in the vim command line.

But when I add the line let g:NERDTreeWinSize=100 to my vimrc vim adapts the NERDTreeWinSize.


Solution

  • Your code is correct, and (at least my version of NERDTree) re-evaluates the g:NERDTreeWinSize variable when building its UI. However, the change does not affect open NERDTree windows, only new ones. So, you need to re-open NERDTree for the changes to take effect, maybe via

    command! -nargs=* Ntws call NerdTreeWinSize( '<args>' ) | NERDTree