正常情况下,当快速修复窗口打开时,它会更改屏幕布局,但是当该窗口关闭时,Vim会恢复它。但是在某些情况下,布局恢复会失败:当预览窗口打开时,存在垂直分割并且在快速修复中执行了
:wincmd J
(或者使用:botright copen
打开),此时预览窗口的大小会发生变化。我提出了一个解决方案,将其放在了~/.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
但我想知道是否有更好/更简单的解决方案来解决这个问题。
wincmd P
,这很有用。我真的很喜欢预览窗口的想法,但是不同的调整大小行为使其难以使用 - 我在 tmux 中工作并经常缩放窗格。使用<C-w>=
可以解决普通窗口的问题,但不会影响特殊窗口。也许可以利用这个来改进!谢谢。 - JonnyRaa