There may be any number of nested vertical and horizontal splits on a Vim screen. I'd like to find the (x, y) coords, in terms of columns and lines inside Vim, of the top-left corner of the current window.
It's easy to find the dimensions of the current window (
winwidth(0)), how many windows there are (
winnr('$')), as well as all of their widths and heights (
winrestcmd()), but this doesn't say enough about the adjacency of windows to each other. All we know is that windows with smaller numbers will generally be towards the top and left of those with larger numbers. Also, I'm not even sure how to find the number of lines and columns of the whole Vim screen (including all of the windows and the command line)...
Right now I'm doing this. It's suitable for me, but it makes the mouse cursor flicker a bit.
funct! CountLinesAboveWindow() let lz_setting = &lazyredraw set lazyredraw let original_nr = winnr() let last_nr = original_nr let lines_above = 0 while 1 wincmd k let nr = winnr() if nr == last_nr break endif let lines_above = lines_above + winheight(0) + 1 let last_nr = nr endwhile exe original_nr . "wincmd w" let &lazyredraw = lz_setting return lines_above endfunct! #And similarly for CountColumnsToTheLeftOfWindow()
Is there a more elegant way? It has to be faster than the above, which excludes
:mksession as an option.
The reason I want this is to write functions
screencol(), analogous to the built-in