我曾经使用ZoomWin:https://github.com/vim-scripts/ZoomWin在Vim中的一个和多个窗口之间切换。但这个插件有一个大问题。当我试图恢复多个窗口(垂直分割)时,延迟大约2-4秒。
你知道如何避免这种滞后吗?或者也许是更好的解决方案。
第25版解决了问题:https://github.com/regedarek/ZoomWin
答案 0 :(得分:59)
我尝试使用没有任何插件的vim,因为当我在另一个系统上工作时我不想依赖它们。现在谈到同样的问题,我可以根据OP的要求提出一些“更好的方法”(替代方式):
c-w-|
让窗口接管(如果使用vsplits)。 c-w-=
要恢复。水平分割的c-w-_
tmux
(如果可用)并运行多个vim实例c-b-z
以在当前窗格的全屏之间切换我按照我的实用性顺序列出了这些。使用专用插件时,体验当然会更好,但这并不总是一种选择。
答案 1 :(得分:32)
A simple alternative(根据您的需要可能就足够了):
" Zoom / Restore window.
function! s:ZoomToggle() abort
if exists('t:zoomed') && t:zoomed
execute t:zoom_winrestcmd
let t:zoomed = 0
else
let t:zoom_winrestcmd = winrestcmd()
resize
vertical resize
let t:zoomed = 1
endif
endfunction
command! ZoomToggle call s:ZoomToggle()
nnoremap <silent> <C-A> :ZoomToggle<CR>
答案 2 :(得分:13)
ZoomWin版本24引入了窗口局部变量的保存。当我试用它时,我发现性能是不可接受的,可能是因为我安装了各种其他插件并安装了各种事件处理程序。
我已向插件作者报告了我的问题,他回答说
ZoomWin的v25a有g:zoomwin_localoptlist和noautocmd东西。
所以,要么尝试恢复到版本23(我做了),要么尝试从http://drchip.org/astronaut/vim/index.html#ZOOMWIN关闭上述设置的最新版本
答案 3 :(得分:5)
另一种简单的方法是:tab split
。好处是它不会改变当前选项卡的布局。缺点是它需要Vim 7.0或更高版本才能支持标签。
nnoremap <leader>t :call TabToggle()<cr>
function! TabToggle()
if tabpagewinnr(tabpagenr(), '$') > 1
" Zoom in when this tab has more than one window
tab split
elseif tabpagenr('$') > 1
" Zoom out when this tab is not the last tab
if tabpagenr() < tabpagenr('$')
tabclose
tabprevious
else
tabclose
endif
endif
endfunction
答案 4 :(得分:2)
我有多年使用的另一种方法;允许我将当前缓冲区“缩放”到一个新的选项卡,然后再次快速将其关闭,以便回到原来的多窗口布局:
" "Zoom" a split window into a tab and/or close it
nmap <Leader>,zo :tabnew %<CR>
nmap <Leader>,zc :tabclose<CR>
答案 5 :(得分:0)
我写了一个与BenC的版本非常相似的版本(以前从未见过,因此值得一笑)
我认为,唯一的区别是如果要移到同一选项卡中的另一个窗口,则autocmd可以恢复布局,因此它会产生“自动缩放”效果:
function! ToggleZoom(toggle)
if exists("t:restore_zoom") && (t:restore_zoom.win != winnr() || a:toggle == v:true)
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:toggle
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
vert resize | resize
endi
endfunction
nnoremap <silent> <Leader>+ :call ToggleZoom(v:true)<CR>
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END