Vim, MiniBufExpl, NERDTree and the QuickFix window

Vim has been my editor of choice for many years now, but only recently have I really started tweaking and fine-tuning my configuration and plugins. I was inspired by this HackerNews thread and I now keep my vim configuration in GitHub and synchronized between all my machines. You can even check out a list of my Vim plugins. Some of my favorites, and the ones I’m writing this post about in particular, are:

  • NERDTree, a filesystem explorer
  • MiniBufExpl, an omnipresent buffer list enabling you to easily see what buffers are open and easily switch to and close them
  • Vim Ack, a plugin that provides a simple interface to the excellent Ack utility.

Life is great. Or it was, at least, until I started having strange problems with window layouts when I was waist deep in code. The first lesson I learned is that using Vim’s :bd command to close a buffer causes problems, namely that if you close the buffer in the current window, it will close the window as well. There are two fixes for this. First, after some Googling, I learned about bclose.vim. I mapped <leader>bd to run :Bclose and all was good. I later learned that MiniBufExpl included this functionality all along – simply place your cursor over a buffer in the buffer list and press “d”.

The second problem I ran into was that after using Ack to search through my project, MiniBufExpl would start opening buffers in unpredictable locations such as the NERDTree left vertical window. This was very frustrating and I was only able to get back to a sane editing environment after restarting the Vim session all together. It turns out that the problem was being caused by the way I closed the QuickFix window after browsing through the Ack search results. I was simply using :q, which is my reflex method of closing a window I don’t want around any longer. Some debugging and research shows that the QuickFix window has its rich set of commands, including an open (:copen) and close (:ccl or :cclose). Using :ccl to close my Ack results has solved this problem entirely.

Life with Vim is better than ever. If you’re a Vim user or have even considered it, I’d really recommend checking out some sample vimrc files, finding and installing some plugins you love, and most importantly keeping your configuration synchronized between all of your development machines.

UPDATE: It turns out that :ccl was not the simple fix I was hoping it would be. After using Ack, MiniBufExpl still sends buffers to the NERDTree window. HALP!

  • John Coulter

    You’ve probably figured this out by now, but I’ll post it for the benefit of others scouring the net. If you’re having the issue of MiniBufExpl opening buffers in NERDTree when NERDTree was the last active window, the following tip from the MiniBufExpl source should help:

    ” If you use other explorers like TagList you can (As of 6.2.8) put:

    ” let g:miniBufExplModSelTarget = 1

    ” into your .vimrc in order to force MBE to try to place selected
    ” buffers into a window that does not have a nonmodifiable buffer.
    ” The upshot of this should be that if you go into MBE and select
    ” a buffer, the buffer should not show up in a window that is
    ” hosting an explorer.

  • http://pagesofinterest.net/ Michael Robinson

    Thank you very much for posting this comment John!