How do I toggle between a Vertical and a Horizontal split in vimdiff?

 ̄綄美尐妖づ 提交于 2019-12-20 09:46:33

问题


I already know how to use the diffopt variable to start diff mode with horizontal/vertical splits but not how to toggle between the two when I already have two files open for comparison.

I tried the accepted answer found in this older post, but to no avail. The Ctrl+W commands didn't work for me. Perhaps because I'm running gVim in Windows-friendly mode?


回答1:


The following command will change a vertical split into a horizontal split:

ctrl+w then J

To change back to a vertical split use either:

ctrl+w H or ctrl+w L

For more information about moving windows:

:h window-moving
:h ctrl-w_J
:h ctrl-w_K
:h ctrl-w_H
:h ctrl-w_L



回答2:


You can also do ctrl-w + <arrow key> to select the window.




回答3:


I'm rly late, but maybe this is an interesting solution. The solution by @PeterRincker only works if u have just a few windows open without inner windows.
I found this (useful) function in my runtime configuration I like to share with u. It is meant to be mapped as keybinding and let the user switch the current split to a specified one. Mark that it does not toggle between vertical and horizontal, but the user tell which one he likes (Could be currently active one too, also if this scenario doesn't make sense.) The Vim window tree always have two windows as "partners". Effects of this are also observable when resizing windows. What I want to say: Trigger the function, if applies to the currently active window and its "partner" window.

" 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>

Unfortunately it currently still change the size of the window and don't leave the shape as it is. I'm working on it, but it isn't that easy to achive, cause I have to know the shape of the "partner" window.



来源:https://stackoverflow.com/questions/5682759/how-do-i-toggle-between-a-vertical-and-a-horizontal-split-in-vimdiff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!