Skip to main content
  1. Posts/

Fixing the nerdtree Window Problem with `bd` Command in Nvim

··175 words·1 min·
Table of Contents

If you have a nerdtree file navigation window on the left of the current buffer and use :bd1, you will find that the nerdtree window will occupy the whole window. When you open another buffer, you have to manually resize the nerdtree window to a smaller size, which is super annoying.

How to prevent this behaviour?

An easy way is to switch to another buffer first, and then delete the previous buffer. We can create a shortcut for this:

nnoremap \d :bp<cr>:bd #<cr>

In the above command, :bp stands for :bprevious, which will change the buffer to the previous buffer. # after the :bd command represents the last used buffer, i.e., the buffer we want to delete.

There is also a Nvim plugin called vim-bufkill, which specifically address this issue. After installing this plugin, you can use :BD to delete the current buffer without closing the window.

References
#


  1. In Nvim, bd[elete] will delete the current buffer. But the window for the current buffer will also be closed. ↩︎

Related

Generating Table of Contents for Markdown with Tagbar
··355 words·2 mins
Show Git Diff When Doing Git Commit
··260 words·2 mins
Why Doesn't Jedi Autocompletion Work for Some Methods
··468 words·3 mins