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 file
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 wS :call switch_window_split(v:true)
nnoremap wV :call switch_window_split(v:false)
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.