Quantcast

Close all buffers except the one you're in ?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Close all buffers except the one you're in ?

Tintin72-2

Hi,

Well I think my question is include in the title.
I know the ':only' command wich close all windows exept the current
one.
Is there a similar command with the buffers ?


Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Alexey Radkov

you can use

autocmd BufEnter * setlocal bufhidden=delete

in .vimrc. This ensure that you will have only one buffer ever in
current window. See ':help bufhidden for details.

Regards. Alexey.

On 17 янв, 11:47, Tintin72 <[hidden email]> wrote:
> Hi,
>
> Well I think my question is include in the title.
> I know the ':only' command wich close all windows exept the current
> one.
> Is there a similar command with the buffers ?
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Tintin72-2

Thanks for your response.
But I don't want to have just one buffer.
Generaly I'm working with several buffers
(typing :bnext or :bprevious to reach them).

So is there a kind of ":bdelete only" ?

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Andy Wokula

Tintin72 schrieb:
> Thanks for your response.
> But I don't want to have just one buffer.
> Generaly I'm working with several buffers
> (typing :bnext or :bprevious to reach them).
>
> So is there a kind of ":bdelete only" ?

with a user command:

com! -bar -bang BdOnly call s:BdOnly(<q-bang>)

func! s:BdOnly(bang)
    let bdcmd = "bdelete". a:bang
    let bnr = bufnr("")
    if bnr > 1
        call s:ExecCheckBdErrs("1,".(bnr-1). bdcmd)
    endif
    if bnr < bufnr("$")
        call s:ExecCheckBdErrs((bnr+1).",".bufnr("$"). bdcmd)
    endif
endfunc

func! s:ExecCheckBdErrs(bdrangecmd)
    try
        exec a:bdrangecmd
    catch /:E51[567]:/
        " no buffers unloaded/deleted/wiped out: ignore
    catch
        echohl ErrorMsg
        echomsg matchstr(v:exception, ':\zsE.*')
        echohl none
    endtry
endfunc

--
Andy


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Tintin72-2

Thanks for your help but I just can't understand what that code means
exactely and where
should I place it. I expected a less complicated solution cause I'm
not an advanced
Vim's user, sorry.

However I found a tip wich is:

- type :ls to see the list of buffers and their numbers (for ex: 1 to
6) .
- see what is the number of the buffer I want to keep (let's say 3)
- and then type :bdelete 1 2 4 5 6

It works, but is it possible to combine the :bdelete command with
a regular expression wich say "anything except 3" ?

A sort of :bdelete [regular exp] 3


Any idea ?
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Andy Wokula

Tintin72 schrieb:

> Thanks for your help but I just can't understand what that code means
> exactely and where
> should I place it. I expected a less complicated solution cause I'm
> not an advanced
> Vim's user, sorry.
>
> However I found a tip wich is:
>
> - type :ls to see the list of buffers and their numbers (for ex: 1 to
> 6) .
> - see what is the number of the buffer I want to keep (let's say 3)
> - and then type :bdelete 1 2 4 5 6
>
> It works, but is it possible to combine the :bdelete command with
> a regular expression wich say "anything except 3" ?
>
> A sort of :bdelete [regular exp] 3
>
>
> Any idea ?

:bd accepts a range:
    :1,2bd | 4,99bd

--
Andy


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Agathoklis D. Hatzimanikas
In reply to this post by Tintin72-2

On Sun, Jan 18, at 01:38 Tintin72 wrote:
>
> Thanks for your help but I just can't understand what that code means
> exactely and where
> should I place it. I expected a less complicated solution cause I'm
> not an advanced
> Vim's user, sorry.
>

Here is the most simple solution, I could think off:

function! Buflist()
    redir => bufnames
    silent ls
    redir END
    let list = []
    for i in split(bufnames, "\n")
        let buf = split(i, '"' )
        call add(list, buf[-2])
|   endfor
    return list
endfunction

function! Bdeleteonly()
    let list = filter(Buflist(), 'v:val != bufname("%")')
    for buffer in list
        exec "bdelete ".buffer
    endfor
endfunction

command! BdelOnly :silent call Bdeleteonly()

Place this function in a file with a meaningful name (with a vim extension),
under ~/.vim/plugin directory, and then use :BdelOnly to delete all buffers
than the current one.

Regards,
Ag.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Close all buffers except the one you're in ?

Charles E Campbell Jr
In reply to this post by Tintin72-2

Tintin72 wrote:
> Hi,
>
> Well I think my question is include in the title.
> I know the ':only' command wich close all windows exept the current
> one.
> Is there a similar command with the buffers ?
>  
Just as an alternative -- you might want to try ZoomWin; you can get
ZoomWin from:

    http://vim.sourceforge.net/scripts/script.php?script_id=508  (stable)
    http://mysite.verizon.net/astronaut/vim/index.html#ZOOMWIN   
(cutting edge)

With it, type  ctrl-w o  and only your current window will be
displayed.  Press   ctrl-w o
again, and your preceding window layout will return.  The
mysite.verizon... version has
some bugs fixed that the stable one doesn't.

Regards,
Chip Campbell


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Loading...