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

Quick: delete buffer & keep window

Expand Messages
  • overbored
    Is it possible to delete a buffer (:bd) without closing the window (and instead do something like switch to another buffer)? Thanks in advance.
    Message 1 of 9 , Oct 8, 2004
    • 0 Attachment
      Is it possible to delete a buffer (:bd) without closing the window (and
      instead do something like switch to another buffer)? Thanks in advance.
    • Alan G Isaac
      ... I assume you have set hidden . So switch to the other buffer. Then ... hth, Alan Isaac
      Message 2 of 9 , Oct 8, 2004
      • 0 Attachment
        On Fri, 08 Oct 2004, overbored apparently wrote:
        > Is it possible to delete a buffer (:bd) without closing the window (and
        > instead do something like switch to another buffer)? Thanks in advance.

        I assume you have set 'hidden'.
        So switch to the other buffer. Then
        :bd #

        hth,
        Alan Isaac
      • Charles E. Campbell, Jr.
        ... Hello! Perhaps the following tip will help you: http://vim.sourceforge.net/tips/tip.php?tip_id=622, on Deleting a buffer without changing your window
        Message 3 of 9 , Oct 8, 2004
        • 0 Attachment
          overbored wrote:

          > Is it possible to delete a buffer (:bd) without closing the window
          > (and instead do something like switch to another buffer)? Thanks in
          > advance.

          Hello!

          Perhaps the following tip will help you:

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

          Regards,
          Chip Campbell
        • Keith Roberts
          ... Here s what I use: Delete buffer, move to Alternate (or next) map :if bufnr( # ) 0 |:b# |:else |:bn |:endif |:bw# imap
          Message 4 of 9 , Oct 29, 2004
          • 0 Attachment
            >-----Original Message-----
            >From: overbored [mailto:overbored@...]
            >Sent: Friday, October 08, 2004 12:03 AM
            >To: vim@...
            >Subject: Quick: delete buffer & keep window
            >
            >Is it possible to delete a buffer (:bd) without closing the
            >window (and instead do something like switch to another
            >buffer)? Thanks in advance.

            Here's what I use:
            " Delete buffer, move to Alternate (or next)
            map <C-S-F4> :if bufnr('#') >
            0\|:b#\|:else\|:bn\|:endif\|:bw#<CR>
            imap <C-S-F4> <ESC><C-S-F4>
            " Unload buffer, move to Alternate (or next)
            map <C-F4> :if bufnr('#') >
            0\|:b#\|:else\|:bn\|:endif\|:bunload #<CR>
            imap <C-F4> <ESC><C-F4>

            ... and just for good measure ...

            " Delete buffer, move to Previous (does NOT remove window)
            map <C-S-F7> :bp<CR>:bw #<CR>
            imap <C-S-F7> <ESC><C-S-F7>
            " Unload buffer, move to Previous
            map <C-F7> :bp<CR>:bunload #<CR>
            imap <C-F7> <ESC><C-F7>
            " Unmapped
            map <S-F7> :echo "Unmapped!"<CR>
            imap <S-F7> <ESC>:echo "Unmapped!"<CR>l
            " Move to Previous buffer
            map <F7> :bp<CR>
            imap <F7> <ESC><C-F7>

            " Delete buffer, move to Next (does NOT remove window)
            map <C-S-F8> :bn<CR>:bw #<CR>
            imap <C-S-F8> <ESC><C-S-F8>
            " Unload buffer, move to Next
            map <C-F8> :bn<CR>:bunload #<CR>
            imap <C-F8> <ESC><C-F8>
            " Unmapped
            map <S-F8> :echo "Unmapped!"<CR>
            imap <S-F8> <ESC>:echo "Unmapped!"<CR>l
            " Move to Next buffer
            map <F8> :bn<CR>
            imap <F8> <ESC><C-F8>

            I uses the F7/F8 series to quickly traverse the buffer list in either
            direction, but now that I use locate and lid so much I more often use
            the F4 series.
          • drchip@campbellfamily.biz
            Hello! Perhaps the following tip will be of help: Deleting a buffer without changing your window layout http://vim.sourceforge.net/tips/tip.php?tip_id=622
            Message 5 of 9 , Oct 29, 2004
            • 0 Attachment
              Hello!

              Perhaps the following tip will be of help:
              "Deleting a buffer without changing your window layout"
              http://vim.sourceforge.net/tips/tip.php?tip_id=622

              Regards,
              Chip Campbell
            • Keith Roberts
              ... That s cool, if in fact you do want an empty buffer to play with; otherwise it burns a buffer number every time you do it. But that does give me an idea
              Message 6 of 9 , Oct 29, 2004
              • 0 Attachment
                >-----Original Message-----
                >From: drchip@... [mailto:drchip@...]
                >Sent: Friday, October 29, 2004 8:14 AM
                >To: vim@...
                >Subject: RE: Quick: delete buffer & keep window
                >
                >Hello!
                >
                >Perhaps the following tip will be of help:
                >"Deleting a buffer without changing your window layout"
                >http://vim.sourceforge.net/tips/tip.php?tip_id=622
                >
                >Regards,
                >Chip Campbell

                That's cool, if in fact you do want an empty buffer to play with;
                otherwise it burns a buffer number every time you do it. But that does
                give me an idea ... Instead of doing :bn when there is no alternate
                buffer, I could instead switch to the scratch buffer I like to have
                handy. :)

                -Keith
              • John Orr
                ... Agree Keith - but most of all I agree entirely with the second last post to Chip s tip 622: ... without disturbing windows splits / cursor position ...
                Message 7 of 9 , Oct 29, 2004
                • 0 Attachment
                  > -----Original Message-----
                  > From: Keith Roberts [mailto:kroberts@...]
                  > Sent: Friday, 29 October 2004 6:41 PM
                  > To: drchip@...; vim@...
                  > Subject: RE: Quick: delete buffer & keep window
                  >
                  >
                  > >-----Original Message-----
                  > >From: drchip@... [mailto:drchip@...]
                  > >Sent: Friday, October 29, 2004 8:14 AM
                  > >To: vim@...
                  > >Subject: RE: Quick: delete buffer & keep window
                  > >
                  > >Hello!
                  > >
                  > >Perhaps the following tip will be of help:
                  > >"Deleting a buffer without changing your window layout"
                  > >http://vim.sourceforge.net/tips/tip.php?tip_id=622
                  > >
                  > >Regards,
                  > >Chip Campbell
                  >
                  > That's cool, if in fact you do want an empty buffer to play with;
                  > otherwise it burns a buffer number every time you do it. But that does
                  > give me an idea ... Instead of doing :bn when there is no alternate
                  > buffer, I could instead switch to the scratch buffer I like to have
                  > handy. :)
                  >
                  > -Keith
                  >
                  >

                  Agree Keith - but most of all I agree entirely with the second last post to
                  Chip's tip 622:

                  "This is how bdel should work (gnu-emacs kill-buffer does it right):
                  > visit a file in window,
                  > go to 2nd file (vim gf)
                  > go to 3rd file
                  > kill-buffer of 3rd file, and you are back to the view of 2nd file,
                  without disturbing windows splits / cursor position
                  > kill 2nd file, and viola, you are back to 1st file."

                  This example seems almost impossible in vim, since, for me at least in
                  windows vim 6.3, gf doesn't set the alternate buffer at all - so there's no
                  (easy) way to know from which buffer you came.

                  Ignore this case then, and suppose you got to the 2nd and 3rd files with a
                  'jump to tag under the cursor' command (as I often do) - then you'll get
                  back one level, from 3 to 2, but then there's no alternate buffer left
                  (well, vim knows that it's number 3, but if you've bw'd it, it can't get
                  there). Keith's solution gives us bn at this point, which is better than
                  nothing, and works in this little example with only three buffers in total -
                  but if more files are involved, bn is just a 'best effort' I would say.
                  What's more, if you have minibuffer or equivalent running, things can get
                  somewhat more stuffed up it seems.

                  IMHO the quote above is indeed the most logical way to work and should be
                  the default behaviour - and people that want to open new buffers, or scratch
                  buffers, or any other kind of buffer which they haven't recently had open in
                  the window in question, should write code to handle such customisations.

                  Counter opinions (not to mention minibuffer customisations to implement this
                  behaviour) most welcome,
                  John
                • Keith Roberts
                  ... Absolutely. That was the idea. My newer idea of using my scratch buffer as the alternative when # is undefined is better, because chances are I want
                  Message 8 of 9 , Nov 1, 2004
                  • 0 Attachment
                    >-----Original Message-----
                    >From: John Orr [mailto:john_orr@...]
                    >Sent: Friday, October 29, 2004 2:54 PM
                    >To: Keith Roberts; drchip@...; vim@...
                    >Subject: RE: Quick: delete buffer & keep window
                    >
                    >> -----Original Message-----
                    >> From: Keith Roberts [mailto:kroberts@...]
                    >> Sent: Friday, 29 October 2004 6:41 PM
                    >> To: drchip@...; vim@...
                    >> Subject: RE: Quick: delete buffer & keep window
                    >>
                    >>
                    >> >-----Original Message-----
                    >> >From: drchip@... [mailto:drchip@...]
                    >> >Sent: Friday, October 29, 2004 8:14 AM
                    >> >To: vim@...
                    >> >Subject: RE: Quick: delete buffer & keep window
                    >> >
                    >> >Hello!
                    >> >
                    >> >Perhaps the following tip will be of help:
                    >> >"Deleting a buffer without changing your window layout"
                    >> >http://vim.sourceforge.net/tips/tip.php?tip_id=622
                    >> >
                    >> >Regards,
                    >> >Chip Campbell
                    >>
                    >> That's cool, if in fact you do want an empty buffer to play with;
                    >> otherwise it burns a buffer number every time you do it. But that
                    >> does give me an idea ... Instead of doing :bn when there is no
                    >> alternate buffer, I could instead switch to the scratch
                    >buffer I like
                    >> to have handy. :)
                    >>
                    >> -Keith
                    >>
                    >>
                    >
                    >Agree Keith - but most of all I agree entirely with the second
                    >last post to Chip's tip 622:
                    >
                    >"This is how bdel should work (gnu-emacs kill-buffer does it right):
                    >> visit a file in window,
                    >> go to 2nd file (vim gf)
                    >> go to 3rd file
                    >> kill-buffer of 3rd file, and you are back to the view of 2nd file,
                    > without disturbing windows splits / cursor position
                    >> kill 2nd file, and viola, you are back to 1st file."
                    >
                    >This example seems almost impossible in vim, since, for me at
                    >least in windows vim 6.3, gf doesn't set the alternate buffer
                    >at all - so there's no
                    >(easy) way to know from which buffer you came.
                    >
                    >Ignore this case then, and suppose you got to the 2nd and 3rd
                    >files with a 'jump to tag under the cursor' command (as I
                    >often do) - then you'll get back one level, from 3 to 2, but
                    >then there's no alternate buffer left (well, vim knows that
                    >it's number 3, but if you've bw'd it, it can't get there).
                    >Keith's solution gives us bn at this point, which is better
                    >than nothing, and works in this little example with only three
                    >buffers in total - but if more files are involved, bn is just
                    >a 'best effort' I would say.

                    Absolutely. That was the idea. My newer idea of using my "scratch"
                    buffer as the alternative when '#' is undefined is better, because
                    chances are I want to load something else in there, and I'm all set to
                    do a :b something<tab> (or the like). And if I want to use locate or
                    lid to grab something, well, I'm now in my "scratch" buffer, and that's
                    what it's for.

                    In order to successfully wipe out buffers while backing thru the :tag
                    list, you could create a map that would ^T, then get the buffer
                    name/number from the :tag list (histget? ... no, tag list isn't
                    addressable by histget, at least in 6.2.287 ... but the info is still in
                    the tag list, since we can do :ta to get back there), then do a :bw by
                    name/number.

                    Also, I believe there is already a request to make 'gf's addressable
                    this way; at least I seem to recall discussion of it. Or maybe 'gf'
                    could be wrapped in a function which would do that.

                    >What's more, if you have minibuffer or equivalent running,
                    >things can get somewhat more stuffed up it seems.
                    >
                    >IMHO the quote above is indeed the most logical way to work
                    >and should be the default behaviour

                    I kind of, sort of, agree. This would necessitate maintaining a list of
                    buffer numbers for each window, which wouldn't be too difficult, and
                    ^W^Q could be used to quit the window immediately, abandoning said list,
                    but this would certainly necessitate another &cpo flag.

                    And what should be done on splits, copy the list from the current
                    window, start a new one with the current buffer, or start a new one with
                    *nothing* in it? I vote for the last, so a user isn't placed in the
                    situation where repeatedly backing up (unloading, deleting or wiping as
                    they go) wipes out the current window *and* it's parent when the
                    beginning of the list is reached (ie, it wouldn't back up any further
                    than beginning of the list, which does not include the buffer initially
                    loaded when the window was created). This would retain the window until
                    a :close or the like is issued.

                    > - and people that want to
                    >open new buffers, or scratch buffers, or any other kind of
                    >buffer which they haven't recently had open in the window in
                    >question, should write code to handle such customisations.
                    >
                    >Counter opinions (not to mention minibuffer customisations to
                    >implement this
                    >behaviour) most welcome,
                    >John
                    >
                    >
                    >
                    >
                  • John Orr
                    FYI - just added http://www.vim.org/scripts/script.php?script_id=1147 to do this task the way I think it should be done. John
                    Message 9 of 9 , Dec 1, 2004
                    • 0 Attachment
                      FYI - just added http://www.vim.org/scripts/script.php?script_id=1147 to do
                      this task the way I think it should be done.

                      John

                      > -----Original Message-----
                      > From: Keith Roberts [mailto:kroberts@...]
                      > Sent: Friday, 29 October 2004 5:36 PM
                      > To: overbored; vim@...
                      > Subject: RE: Quick: delete buffer & keep window
                      >
                      >
                      > >-----Original Message-----
                      > >From: overbored [mailto:overbored@...]
                      > >Sent: Friday, October 08, 2004 12:03 AM
                      > >To: vim@...
                      > >Subject: Quick: delete buffer & keep window
                      > >
                      > >Is it possible to delete a buffer (:bd) without closing the
                      > >window (and instead do something like switch to another
                      > >buffer)? Thanks in advance.
                      >
                      > Here's what I use:
                      > " Delete buffer, move to Alternate (or next)
                      > map <C-S-F4> :if bufnr('#') >
                      > 0\|:b#\|:else\|:bn\|:endif\|:bw#<CR>
                      > imap <C-S-F4> <ESC><C-S-F4>
                      > " Unload buffer, move to Alternate (or next)
                      > map <C-F4> :if bufnr('#') >
                      > 0\|:b#\|:else\|:bn\|:endif\|:bunload #<CR>
                      > imap <C-F4> <ESC><C-F4>
                      >
                      > ... and just for good measure ...
                      >
                      > " Delete buffer, move to Previous (does NOT remove window)
                      > map <C-S-F7> :bp<CR>:bw #<CR>
                      > imap <C-S-F7> <ESC><C-S-F7>
                      > " Unload buffer, move to Previous
                      > map <C-F7> :bp<CR>:bunload #<CR>
                      > imap <C-F7> <ESC><C-F7>
                      > " Unmapped
                      > map <S-F7> :echo "Unmapped!"<CR>
                      > imap <S-F7> <ESC>:echo "Unmapped!"<CR>l
                      > " Move to Previous buffer
                      > map <F7> :bp<CR>
                      > imap <F7> <ESC><C-F7>
                      >
                      > " Delete buffer, move to Next (does NOT remove window)
                      > map <C-S-F8> :bn<CR>:bw #<CR>
                      > imap <C-S-F8> <ESC><C-S-F8>
                      > " Unload buffer, move to Next
                      > map <C-F8> :bn<CR>:bunload #<CR>
                      > imap <C-F8> <ESC><C-F8>
                      > " Unmapped
                      > map <S-F8> :echo "Unmapped!"<CR>
                      > imap <S-F8> <ESC>:echo "Unmapped!"<CR>l
                      > " Move to Next buffer
                      > map <F8> :bn<CR>
                      > imap <F8> <ESC><C-F8>
                      >
                      > I uses the F7/F8 series to quickly traverse the buffer list in either
                      > direction, but now that I use locate and lid so much I more often use
                      > the F4 series.
                      >
                    Your message has been successfully submitted and would be delivered to recipients shortly.