0

I am search for the opposite of winline(). winline() returns the screen line in the window of the current cursor position. I want to be able to set it. Therefore scroll the windows content so that the line the cursor is currently in, lands in screen line x.

vim already provides commands like zz to scroll the current line to the middle of the window or zt to scroll it to the top of the window. But I didn't find a way to scroll it to a specific line.

Edit:

Just for reference: I can calculate it myself by getting the actual winline with winline(), calculating the difference and calling one of:

execute "normal! " . count . "\<C-Y>" execute "normal! " . count . "\<C-E>" 

But that seems slightyl awkward to me and has the actual drawback that it won't work (and in fact does unpredictable things) if the user remapped <C-Y> or <C-E> to some other operation.

4
  • "I want to be able to set it." If you want to move the cursor, use "nG" where n is the line number. For example "42G" moves to the forty-second line. vimhelp.org/motion.txt.html#up-down-motions Commented Apr 6, 2022 at 13:38
  • it won't work ... if the user remapped <C-Y> or <C-E> Actually, you are using normal! (with the bang), which ignores mappings Commented Apr 6, 2022 at 14:07
  • @shawnhcorey No, I don't want to set the cursor to a different line. I want it to stay on the current line, but that line be moved to a certain screen line . Like zt moves the line with the cursor to the top of the window (while the cursor remains in that line). Commented Apr 7, 2022 at 10:04
  • @husB Yes! You are right, of course! So that workaround isn't too bad. Commented Apr 7, 2022 at 10:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.