我曾经使用ZoomWin:https://github.com/vim-scripts/ZoomWin切换Vim中的单窗口和多窗口。但是这个插件有一个大问题。当我尝试恢复多个窗口(竖直分割)时,会有约2-4秒的延迟。
你知道如何避免这种延迟吗?或者可能有更好的解决方案。
第25版已解决此问题:https://github.com/regedarek/ZoomWin
我曾经使用ZoomWin:https://github.com/vim-scripts/ZoomWin切换Vim中的单窗口和多窗口。但是这个插件有一个大问题。当我尝试恢复多个窗口(竖直分割)时,会有约2-4秒的延迟。
你知道如何避免这种延迟吗?或者可能有更好的解决方案。
第25版已解决此问题:https://github.com/regedarek/ZoomWin
我尝试在不使用任何插件的情况下使用vim,因为我不想在另一个系统上工作时依赖它们。现在遇到相同的问题,我可以提出一些“更好的方法”(替代方法),如请求者所要求:
c-w-|
可以使窗口占满整个屏幕(如果使用vsplits)。c-w-=
可以还原窗口。 c-w-_
可以进行水平分割。tmux
并运行多个实例的vim。 c-b-z
可以在当前窗格之间切换全屏模式。我按照实用性给这些列了一个顺序。当然,使用专用插件会更好,但这并不总是可行的选择。
一个简单的替代方案(根据您的需求可能已经足够):
" 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>
<Leader><Leader>
,因为我将<C-A>
用于tmux;-) - BenC我还有另一种多年来一直在使用的方法;它允许我将当前缓冲区“缩放”到一个新标签页中,然后快速关闭它,以便我可以回到我的原始多窗口布局:
" "Zoom" a split window into a tab and/or close it
nmap <Leader>,zo :tabnew %<CR>
nmap <Leader>,zc :tabclose<CR>
另一种简单的方法是: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
Ctrl+w s
将分割窗口复制到一个新缓冲区,然后使用 Ctrl+w T
将其拆分为一个新选项卡。完成后,只需关闭新选项卡,原始布局将恢复。 - user1717828我写了一个与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