I've been trying to find out how the get the position/coordinates of a splitt window inside a vim editor window, but no luck so far.
Say for example I have this layout
(0,0) (2, 0)
\____________/____________
| | |
| Split A | Split C |
(0,2)-+------------+----------+
| Split B | Split D |
|____________|__________| #Split D would be (2, 2)
I want to get the coordinates of the different splits on of my Vim Window, is this possible?
I've done my homework and googled this, also went through the vim :help
/:helpgrep
Things that I've tried that wouldn't work:
getwinposx()
/getwinposy()
: They doesn't work on terminal, and they don't actually return the info I want, it just returns the position of the Host OS window.
:winpos
: the same reason as the previous bullet.
I do not know a function that will do this, but here are some facts:
winwidth(wnr)
and winheight(wnr)
.winnr('$')
.0<wnr≤winnr('$')
, then window with number wnr
exists.&columns
and total height is &lines
.In order to get window layout you lack only one fact here: how windows are numbered. I can't find this in help now.
:h CTRL-W_w
states that windows are numbered from top-left to bottom-right. It is not enough though to determine how windows will be numbered after executing the following commands:
only
enew
vnew
new
wincmd h
new
" Result:
" +---+---+
" | 1 | 3 |
" +---+---+
" | 2 | 4 |
" +---+---+
only
enew
new
vnew
wincmd j
vnew
" Result:
" +---+---+
" | 1 | 2 |
" +---+---+
" | 3 | 4 |
" +---+---+
Thus, it looks like determining current window layout is not possible without using window movement commands (wincmd h/j/k/l
).
Some time ago one additional variant was introduced: pyeval(printf('(lambda win: [win.col, win.row])(vim.windows[%s - 1])', winnr))
(also py3eval(…)
) will provide exact position of the top-left corner of window winnr
. Requires Vim compiled with +python[/dyn]
or +python3[/dyn]
and Python itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With