-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Create alias to fast-edit a result #304
Comments
I don't think mucking about with shell aliases is something that belongs in ripgrep. It sounds like a maintenance nightmare. Does it work on Windows? Which shells does it support? I would, however, be amenable to making ripgrep's output format a bit more customizable. However, that will require some refactoring/design work that I'm not quite ready to tackle yet. That particular issue is tracked by #244. |
Note that it looks like ripgrep support will land in |
You can do this using peco and a shell function. Put this in your .zshrc / .bashrc / whatever: rg2vim() { vim $(rg -n $1 | peco | awk -F\: '{print "+"$2,$1}') } You can then just call |
This has the virtue of opening multiple selected files in individual tabs and skipping peco if there is only one match reported by rg. It does a horrible (read:none) job of escaping special characters though. Maybe someone can come up with something better rg2vim() { vim -c "$(rg -n $1 | peco --select-1 | awk -F\: 'BEGIN {ORS="|"}; {print (NR==1 ? "e " : "tabe ") $1"|:"$2}')" } |
Will try to integrate it into emacs. Have been running Vim for 7 years, I did the switch recently (with evil-mode, miam!). |
peco is a nicer alternative to tag. Thanks for the tips! |
EDIT: Moving the chat to Luke's dotfiles. lukaslueg/dotfiles#1 Hey @lukaslueg it's been some time from this thread but I noticed this in your dotfiles rg2vim() {
vim -c "$(
FL=0
while IFS=: read -r fn ln line; do
if [ "$FL" -eq "0" ]; then
printf "e %q|" "$fn"
FL=1
else
printf "tabnew %q|" "$fn"
fi
printf ":%d|" "$ln"
done < <(rg -n "$1" | peco --select-1)
)"
} Is this the latest and greatest solution? EDIT: Also any way to catch a Ctrl-C and prevent vim from opening? |
I never got around to such details. The "script" does not process Ctrl-C and just falls on it's nose if there is no |
Hello and thanks for this incredible work!
I am wondering if this would be hard to implement something similar to https://github.com/aykamko/tag? I can try if you want. The principle is simple: Generate one alias per results in a temporary file (so
e1
will open an editor to the first result —file and line—,e2
to the second result etc.; e.g.alias e1="$EDITOR +line file"
), source the alias (done by the shell, not by the command itself), that's it.The text was updated successfully, but these errors were encountered: