As a partial answer, for line('.')
, you can get the buffer number associated with a window with winbufnr({nr})
(carefull to pass the window number and not the window id) then pass it to getbufinfo([{expr}])
and get the lnum
entry :
getbufinfo(winbufnr({nr}))[0]['lnum']
Thanks to @Luc Hermitte, we can get the last line number with
len(getbufline(winbufnr({nr}), 1, '$')
which gets all the lines of the buffer as a list of strings and returns its length.
Old original answer
Can't tell how to get line('$')
without moving to the actual window. But we could achieve it with a function that restores the current and previous visited window, than get any line({expr})
:
function! WindowLine(winnr, expr)
let curr_window = winnr()
let prev_window = winnr('#')
exec a:winnr . 'wincmd w'
let line = line(a:expr)
exec prev_window . 'wincmd w'
exec curr_window . 'wincmd w'
return line
endfunction
echo WindowLine(2, '$')