首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在vimdiff中的垂直拆分和水平拆分之间切换?

如何在vimdiff中的垂直拆分和水平拆分之间切换?
EN

Stack Overflow用户
提问于 2011-04-15 22:00:14
回答 2查看 25.2K关注 0票数 56

I already know如何使用diffopt变量启动具有水平/垂直拆分的diff模式,但不是在我已经打开两个文件进行比较时如何在两者之间切换。

我尝试了在this older post中找到的公认答案,但无济于事。Ctrl+W命令对我不起作用。也许是因为我在Windows友好模式下运行gVim?

EN

回答 2

Stack Overflow用户

发布于 2018-05-17 14:52:46

我来晚了,但也许这是一个有趣的解决方案。@PeterRincker的解决方案只有在你只打开了几个窗口而没有内部窗口的情况下才有效。

我在我的运行时配置中发现了这个(有用的)函数,我想和你分享。它的目的是映射为键绑定,让用户将当前的拆分切换到指定的拆分。标记它不会在垂直和水平之间切换,但用户会告诉他喜欢哪一个(如果这个场景没有意义,也可能是当前活动的)。Vim窗口树总是有两个窗口作为“合作伙伴”。在调整窗口大小时,也可以观察到这种影响。我想说的是:如果应用于当前活动窗口及其“伙伴”窗口,则触发函数。

代码语言:javascript
运行
AI代码解释
复制
" 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>

不幸的是,它目前仍然改变窗口的大小,而不是保持形状不变。我正在努力,但实现起来并不容易,因为我必须知道“合作伙伴”窗口的形状。

票数 0
EN

Stack Overflow用户

发布于 2016-10-17 21:26:53

也可以按住ctrl-w + <arrow key>来选择窗口。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5682759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档