Loading ...
Sorry, an error occurred while loading the content.

Re: how to get list of open windows

Expand Messages
  • Tony Mechelynck
    ... To determine how many split-windows are open: winnr( $ ) How many in the current tabpage: tabpagewinnr(tabpagenr(), $ ) List all split windows by tab
    Message 1 of 8 , Aug 31, 2007
    • 0 Attachment
      gmguyx wrote:
      > Is there some function I can call to get the list of open windows (not
      > buffers) in vim? When I say windows I mean split windows. The reason I
      > need this is because I'm writing a script whose behavior will be
      > different depending on how many split windows are open.

      To determine how many split-windows are open:

      winnr('$')

      How many in the current tabpage:

      tabpagewinnr(tabpagenr(), '$')

      List all split windows by tab page:

      let t = 1
      while t <= tabpagenr('$')
      echo 'tab' t . ':'
      let bufs = tabpagebuflist(t)
      let w = 0
      while w < tabpagewinnr(t, '$')
      echo "\t" . bufname(bufs[w])
      let w += 1
      endwhile
      let t += 1
      endwhile
      unlet t w bufs


      Best regards,
      Tony.
      --
      -- Gifts for Men --

      Men are amused by almost any idiot thing -- that is why professional
      ice hockey is so popular -- so buying gifts for them is easy. But you
      should never buy them clothes. Men believe they already have all the
      clothes they will ever need, and new ones make them nervous. For
      example, your average man has 84 ties, but he wears, at most, only
      three of them. He has learned, through humiliating trial and error,
      that if he wears any of the other 81 ties, his wife will probably laugh
      at him ("You're not going to wear THAT tie with that suit, are you?").
      So he has narrowed it down to three safe ties, and has gone several
      years without being laughed at. If you give him a new tie, he will
      pretend to like it, but deep inside he will hate you.

      If you want to give a man something practical, consider tires. More
      than once, I would have gladly traded all the gifts I got for a new set
      of tires.
      -- Dave Barry, "Christmas Shopping: A Survivor's Guide"

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tim Chase
      ... Ah...something I must have missed somewhere. Other than Try it and see that it happens to be the case , is there some place to learn this in the docs?
      Message 2 of 8 , Sep 1, 2007
      • 0 Attachment
        > Actually, the windows are identified by sequential numbers from 1 to
        > winnr('$') and they don't have any fixed ids so they are reliable only
        > when the window layout has not changed.

        Ah...something I must have missed somewhere. Other than "Try it
        and see that it happens to be the case", is there some place to
        learn this in the docs? The best I could find was

        "windows are numbered from top-left to bottom-right"

        in ":help windows.txt". However, this doesn't make it obvious
        that they're time-sensitive (if I changed my window layout, the
        buffer<->window mapping changes), and that holes never appear in
        the count if windows are closed.

        With that foreknowledge that they're monotonically increasing
        from 1..winnr('$'), the results are, as Hari and others noted,
        considerably easier to produce :)

        -tim




        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... help winnr() also mentions that winnr( $ ) is both the number of the last window and the window count . IOW, no holes. The fact that the windows are
        Message 3 of 8 , Sep 1, 2007
        • 0 Attachment
          Tim Chase wrote:
          >> Actually, the windows are identified by sequential numbers from 1 to
          >> winnr('$') and they don't have any fixed ids so they are reliable only
          >> when the window layout has not changed.
          >
          > Ah...something I must have missed somewhere. Other than "Try it
          > and see that it happens to be the case", is there some place to
          > learn this in the docs? The best I could find was
          >
          > "windows are numbered from top-left to bottom-right"
          >
          > in ":help windows.txt". However, this doesn't make it obvious
          > that they're time-sensitive (if I changed my window layout, the
          > buffer<->window mapping changes), and that holes never appear in
          > the count if windows are closed.
          >
          > With that foreknowledge that they're monotonically increasing
          > from 1..winnr('$'), the results are, as Hari and others noted,
          > considerably easier to produce :)
          >
          > -tim

          help winnr() also mentions that winnr('$') is both "the number of the last
          window" and "the window count". IOW, no holes.

          The fact that the windows are numbered top-to-bottom implies (the way I read
          it) that when you rearrange your window layout, the window-number-to-buffer
          mapping changes. Unlike buffer numbers (which are attributed once and for all,
          and never change even if a lower-numbered buffer is ":bwipeout"ed), a window's
          number changes whenever a lower-numbered window is opened or closed. (Window
          number 1 is always at top left and window number winnr('$') is always at
          bottom right.)


          Best regards,
          Tony.
          --
          "The whole world is about three drinks behind."
          -- Humphrey Bogart

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.