Instead of unmap
I simply did a buffer-local (:h :map-local
) mapping back to the original values...
augroup QuickFix
au FileType qf map <buffer> j j
au FileType qf map <buffer> k k
augroup END
Ran vimgrep
per your example and in the quickfix window I have j
/k
behavior while still maintaining gj
/gk
function in the main window.
Update: Interesting (and somewhat lengthy) side bar regarding the mapping commands used above. @LucHermite asked a valid question in the comments: "Shouldn't [the auto commands use] noremap
?" He asked because what happens with map
and the other non-noremap mapping commands is that keys on the RHS of a defined mapping retain any mappings they already have. This can actually result in a kind of "infinite loop" where a LHS key triggers a RHS key that is mapped to the LHS key which triggers the mapped keys again and repeat, ad infinitum.
It seems pretty clear then that map j j
should result in just such an endless cycle. But it works fine. How? Well, there is a specific exception to the behavior I described which is noted in :h recursive_mapping
:
If the {rhs} starts with {lhs}, the first character is not mapped again.
For example:
:map ab abcd
will execute the "a" command and insert "bcd" in the text. The "ab" in the
{rhs} will not be mapped again.
That being said, I'm normally a stickler for using the noremap commands. I just kind of locked in on the fact that map
works correctly and answers OP's question but noremap
is better because, at the very least, it's a good idea to get in the habit of using it always unless you know explicitly that you need map
.
TL;DR: Though both are valid I recommend using noremap
instead of map
in the auto commands above.