Search code examples
vimwinmerge

How to detect the position of window in vim


I am trying to customize the mappings for vimdiff and make them similar to winmerge

In a vertical 2 way split, I want to map alt-left <a-left> to move current diff to left side and alt-right <a-right> to move current diff to right side.

For merging i can use :diffg and :diffp. But I need to know which split i am in so that i can use :diffg/:diffp in that.

Is there any way by which i can detect which split i am in. Specifically is there is any way by which i can know whether the cursor is in left split or right split

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


Solution

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

    You can also just use dp and do, then you don't need to jump betweem windows as much, and it's easier to reach than the arrow keys.