How to get line numbers of a different windowHow do I use relative line numbers in command line mode?Get the offset/position of the current window in the layoutWhat is a better way to use `windo` without changing of window?Why `v:lnum` doesn't return 1 for the first line?Set line numbers only while in normal modecontinue buffer in new windowGet column of last character in visual line - VimscriptIn VIM, Change the number that relative lines numbers start fromHow to copy lines with line numbers?Add line numbers and remove line numbers to selected lines
Why does my house heat up, even when it's cool outside?
Have only girls been born for a long time in this village?
Why we don't have vaccination against all diseases which are caused by microbes?
How to compare two different formulations of a problem?
Can we save the word "unique"?
How do you call it when two celestial bodies come as close to each other as they will in their current orbits?
Is it safe to remove the bottom chords of a series of garage roof trusses?
Is refusing to concede in the face of an unstoppable Nexus combo punishable?
Was Switzerland really impossible to invade during WW2?
Was Tuvok bluffing when he said that Voyager's transporters rendered the Kazon weapons useless?
A second course in the representation theory
Metal that glows when near pieces of itself
Church Booleans
Potential new partner angry about first collaboration - how to answer email to close up this encounter in a graceful manner
Do I have to learn /o/ or /ɔ/ separately?
Vacuum collapse -- why do strong metals implode but glass doesn't?
Can you grapple/shove with the Hunter Ranger's Whirlwind Attack?
How to determine if an Apex class hasn't been used recently
!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!
Running script line by line automatically yet being asked before each line from second line onwards
Why don't politicians push for fossil fuel reduction by pointing out their scarcity?
Can others monetize my project with GPLv3?
Was this pillow joke on Friends intentional or a mistake?
Starships without computers?
How to get line numbers of a different window
How do I use relative line numbers in command line mode?Get the offset/position of the current window in the layoutWhat is a better way to use `windo` without changing of window?Why `v:lnum` doesn't return 1 for the first line?Set line numbers only while in normal modecontinue buffer in new windowGet column of last character in visual line - VimscriptIn VIM, Change the number that relative lines numbers start fromHow to copy lines with line numbers?Add line numbers and remove line numbers to selected lines
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I would like to get these line numbers of a different window without moving to that window.
line('w0')
line('w$')
line('.')
line('$')
As for the first two, we can use getwininfo([winid]) which returns a list including 'topline' and 'botline'. Is there any function or some workaround as for the last two?
vimscript vim-windows line-numbers
add a comment |
I would like to get these line numbers of a different window without moving to that window.
line('w0')
line('w$')
line('.')
line('$')
As for the first two, we can use getwininfo([winid]) which returns a list including 'topline' and 'botline'. Is there any function or some workaround as for the last two?
vimscript vim-windows line-numbers
add a comment |
I would like to get these line numbers of a different window without moving to that window.
line('w0')
line('w$')
line('.')
line('$')
As for the first two, we can use getwininfo([winid]) which returns a list including 'topline' and 'botline'. Is there any function or some workaround as for the last two?
vimscript vim-windows line-numbers
I would like to get these line numbers of a different window without moving to that window.
line('w0')
line('w$')
line('.')
line('$')
As for the first two, we can use getwininfo([winid]) which returns a list including 'topline' and 'botline'. Is there any function or some workaround as for the last two?
vimscript vim-windows line-numbers
vimscript vim-windows line-numbers
edited Aug 8 at 12:09
statox♦
28.5k8 gold badges80 silver badges145 bronze badges
28.5k8 gold badges80 silver badges145 bronze badges
asked Aug 8 at 4:10
Rick HoweRick Howe
1614 bronze badges
1614 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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, '$')
1
Withlen(getbufline(winbufnr(nr), 1, '$')we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)
– Luc Hermitte
Aug 8 at 11:48
add a comment |
patch 8.1.1418 introduced :h win_execute() :
call win_execute(winid, 'let l:num_lines = line("$") | let l:current_line = line(".")')
It's fast, it has no window related side effect.
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "599"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20850%2fhow-to-get-line-numbers-of-a-different-window%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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, '$')
1
Withlen(getbufline(winbufnr(nr), 1, '$')we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)
– Luc Hermitte
Aug 8 at 11:48
add a comment |
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, '$')
1
Withlen(getbufline(winbufnr(nr), 1, '$')we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)
– Luc Hermitte
Aug 8 at 11:48
add a comment |
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, '$')
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, '$')
edited Aug 8 at 12:02
answered Aug 8 at 11:08
pereloperelo
2811 silver badge5 bronze badges
2811 silver badge5 bronze badges
1
Withlen(getbufline(winbufnr(nr), 1, '$')we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)
– Luc Hermitte
Aug 8 at 11:48
add a comment |
1
Withlen(getbufline(winbufnr(nr), 1, '$')we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)
– Luc Hermitte
Aug 8 at 11:48
1
1
With
len(getbufline(winbufnr(nr), 1, '$') we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)– Luc Hermitte
Aug 8 at 11:48
With
len(getbufline(winbufnr(nr), 1, '$') we can obtain the number of the last line in a given buffer. It will be a lot more efficient than any solution that switches context (and that could also trigger autocommands)– Luc Hermitte
Aug 8 at 11:48
add a comment |
patch 8.1.1418 introduced :h win_execute() :
call win_execute(winid, 'let l:num_lines = line("$") | let l:current_line = line(".")')
It's fast, it has no window related side effect.
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
add a comment |
patch 8.1.1418 introduced :h win_execute() :
call win_execute(winid, 'let l:num_lines = line("$") | let l:current_line = line(".")')
It's fast, it has no window related side effect.
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
add a comment |
patch 8.1.1418 introduced :h win_execute() :
call win_execute(winid, 'let l:num_lines = line("$") | let l:current_line = line(".")')
It's fast, it has no window related side effect.
patch 8.1.1418 introduced :h win_execute() :
call win_execute(winid, 'let l:num_lines = line("$") | let l:current_line = line(".")')
It's fast, it has no window related side effect.
answered Aug 8 at 13:50
dedowsdidedowsdi
2,2661 gold badge4 silver badges16 bronze badges
2,2661 gold badge4 silver badges16 bronze badges
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
add a comment |
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
1
1
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
Thank you. win_execute() can be used not only for line() but also other window local functions without changing the window.
– Rick Howe
Aug 9 at 7:30
add a comment |
Thanks for contributing an answer to Vi and Vim Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20850%2fhow-to-get-line-numbers-of-a-different-window%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown