Emacs has a pretty great feature called “Occur” and to use it you do the ol’ M-x occur. But I’m a Vim user, and so this is the solution I’ve come up with:
nmap g/ :vimgrep /<C-R>//j %<CR>\|:cw<CR>
So my work flow is as follows:
I search for what I’m trying to find with the usual
/my query<CR>.If I didn’t hit what I was looking for then I hit
g/and find the line containing what I’m looking for and hitto be taken there.
If this isn’t your work flow, you could create a function that takes your query
as input and uses that as your pattern instead of what you last searched for
(the <C-R>/ part). Or if you’re not a fan of the QuickFix buffer, what I
previously used was nmap g/ global//print, but I feel what I have now is
superior.