Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return to vgrep from Editor #177

Open
mjklemm opened this issue May 5, 2022 · 5 comments
Open

Return to vgrep from Editor #177

mjklemm opened this issue May 5, 2022 · 5 comments

Comments

@mjklemm
Copy link

mjklemm commented May 5, 2022

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?

@vrothberg
Copy link
Owner

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.

@mjklemm
Copy link
Author

mjklemm commented May 13, 2022

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.

@vrothberg
Copy link
Owner

Thanks for sharing, @mjklemm!

@suvayu
Copy link
Contributor

suvayu commented Dec 19, 2023

There's no need for a custom script if you use this bind option: --bind "enter:execute:vim {2} +{3}"

@mjklemm
Copy link
Author

mjklemm commented Dec 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants