How to determine window position in vim

I am trying to configure mappings for vimdiff and make them look like winmerge

In a vertical split in 2 directions, I want to display alt-left <a-left>to move the current diff to the left and alt-right <a-right>to move the current diff to the right.

I can use :diffgand to merge :diffp. But I need to know what kind of split I am in it, so that I can use :diffg/:diffpit.

Is there a way by which I can determine in which split I am entering. In particular, is there any way by which I can find out if the cursor is in the left split or in the right split

Related Question how-to-get-list-of-files-which-are-currently-being-diffed-in-vim

+1
source share
2 answers

Assuming that there are only two windows, the function winnr()will return 1for the first window and 2for the second window. You can also use winnr('$')to find out how many windows there: :echo winnr('$').

You can also just use dpand do, then you do not need to go to different windows many times, and this is easier than the arrow keys.

+1
source

Not the answer to your specific question, but here are some useful settings that may help.

"" Diff options; ignore whitespace.
set diffopt+=iwhite

I don't like: diffon: diffoff, because they fight with word wrap (turns it on when you exit diff). Therefore, I install only diff, scrollbind, foldmarker and foldcolumn.

"" Diff 'd' {{{
    nmap <silent> ,dd :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,dD :windo :set diff scb fdm=diff fdc=2<CR>
    nmap <silent> ,do :set nodiff noscb fdm=manual fdc=0<CR>
    nmap <silent> ,dO :windo :set nodiff noscb fdm=manual fdc=0<CR>
    "nmap <silent> ,dd :diffthis<CR>
    "nmap <silent> ,dD :windo :diffthis<CR>
    "nmap <silent> ,do :diffoff<CR>
    "nmap <silent> ,dO :windo :diffoff<CR>
    nmap <silent> ,du :diffupdate<CR>
"" }}}

, DirDiff , ...

+1

Source: https://habr.com/ru/post/1737889/


All Articles