I was playing around with the MiniBufExplorer plugin, and I thought it would be nice if the MBE window could stick to the bottom of my ViM screen, even if I specifically open a new window with e.g.
:bot split xyz. If I can get that working, then as a bonus I can set laststatus=0 when the MBE window is active, because having a statusline on it doesn't really accomplish anything. I already have an autocmd that customizes my statusline that I could piggyback off of, so at first I thought I could make a quick tweak to that function like so:
function! s:RefreshStatus() let l:mbe = 2 for nr in range(1, winnr('$')) if '-MiniBufExplorer-' == expand('%') let l:mbe = 0 wincmd J else call setwinvar(nr, '&statusline', '%!Status(' . nr . ')') endif endfor call setwinvar (0, '&laststatus', l:mbe) endfunction
Oops, of course that didn't work. I'm not actually jumping through the buffers to set the status line, so
wincmd J don't actually behave correctly. So my biggest question is, how do I execute
wincmd J in window #nr?
I found the
bufname() function, which solves the problem of correctly identifying the MBE window, but I'd still like to be able to move the window to the bottom when something has snuck in under it.
EDIT 2: MiniBufExplorer seems to have some logic for window positioning built in that interferes with what I am attempting to accomplish, even when using noautocmd. Here's the function I ended up with, following Ingo's answer:
function! FixMBE() " Now a separate function let l:mbenr = 0 for nr in range(1, winnr('$')) if '-MiniBufExplorer-' == bufname(nr) call setwinvar(nr, '&statusline', '') let l:mbenr = nr endif endfor if l:mbenr set laststatus=0 let l:active = winnr() try exe 'noautocmd ' . l:mbenr . 'wincmd w' wincmd J if l:active > l:mbenr let l:active = l:active -1 " window numbers will change after we move MBE endif finally exe 'noautocmd ' . l:active . 'wincmd w' endtry else set laststatus=2 endif endfunction
It mostly works with horizontal splits, but goes badly belly up when vertical splits are added to the mix. However, if I disable the MBE plugin and create a normal window with that name, this script behaves exactly as expected.