我已经知道如何使用diffopt
变量以水平/垂直分割开始diff模式,但当我已经打开两个文件进行比较时,不知道如何在两者之间切换。
我尝试了在这个旧帖子中找到的公认答案,但无济于事。Ctrl+W命令对我不起作用。也许是因为我在windows友好模式下运行gVim ?
下面的命令将垂直分割改为水平分割:
ctrl + w , J
若要更改为垂直分割,请使用:
ctrl + w H 或 ctrl + w L
有关移动窗口的更多信息:
:h window-moving
:h ctrl-w_J
:h ctrl-w_K
:h ctrl-w_H
:h ctrl-w_L
我迟到了,但也许这是一个有趣的解决方案。@PeterRincker的解决方案只适用于如果你只有几个窗口打开没有内部窗口。
我在我的运行时配置中发现了这个(有用的)函数,我喜欢与u分享。它意味着被映射为键绑定,并让用户将当前分割切换到指定的一个。注意,它不会在垂直和水平之间切换,而是用户告诉他喜欢哪一个(如果这个场景没有意义,也可以是当前活动的一个)。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>
来选择窗口