我已经知道如何使用
diffopt
变量启动水平/垂直分割的差异模式,但不知道当我已经打开两个文件进行比较时如何在两者之间切换。
我尝试了这篇旧文章中找到的已接受答案,但无济于事。 Ctrl+W 命令对我不起作用。也许是因为我在 Windows 友好模式下运行 gVim?
以下命令会将垂直分割更改为水平分割:
ctrl+w,然后shift+j
要改回垂直分割,请使用:
有关移动窗口的更多信息:
:h window-moving
:h ctrl-w_J
:h ctrl-w_K
:h ctrl-w_H
:h ctrl-w_L
我迟到了,但也许这是一个有趣的解决方案。 @PeterRincker 的解决方案仅在您只打开几个窗口而没有内部窗口的情况下才有效。
我在我的运行时配置中发现了这个(有用的)函数,我想与你分享。它旨在映射为键绑定并让用户将当前拆分切换到指定的拆分。标记它不会在垂直和水平之间切换,但用户会告诉他喜欢哪一个(也可能是当前活动的,如果这种情况没有意义的话。) Vim 窗口树总是有两个窗口,如“伙伴”。调整窗口大小时也可以观察到这种效果。我想说的是:如果适用于当前活动窗口及其“伙伴”窗口,则触发该功能。
" Switch to a vertical or horizontal split between two windows.
" Switching to currently used split results into the equal split.
" This is between the current window and the one window which is focused, when close the active window.
" This function does not adjust the windows height after the switch, cause this can't work correctly.
"
" Arguments:
" horizontal - Boolean to differ between both layouts.
"
function! s:switch_window_split(horizontal) abort
let l:bufnr = bufnr('%') " Get current buffer number to restore it in the new window.
if a:horizontal | let l:vert = '' | else | let l:vert = 'vert ' | endif
" Close current window and open new split with the cached buffer number.
wincmd c
execute l:vert . 'sbuffer ' . l:bufnr
endfunction
" Switch split layout.
nnoremap <leader>wS :<C-u>call <SID>switch_window_split(v:true)<CR>
nnoremap <leader>wV :<C-u>call <SID>switch_window_split(v:false)<CR>
不幸的是,它目前仍然会改变窗口的大小,并且不会保持原来的形状。我正在努力,但实现起来并不容易,因为我必须知道“合作伙伴”窗口的形状。
您也可以通过
ctrl-w
+ <arrow key>
选择窗口。