How do you get the position of the cursor or of a line within the window?

image

I want to know where the cursor is relative to the window, or where a certain line is relative to the window. For example, say the cursor is on line 7 of the buffer. If line 7 is at the top of the window, I want 1. If line 7 is a little ways down in the window, I want 20. If my window height is 100 and line 7 is at the very bottom, then I want 100.

Is there a way to obtain this information?

I have looked at nvim_win_get_cursor, getcurpos, win_screenpos, getwininfo, getpos and others, but these deal with either the position of the cursor in the buffer, or the position of the window in the layout, neither of which are what I want.

I would recommend to use screenpos()

or:

For the line information you can also do:

Ask AI
#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70