When I am working with vim, I occasionally end up with a split menu setup like this:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | | #
###############################################
Even when tagbar is closed, I may end up with a comparable setup, for example when I compare different files.
However, when I do a vimgrep command the results (displayed in a quickfix list) are only displayed below the main window, when tagbar (or other splits at the right) are closed.
Hence, this setup works correctly every time:
###############################################
# | #
# | #
# NERDTree | main window #
# | #
# | #
# |__________________________________#
# | #
# | quickfix list: vimgrep results #
# | #
###############################################
...while this does not:
###############################################
# | | #
# | | #
# NERDTree | main window | tagbar #
# | | #
# | |________#
# | | quick- #
# | | fix #
# | | list: #
# | | vimgrep#
# | | results#
###############################################
How can I enforce the quickfix list to always open (containing the vimgrep results) below the main window?
At the moment it just opens up correctly (below the main window) if - and only if - there is no other split window right to the main window. If any split exists right to the main window, the vimgrep command always opens quickfix there :/
I've bound searching for the word currently under the cursor with a vimgrep command (to search for this word in the entire file):
nnoremap some-key :execute "vimgrep /\\<" . expand("<cword>") . "\\>/j ".expand("%") <Bar> cw<CR>
...just to show what I am doing with vimgrep.
Sadly Vim does not have a concept of a project drawer just windows (splits). After using a command to open the Quickfix list, e.g. :copen
or :cwindow
, it would probably be best to close then open NerdTree and Tagbar. Something like this:
command! Copen copen|NERDTreeToggle|TagbarClose|TagbarOpen
Note: I have not tested this command as I do not have NERDTree or Tagbar plugins. This also focuses the Tagbar window which is probably undesired.
Alternatively, you may want to look into simplifying your workflow by keeping both tagbar and nerdtree closed unless you are using them. This can make sense for some workflows as needing to see either the tags or file structure can be relatively uncommon (maybe 10% of the time). For tags you can just avoid tagbar entirely and use the :tag
command directly or use <c-]>
if you are on a symbol. Nerdtree can be used in the same manner as netrw to avoid this issue (See Oil and vinegar - split windows and the project drawer). I talk about these issues in the post: Files, Buffers, and Splits Oh My!
Personally I don't use NerdTree, Tagbar, or anything similar. I prefer to have 1-2 splits open at a time. I use projectionist.vim, a fuzzy finder like CtrlP, :find
, or if I really must netrw.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With