Describe the bug
getbufinfo({expr})[0].lnum doesn't return the correct line number when {expr} is not the current buffer.
To Reproduce
vim --clean test.vim -S test.vim with
new foo call setline(1, ['1', '2', '3']) $ wincmd p echomsg getbufinfo('foo')[0].lnum
0, but it should be 3.Expected behavior
getbufinfo({expr})[0].lnum should always return the current cursor position in buffer {expr} even if the buffer isn't currently focused.
Environment
Vim version 8.2.1351
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
Okay I misunderstood then. I thought it returns the last cursor position in the given buffer.
Closed #6612.
But how is getbufinfo({expr})[0].lnum userful? I honestly don't understand the purpose of it since the buffer needs to be focused. Isn't it the same as line('.')?
@bfrg I think what Bram means is that the cursor position is related to the buffer when it is opened in the current window. You can see this with this modification to your example, which opens foo in the same window, instead of in a split:
enew file foo
call setline(1, ['1', '2', '3']) $
set hidden edit #
echomsg getbufinfo('foo')[0].lnum
—