6

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.

daniel451
  • 10,626
  • 19
  • 67
  • 125

3 Answers3

2

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.

Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
2

You can force quickfix to open on full width with this code in your .vimrc:

augroup DragQuickfixWindowDown
    autocmd!
    autocmd FileType qf wincmd J
augroup end

It is now what was asked but it is as close to it as I could get.

ephemerr
  • 1,833
  • 19
  • 22
0

I found a good solution here, just put the text below in your vimrc. It will always move quickfix window to the bottom of your screen with full width and without affecting other quickfix stuff.

" Position the (global) quickfix window at the very bottom of the window
" (useful for making sure that it appears underneath splits)
"
" NOTE: Using a check here to make sure that window-specific location-lists
" aren't effected, as they use the same `FileType` as quickfix-lists.
autocmd FileType qf if (getwininfo(win_getid())[0].loclist != 1) | wincmd J | endif
Aaron
  • 1
  • 2