How I can make a window automatically visible on all tabs ? Like NerdTree-tabs plugin:

Aba 1
Aba 2
Aba 3
>   readme.md
  • 2
    You read the plugin's source and use the same method.
    – romainl
    Mar 19, 2016 at 10:27

1 Answer 1


First, @romainl's comment is a really good advice: you'll learn a lot by reading a real plugin code and trying to understand its behavior.

Now if you're new to vimscript and coding, it can be pretty hard. So here is a solution. (It is probably more simple and maybe not as efficient as NERDTree way to do it but it should work properly)

Add this to your .vimrc:

let g:windowToKeep=[]

nnoremap <F2> :call SetWindowToKeep()<CR>
nnoremap <F4> :call OpenTab()<CR>

function! SetWindowToKeep()
    let g:windowToKeep = [expand("%:p"), winheight(0), winwidth(0)]

function! OpenTab()
    execute "tabedit " . g:windowToKeep[0]
    execute "vsplit"
    execute "resize " . g:windowToKeep[1]
    execute "vertical resize " . g:windowToKeep[2]

The idea behind this code is that "make a window visible on all tabs" is actually doing the following:

  • Selecting a windows containing a buffer as the one you want to keep
  • Then each time a new tab is created, it is splited to contain:
    • The selected window with the same buffer and the same size
    • Another window containing a new buffer

To do so, this code will create a variable g:windowToKeep which will contain the window that you want to keep.

To set this variable a mapping is done on F2: you'll have to press this key to set the window to keep on your tabs.

Then you can call the function OpenTab() either with ex mode or by pressing F4. This function creates a new tab with a buffer you want to keep, split the tab and resize the window containing your buffer.

Note 1 You can (of course) replace <F2> and <F4> by your favorite mappings.

Note 2 It is possible that the function isn't exactly what you expected because your workflow can be a little different than what I imagined while creating the code. As it's a pretty simple code you should be able to tweak it to fit your needs more closely.

  • Maybe the variable you are referring to is g:windowToKee, not g:bufferToKeep. Mar 19, 2016 at 19:09
  • @JairLopez: Obviously that was a typo, thanks for pointing it to me I edited the answer.
    – statox
    Mar 19, 2016 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.