Using the quickfix window without losing focus

1,255 views
Skip to first unread message

Jonathan del Strother

unread,
May 14, 2012, 4:04:33 AM5/14/12
to v...@vim.org
Hi,
I'm using fugitive's :Ggrep (a git-based wrapper around vimgrep) to
scan for occurrences of a word in my project, viewing them in the
quickfix window. I end up with quite a few results, and it's not
obvious which file I'm interested in without opening the file. When I
hit enter in the quickfix window, it opens that file and moves the
cursor focus to the new buffer. Is it possible to keep the focus in
the quickfix window, so I can just hit enter, realise it's not the
file I'm looking for, hit down/enter, and repeat?

Karthick Gururaj

unread,
May 14, 2012, 5:52:45 AM5/14/12
to vim...@googlegroups.com, v...@vim.org
You can map the <CR> key?
E.g:

:noremap <CR> <CR><C-W><C-P>

Or,
:noremap <CR> <CR><C-W><C-P>j
(saves one more keystroke).

Better to put that in autocmd for filetype as 'qf'.

(disclaimer: works for quickfix, haven't used :Ggrep).

John Beckett

unread,
May 14, 2012, 6:43:30 AM5/14/12
to vim...@googlegroups.com
Karthick Gururaj wrote:
>
> :noremap <CR> <CR><C-W><C-P>

Yes, however it should be a buffer mapping, and you might like
to use a different key, such as o to open the file:

nnoremap <buffer> o <CR><C-W>p

Put the above line in file ~/.vim/after/ftplugin/qf.vim (Unix)
or file $HOME\vimfiles\after\ftplugin\qf.vim (Windows).
Create any missing directories.

John

Jonathan del Strother

unread,
May 14, 2012, 6:56:43 AM5/14/12
to vim...@googlegroups.com
On 14 May 2012 11:43, John Beckett <johnb....@gmail.com> wrote:
> Karthick Gururaj wrote:
>>
>> :noremap <CR> <CR><C-W><C-P>
>
> Yes, however it should be a buffer mapping, and you might like
> to use a different key, such as o to open the file:
>
> nnoremap <buffer> o <CR><C-W>p
>
> Put the above line in file ~/.vim/after/ftplugin/qf.vim (Unix)

Nifty, thanks.

Ben Fritz

unread,
May 14, 2012, 11:34:31 AM5/14/12
to vim...@googlegroups.com, v...@vim.org

You can navigate between entries without leaving the quickfix list using :cnext and :cprev commands. Both of these take a count if you want to skip a few entries. But going to a specific entry in the middle of the list somewhere would be difficult without a mapping-based solution like John and Karthick gave.

Reply all
Reply to author
Forward
0 new messages