function frg {
$result = rg --ignore-case --color=always --line-number --no-heading @Args |
fzf --ansi `
--color 'hl:-1:underline,hl+:-1:underline:reverse' `
--delimiter ':' `
--preview "bat --color=always {1} --theme='Solarized (light)' --highlight-line {2}" `
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
if ($result) {
& ($env:EDITOR).Trim("`"'") $result.Split(': ')[0]
}
}
There are other ways to approach this, but for me this is a very fast way of nailing down 'I now something exists in this multi-repo project but don't know where exactly nor the exact name'edit this comes out of https://github.com/junegunn/fzf/blob/master/ADVANCED.md and even though you might not want to use most of what is in there, it's still worth glancing over it to get ideas of what you could do with it
[1] https://github.com/phiresky/ripgrep-all/wiki/fzf-Integration
function frg {
result=`rg --ignore-case --color=always --line-number --no-heading "$@" |
fzf --ansi \
--color 'hl:-1:underline,hl+:-1:underline:reverse' \
--delimiter ':' \
--preview "bat --color=always {1} --theme='Solarized (light)' --highlight-line {2}" \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'`
file="${result%%:*}"
linenumber=`echo "${result}" | cut -d: -f2`
if [ ! -z "$file" ]; then
$EDITOR +"${linenumber}" "$file"
fi
} fza = "!git ls-files -m -o --exclude-standard | fzf -m --print0 | xargs -0 git add"
With that in the [alias] section of a gitconfig file, running git fza brings up a list of modified and not yet added files, space toggles each entry and moves to the next entry.That alias as well as fzf+fd really speed up some parts of my workflow.
Oh and shameless plug for my guide on what to include in your zsh setup on macOS: https://gist.github.com/aclarknexient/0ffcb98aa262c585c49d4b...
How do you scroll the preview window with keyboard ?
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
The Xref key sequences and commands work fine with it. If I type M-. (or C-u M-.) to find definitions of an identifier in a Python project, dumb-jump runs a command like the following, processes the results, and displays the results in an Xref buffer. rg --color never --no-heading --line-number -U --pcre2 --type py '\s*\bfoo\s*=[^=\n]+|def\s*foo\b\s*\(|class\s*foo\b\s*\(?' /path/to/git/project/
The above command shows how dumb-jump automatically restricts the search to the current file type within the current project directory. If no project directory is found, it defaults to the home directory.By the way, dumb-jump supports the silver searcher tool ag too which happens to be quite fast as well. If neither ag nor rg is found, it defaults to grep which as one would expect can be quite slow while searching the whole home directory.
Ripgrep can be used quite easily with the project.el package too that comes out of the box in Emacs. So it is not really necessary to install an external package to make use of ripgrep within Emacs. We first need to configure xref-search-program to ripgrep as shown below, otherwise it defaults to grep which can be quite slow on large directories:
(setq xref-search-program 'ripgrep)
Then a project search with C-x p g foo RET ends up executing a command like the following on the current project directory: rg -i --null -nH --no-heading --no-messages -g '!*/' -e foo
The results are displayed in an Xref buffer again which in my opinion is the best thing about using external search tools within Emacs. The Xref key sequences like n (next match), p (previous match), RET (jump to source of match), C-o (show the source of the match in a split window), etc. make navigating the results a breeze!Looking at your regex---just by inspection, I haven't tried it, so I could be wrong---but I think you can drop the --pcre2 flag. I also think you can drop the second and third \b assertion. You might need the first one though.
You can find the rg binary in the VS installation (at least, I can on Windows at my place of employment).
Random other helpful flag I use often is -M if any of the matches are way too long to read through and cause a lot of terminal chaos. Just add `-M 1000` or adjust the number for your needs and the really long matches will omit the text context in the results.
Also the fact that it is a standalone portable executable can be super handy. Often when working on a new machine, I'll drop in the executable and an alias for grep that points to rg, so if muscle memory kicks in and I type grep it will still use rg.
I use ag (typically from inside Emacs) on a 900k LOC codebase and it is effectively instantaneous (on a 16 core Ryzen Threadripper 2950X). I just don't have a need to go from less than 1 second to "a bit less than less than 1 second".
Speed is not the defining attribute of the "new greps" - they need to be assessed and compared in other ways.
But as I mentioned in my comparison to qgrep elsewhere in the thread, everyone has different workloads. And for some workloads, perf differences might not matter. It really just depends. 900 KLOC isn't that big, and indeed, for simple queries pretty much any non-naive grep is going to chew through it very very quickly.
As for comparisons in other ways, at least for ag, it's on life support. I thought it was going to get removed from Debian, but it looks like someone rescued it: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=999962
The blog post also compares Unicode support, and contextualizes its performance. ag essentially has zero Unicode support. Unicode support isn't universally applicable of course---you may not care about it---but it satisfies your non-perf comparison criteria. :-)
this above all true UNLESS you need multi-line matches with UTF8, where ripgrep is not so fast, because it needs to fall back to the other PCRE2 lib
The optional Google search syntax also very convenient.
[1]: https://github.com/minad/consult#grep-and-find [2]: https://lambdaland.org/posts/2023-05-31_warp_factor_refactor...
For those just using it to search through a codebase, don't forget -F for string literals.