Tuesday, March 30, 2010

Re: Commnad over a window

On 03/02/10 01:27, JuanPablo wrote:
> and there is some way of listing the windows?
> similar to buffers
> ?

For buffers, it's easy: see :help :ls; but for use in a script see the
help links near the bottom of this message.

For windows, it's more involved: windows are defined by their number
(starting at 1 at top-left and with the highest number at bottom-right)
within their tabpages (which are also numbered starting at 1). Unlike
buffers, there is no "window identifier" which remains unchanged when
you move windows and tabpages around, or open and close them.

Now here we go:

tabpagenr()
the number of the current tab page
tabpagenr('$')
the total number of tab pages

winnr()
the number of the current window within the current tab page
winnr('$')
the number of windows within the current tab page
winnr('#')
the number of the latest window accessed in this tab
before the current one; or 0 if there was no previous window
or if it was in a different tabpage

tabpagewinnr(t)
the number of the current window in the t-th tab
tabpagewinnr(t,'$')
the total number of windows in the t-th tab
tabpagwinnr(t,'#')
the previous window for the t-th tab

tabpagebuflist()
a List whose items are the buffer numbers for the current tab
This is zero-based!
tabpagebuflist()[0] is the number of the buffer in window 1
tabpagebuflist(t)
the same for the t-th tab
Notes:
- In case of error (t < 1 || t > tabpagenr('$'),
the number 0 is returned.
- A buffer can be displayed in more than one window.

winbufnr(0)
the number of the buffer in the current window
(of the current tab)
winbufnr(w)
the number of the buffer in the w-th window
(of the current tab)
== tabpagebuflist()[w - 1]
Returns -1 if there is no w-th window

See also:
:help tabp*(<Ctrl-D>
:help win*(<Ctrl-D>
:help buf*(<Ctrl-D>

where <Ctrl-D> means: hit Ctrl-D (i.e. hit d while holding Ctrl).

And see ":help setting-tabline" for a couple of user-defined functions
which use these builtin functions in order to display the text-mode tab
line (showing the current buffer in each tab). See also the example
under tabpagebuflist() to get a List of all buffers in all tabs (some of
them may appear more than once, and hidden buffers, which are loaded but
not displayed, won't appear at all in that List). Either of these
examples can be expanded to get a two-level list of all buffers listed
per tab.

Best regards,
Tony.
--
Adore, v.:
To venerate expectantly.
-- Ambrose Bierce, "The Devil's Dictionary"

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.

No comments: