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;








2















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?










share|improve this question
































    2















    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?










    share|improve this question




























      2












      2








      2








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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























          2 Answers
          2






          active

          oldest

          votes


















          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, '$')





          share|improve this answer






















          • 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



















          2














          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.






          share|improve this answer




















          • 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













          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
          );



          );













          draft saved

          draft discarded


















          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









          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, '$')





          share|improve this answer






















          • 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
















          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, '$')





          share|improve this answer






















          • 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














          2












          2








          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, '$')





          share|improve this answer















          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, '$')






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 8 at 12:02

























          answered Aug 8 at 11:08









          pereloperelo

          2811 silver badge5 bronze badges




          2811 silver badge5 bronze badges










          • 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













          • 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








          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














          2














          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.






          share|improve this answer




















          • 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















          2














          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.






          share|improve this answer




















          • 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













          2












          2








          2







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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












          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

          Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

          Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림