Is there a way to "lock" the viewport in vim?

I recently started using Vim with NERDTree. The annoying thing is when I close the buffer, NERDTree expands to fill the rest of the screen, and I have to open another file and reopen NERDTree to get it back to the old layout.

Is there a way to "lock" NERDTree in place? Ideally, closing a buffer would replace it with another buffer that's hidden, or open a new blank buffer if no other buffers are open.

Thanks!


i do not think so. the only solution which comes to mind is to create a new keybinding which

  • :vnew
  • ctrl-w left
  • ctrl-w q

instead of just closing the current buffer.


Take a look at http://github.com/carlhuda/janus, it's a customised version of vim that let's you keep nerdtree locked on the left. It also includes many other popular plugins like command-t, ctags and ack.


Try bufkill. It's built to solve this exact problem.

Instead of :bd to close your buffer, you use :BD. This prevents the window from being closed just because you killed the buffer. If there isn't another available buffer to replace it with, an empty buffer is opened.