>
> Vim 7.2.411
>
> I am trying to determine via VimScript how many windows are on the
> screen at the moment.
> More specifically, I am trying to determine if a user just opened Vim
> and they are sitting at the [No Name] buffer.
> This could also be in a new tab.
>
> If so, I would like to take over that buffer with something else rather
> than creating a new buffer and end up having 2 buffers.
>
> Looking through :h functions, I don't see anything jumping out to give
> me a count of all windows.
> What I think will work is parsing the output from winrestcmd().
>
> 1resize 32|vert 1resize 117|2resize 32|vert 2resize 117|3resize 65|vert
> 3resize 117|
>
> Based on this output and simple regex to find '\<2resize\>' should do
> it, but it just seems a bit of a hack.
>
> That gets me to the point where I know we just have the one buffer.
>
> Not really sure how to get rid of the [No Name] buffer and replace it
> with my own.
> :0r myfile
>
> Results in [No Name] with the contents.
> But what I really want is [No Name] gone and just myfile.
>
> Suggestions?
>
> TIA,
> Dave
>
To determine how many windows are onscreen (in the current tabpage)
:let numwindows = winnr('$')
see :help winnr()
See also http://vim.wikia.com/wiki/Going_to_the_nth-from-last_window for
one possible use case.
If the current buffer is an empty [NoName] buffer, you can easily
replace it by /some/long/exemplary/path/to/foobar.txt by using
:e /some/long/exemplary/path/to/foobar.txt
(now who would have thought of that? ;-) and add an exclamation mark
after :e if the buffer is modified).
To close all windows (of the current tabpage) except the current one:
:only
The help for that command describes its interaction with the 'hidden'
and 'autowrite' options, and what difference there is if you add an
exclamation mark -- broadly, that interaction is what you would expect
it to be.
In all these examples, the initial colon is of course unnecessary when
the command is read from a sourced script.
Best regards,
Tony.
--
ARTHUR: Shut up! Will you shut up!
DENNIS: Ah, now we see the violence inherent in the system.
ARTHUR: Shut up!
DENNIS: Oh! Come and see the violence inherent in the system!
HELP! HELP! I'm being repressed!
The Quest for the Holy Grail (Monty
Python)
--
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
No comments:
Post a Comment