Return to vgrep from Editor
mjklemm opened this issue · 5 comments
Not a real issue, more a question. :-)
Is there a way to return to vgrep/fzf after opening a match in the editor? I'm using the bvgrep alias from the README for interactive searching and it would dramatically speedup things if I could go to a match by selecting it in the fzf list, then quit the editor and return to the (interactive) search that had before.
Any chance that this could work?
Thanks for reaching out, @mjklemm!
I have absolutely no experience using fzf, and really don't know if or how this could work. I rarely use or need an interactive mode but when I do, I use vgrep --interactive
which will bring me back to vgrep when returning from the editor.
I will leave this issue open. Maybe someone in the community has an answer.
I have hacked a bit on this and I have come up with this "solution" (it's still very hacky, but it might give people a hint on what can be done).
This alias triggers the search with vgrep
and uses fzf
to presen the results:
vg() {
vgrep --no-header --no-less "$1" | fzf --ansi --bind "enter:execute:vgrep-vim.sh {}"
}
The vgrep-vim.sh
script then further processes the selected result to open Vim:
#!/bin/bash
file="$(echo $@ | sed 's/[0-9]* \(.*\) [0-9]* .*/\1/')"
line="$(echo $@ | sed 's/[0-9]* .* \([0-9]*\) .*/\1/')"
vim "$file" +"$line"
I'm sure that this is not the most efficient way to do this, and for sure it will break for certain corner cases, but it seems to work well enough for me.
There's no need for a custom script if you use this bind option: --bind "enter:execute:vim {2} +{3}"
There's no need for a custom script if you use this bind option:
--bind "enter:execute:vim {2} +{3}"
Thanks! That's indeed very useful and quite simplifies the script. I still have, as it makes it easier for me to switch editors w/o changing the ZSH alias I have created.