Normally when quickfix window opens it changes the screen layout, but Vim restores
it when that window is closed.
But there is a situation where the layout restoration fails: when the
preview window is open, vertical splits are presents and :wincmd J is executed
in quickfix (or it is opened with :botright copen). In this case the size of
preview window is changed.
I came with a solution which I placed on ~/.vim/ftplugin/qf.vim,
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
" expand quickfix when there are vertical splits
wincmd J
func! RestorePreviewWindow()
let l:quickfixHeight = winheight(0)
wincmd p " include previous window on jump list
silent! wincmd P " jump to preview window
if &previewwindow " if we really get there...
exe "resize " . (&previewheight - l:quickfixHeight - 1)
wincmd p " back to old window
endif
endfunc
augroup quickfixClosing
au!
au BufDelete <buffer> call RestorePreviewWindow()
augroup END
, but I was wondering if there is some better/simpler solutions to this
problem.
If you can reproduce the problem in plain vanilla Vim (
vim -N -u NONE), I’d report it to the vim_dev mailing list to have it fixed inside Vim. The preview window should not change its size when other, normal windows could stand in for it.If this is just a peculiarity of your setup, I think your implemented workaround is fine; I would probably solve it along the same lines.