You can make the process of reviewing the grep matches smoother by using the emacs way of interacting with the *Compilation*
family of buffers.
This solution does not specifically solve your question on how to show the matched line without moving the cursor but it helps you navigate the grep results as probably intended in emacs.
Here are the steps:
- Run grep using
M-x grep
. For the sake of example, let's say you are running grep in your ~/.emacs.d/
and you enter the grep arguments as require *.el
.
- Now here are few default bindings and commands that will help you navigate the results in a convenient manner while the point is in the actual file buffer on the matched line:
M-x next-error
to navigate to the next grep result. The default bindings are M-g M-n
or C-x `
.
M-x previous-error
to navigate to the previous grep result. The default binding is M-g M-p
.
M-x first-error
to navigate to the first grep result.
Do not be confused by the term 'error' in the functions above. It is a generic term used in *Compilation* buffers.