Reputation: 1931
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.
Upvotes: 9
Views: 1287
Reputation: 1050
I'm coming across this question in September 2023, which now has the built-in function winlayout()
, which appears to have been added into Vim circa 2019 judging from the Vim's GH repo.
Granted, its return value isn't exactly in the form the OP asked for. But for my purpose of determining if the primary split of my windows is along the vertical or horizontal orientation, this function suffices.
Upvotes: 0
Reputation: 53654
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.
Upvotes: 4
Reputation: 12205
So I think the only thing that might help you is:
:!xwininfo -id $WINDOWID
Other then that I don't think you can get the specific coordinate splits.
Upvotes: 0