:bd - don't close window?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

:bd - don't close window?

Dominic Evans
hi,

simple question, any way to make it so vim doesn't close a window when
you do :bd on its buffer?

cheers
dom
Reply | Threaded
Open this post in threaded view
|

RE: :bd - don't close window?

Goli, Rajesh (Rajesh)
I wanted to the very same thing, so I did this: (Not sure if this is the
best way though..)

function! DeleteCurrentBufferAfterBNext()
   bNext
   let buffer_to_delete = bufnr("#")
   if !buflisted(buffer_to_delete)
       enew
       let buffer_to_delete = bufnr("#")
   endif
   execute "bdelete! " buffer_to_delete
endfunction

" Use Control-Q to delete current buffer without removing the window
nnoremap <C-q> :call DeleteCurrentBufferAfterBNext()<CR>
imap     <C-q> <ESC>:call DeleteCurrentBufferAfterBNext()<CR>i

HTH,
Rajesh

-----Original Message-----
From: Dominic Evans [mailto:[hidden email]]
Sent: Thursday, September 15, 2005 2:49 PM
To: vim mailing list
Subject: :bd - don't close window?


hi,

simple question, any way to make it so vim doesn't close a window when
you do :bd on its buffer?

cheers
dom
Reply | Threaded
Open this post in threaded view
|

Re: :bd - don't close window?

Robert Schols
In reply to this post by Dominic Evans
Dominic Evans wrote:

>hi,
>
>simple question, any way to make it so vim doesn't close a window when
>you do :bd on its buffer?
>
>cheers
>dom
>  
>
:help :bd specifically states that it will close all windows displaying
the buffer and it doesn't specify how to change that behaviour. So I
assume that there is no option to tell :bd to keep the window open.

The shortest way can think of would be:

:set bufhidden=delete
:enew

That's still too long to type, so you will probably want to map it.

-- Robert

Reply | Threaded
Open this post in threaded view
|

Re: :bd - don't close window?

James Vega-3
In reply to this post by Dominic Evans
On Thu, Sep 15, 2005 at 10:18:51AM +0100, Dominic Evans wrote:
> hi,
>
> simple question, any way to make it so vim doesn't close a window when
> you do :bd on its buffer?

The following command and mapping will do that:

  " Delete a buffer but keep layout
  command! Kwbd enew|bw #
  nmap     <C-w>!   :Kwbd<CR>

James
--
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

attachment0 (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: :bd - don't close window?

Dominic Evans
Excellent.

I guess ':bw #' means wipeout last opened buffer (before the enew).

Cheers,
Dom

On 15/09/05, James Vega <[hidden email]> wrote:

> On Thu, Sep 15, 2005 at 10:18:51AM +0100, Dominic Evans wrote:
> > hi,
> >
> > simple question, any way to make it so vim doesn't close a window when
> > you do :bd on its buffer?
>
> The following command and mapping will do that:
>
>   " Delete a buffer but keep layout
>   command! Kwbd enew|bw #
>   nmap     <C-w>!   :Kwbd<CR>
>
> James
> --
> GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: :bd - don't close window?

Charles E Campbell Jr
In reply to this post by Dominic Evans
Dominic Evans wrote:

>simple question, any way to make it so vim doesn't close a window when
>you do :bd on its buffer?
>  
>

Check out http://vim.sourceforge.net/tips/tip.php?tip_id=622, "Deleting
a buffer without changing
your window layout".

Regards,
Chip Campbell