Vimscript gets the number of the first and last visible line

I know that I can go to the first and last visible line of the current buffer with H and L, respectively. But how can I pass line numbers to variables?

+4
source share
2 answers
let topline = line("w0") let botline = line("w$") 
+8
source

There may be a better way, but if nothing else, you can use H and L to move there and, to return and receive. Sort of

 norm 'H' let top=line('.') norm '``L' let bottom=line('.') norm '``' 

or you can use getpos() to store and setpos() to restore the position, but I'm not sure that you can avoid destroying the previous position label (the command :keepmarks should do this, but the documentation says only this works in some special case).

0
source

All Articles