0

So when I have the quickfix window open in Vim with a list of files in it, to look at a particular file, while in the window, I navigate up or down to go to select the one I want and press enter to see it.

I want quickfix to open the file for viewing immediately as I focus on a file without having to press enter. For example, if I have a list of git versions for a file in the quickfix window, I'd like to go down one by one and see the file in the other window as I go down the list.

That way I can smoothly look at how this file "evolved" in git history by just scrolling down or up the list.

I'm open to using a plugin that would do this too.

user938883
  • 126
  • 2
  • 5

1 Answers1

1

FWIW, my vim-qf plugin has a o mapping that could be of help:

" in after/ftplugin/qf.vim
nmap <buffer> <Down> <Down>o
nmap <buffer> <Up> <Up>o

If you don't want to pull the whole thing just for this use case, the mapping in question is very simple:

nnoremap <silent> <buffer> o <CR><C-w>p

so you can integrate the RHS directly in your own mappings:

" in after/ftplugin/qf.vim
nnoremap <buffer> <Down> <Down><CR><C-w>p
nnoremap <buffer> <Up> <Up><CR><C-w>p

next/previous

--- EDIT ---

To be perfectly clear, I mentioned my plugin for context but the proposed solution doesn't require that you install it.

All it requires is that you create a after/ftplugin/qf.vim file in your personal runtime directory (~/.vim/ on Unix-like systems) and that you put the following lines in it:

nnoremap <buffer> <Down> <Down><CR><C-w>p
nnoremap <buffer> <Up> <Up><CR><C-w>p

You don't need my plugin at all for that.

Now… the <buffer> in the mappings above is there to tell Vim to create those mappings only for the current buffer. Your vimrc is sourced very early in the startup process, before any buffer is created so, when Vim executes those lines it does its best to honor your wish by creating the mappings for the first buffer only, which is generally useless.

The intent, here, is to have those mappings only in the quickfix window. Since the buffer displayed in that window has the qf filetype, it means that we must create that mapping only for buffers with that filetype. The proper way to do it is to put those mappings in the relevant ftplugin, which will be sourced every time we load a quickfix list in the quickfix window.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thanks @romainl. I put ``` nnoremap p nnoremap p ``` In my .vimrc and it didn't seem to have any effect in my quickfix window. Do you mean I need to install `vim-qf` first before it will work? – user938883 Apr 17 '23 at 03:59
  • I wrote `" in after/ftplugin/qf.vim`, not `" in your vimrc`. – romainl Apr 17 '23 at 07:04
  • Of course, duh, sorry @romainl. I installed it and put in the last line of qf.vim and it worked great, exactly what I was looking for. Thank you! Now, if you'd like to humor this newb some more, why did the mappings work in the plugin, but not in my .vimrc? I obviously don't know what's going on here. – user938883 Apr 19 '23 at 22:26