As an example, let's say I want to search for the word test
.
When I type M-x occur RET test RET
, the current frame is split into two windows, with the current buffer on top and the *Occur*
buffer on bottom. If I click a line in the *Occur*
buffer point is moved to the matching line in the top buffer. All this is fine..
But if I want to return to the original position in the top buffer, it is more difficult. First, there is no shortcut in the *Occur*
buffer to return to that original position in the searched buffer. I could of course as a workaround type C-x r b before I clicked the line in the *Occur*
buffer such that I got a bookmark. But I think this is not an ideal solution.
So the question is: Is it possible to add the original buffer position in the searched buffer as a single line in the *Occur*
buffer (for example, the topmost line) such that I can easily return to my starting point after visiting (that is: moving to) some matches from the *Occur*
buffer?
C-x r SPC
and later jump back withC-x r j
. If you use Helm, you can usehelm-occur
that allows you to visit match by pressingTAB
on the match for previewing. Then you can either jump to that match usingRET
or cancel withC-g
to return to original location. Here is a demo.icicle-occur
(C-c '
) to visit occurrences, then just useC-g
to return to the original position.