astropanic
astropanic

Reputation: 10939

vimscript get number of first and last visible line

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

Upvotes: 5

Views: 2067

Answers (2)

tjm
tjm

Reputation: 7550

let topline = line("w0")
let botline = line("w$")

Upvotes: 12

Jan Hudec
Jan Hudec

Reputation: 76316

There might be a better way, but if nothing else, you can use H and L to move there and `` to get back and get. Something like

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 am not sure you can avoid destroying the previous position mark (the :keepmarks command should do that, but it's documentation says it only works in some special case).

Upvotes: 0

Related Questions