24

I usually type :bd to remove the buffer, however, it results in undesirable side-effect of the window being closed which I do NOT want.

ib.
  • 27,830
  • 11
  • 80
  • 100
vehomzzz
  • 42,832
  • 72
  • 186
  • 216
  • 2
    this is my question: http://stackoverflow.com/questions/4298910/vim-close-buffer-but-not-splitted-window – RusAlex Dec 09 '10 at 22:17
  • possible duplicate of [Vim: Delete buffer without losing the split window](http://stackoverflow.com/questions/4465095/vim-delete-buffer-without-losing-the-split-window) – George Hilliard May 27 '15 at 18:44
  • Possible duplicate of [Vim close buffer but not split window](https://stackoverflow.com/questions/4298910/vim-close-buffer-but-not-split-window) – KevinG Apr 04 '19 at 18:34
  • If you just want that so you can do actions without being asked to save file (like `'0`, `:e another-file`), a workaround is `98u`. Easy to type and will clear probably every modification you've done to the file, freeing you from "having" to save it. – André Willik Valenti Aug 03 '22 at 21:53

4 Answers4

35

I usually use :bn (next buffer) followed by :bd# (delete alternate buffer). You could create a mapping or command for this, of course.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
9
nmap <leader>d :bprevious<CR>:bdelete #<CR>

Works as it should until one buffer is open in several windows. Good enough unless you want to use the bigger scripts out there.

ggustafsson
  • 603
  • 7
  • 13
4

I'm not sure if icecrime's bufclose plugin link is based on the same thing, but the Vim Tips Wiki shows a couple of different approaches via a script. Check them out.

Jason Down
  • 21,731
  • 12
  • 83
  • 117
  • actually I think this one's better – icecrime Dec 09 '10 at 22:15
  • I just noticed the see also section near the bottom of the wiki page. It mentions bufclose there, along with this comment: not useful because it doesn't work as expected (if you close a buffer that's open in several windows, those windows close). So I guess there is an issue with bufclose. – Jason Down Dec 09 '10 at 22:18
0

Try kwbdi(Keep Window on Buffer Delete) plugin. Worked well for me.

Pete
  • 1,305
  • 1
  • 12
  • 36
Rumple Stiltskin
  • 9,597
  • 1
  • 20
  • 25