mMontu
mMontu

Reputation: 9273

Quickfix & Preview window resizing

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.

Upvotes: 4

Views: 2564

Answers (3)

JonnyRaa
JonnyRaa

Reputation: 8038

I used your answer to improve the default auto resize behaviour of vim.

It's not really an answer to this question but hopefully other people might find it useful as I stumbled across this question for that reason:

nmap <silent> <C-w>= :call ResizeAllWindows()<cr>

function! ResizeAllWindows()
  call RestorePreviewWindowHeight()
  wincmd = "set all equal after restore
endfunction

function! RestorePreviewWindowHeight()
  silent! wincmd P "jump to preview, but don't show error
  if &previewwindow
    exec "resize" &previewheight
    wincmd p "jump back
  endif
endfunction

Upvotes: 0

MaikoID
MaikoID

Reputation: 4997

I was with this problem and I've tried your proposed qf.vim but it didn't work. I found something that did, in the qf help page, =|, so put this in your .vimrc:

au FileType qf botright cwindow

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172580

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.

Upvotes: 2

Related Questions