Ripgrep 14 Released
297 points by timf 1 year ago | 71 comments- akprasad 1 year agoAndrew sets an extremely high bar for open-source engineering. As a loose member of the broader Rust community, I've benefited enormously not only from his code but also from his discussion comments and his blog posts (especially [1] and [2]).
Congratulations on the release, Andrew! I also notice that you've joined Astral [3], which as a fan of Rust/Ruff/rg I'm thrilled about.
[1]: https://blog.burntsushi.net/transducers/
- burntsushi 1 year ago<3
- burntsushi 1 year ago
- insanitybit 1 year agoThere is a distinct joy in showing someone rg who has never seen it before and then seeing them immediately adopt it as a daily tool.
Recently a colleague had a bug. He told me it was related to the "X" that was weirdly behaving like a "Y".
I fd'd "X" and then rg'd the resulting files for "Y" and found a place where some copy/pasted code was treating "X" as a "Y". Big monorepo codebase, absolutely just tore through it and solved the entire bug.
- blindriver 1 year agoThis happened to me. The codebase I work with is hundreds of gigabytes and I was using find --exec grep, and my coworker showed me rg and I couldn't believe what I was seeing. It's a beautiful and amazing tool.
- Matthias247 1 year agoSince Visual Studio Code is using ripgrep for search one can also open the repo in the editor and use find in files to search for such things similar performance. It’s one of my favorite tools for searching specific expressions in codebases.
- carlmr 1 year agoThat's why I initially jumped on the VSCode bandwagon. I'm slightly miffed that nowadays the search is much slower than ripgrep. I see myself using ripgrep from the VSCode console.
I don't think it's ripgrep itself, it's something with the way VSCode manages extensions, and doesn't give you enough information to debug which extension is blocking it.
- insanitybit 1 year agoI always just find it faster to put a command argument together tbh
- carlmr 1 year ago
- blindriver 1 year ago
- ashton314 1 year agoIf you are an Emacs user like me, you must try out the consult-ripgrep command from the peerless Consult [1] package by Daniel Mendler: search your whole project with ripgrep and get a live preview of every matching candidate all inside of Emacs!
- TacticalCoder 1 year agoAnd for those who are also on Emacs but on the Swiper/avy/ivy/counsel side of the fence, there's counsel-rg.
I use it since before burntsushi (who's here on HN btw)'s ripgrep was shipped with Debian stable!
> search your whole project with ripgrep and get a live preview of every matching candidate all inside of Emacs
I'm sometimes searching not just my project but my entire user dir or my entire shared drive, from Emacs. A NVMe PCIe 4.0 SSD (I'm using a WD SN850X which someone here recommended to me when I assembled my PC) is that fast and ripgrep too.
- oakpond 1 year agoEn garde! If you're a Vim user, fzf.vim [1] can do this. :)
- nerdponx 1 year agoIf you don't need live updating output, you can just set grepprg and get results in the quickfix list with :grep[!] (or the location list with :lgrep[!]).
No need for Fzf/Telescope/Denite/DDU or anything else in that case.if executable('rg') let &grepprg = 'rg --vimgrep $*' endif
See:
- a-dub 1 year agoused to do that with glimpse when i worked with very large codebases 23 years ago!
big fan of ag, ripgrep and burntsushi's rust work!
- a-dub 1 year ago
- bombela 1 year agoAnd if you want interactive support, try https://github.com/bombela/fzf.vim.rgfd
(shameless plug)
- nerdponx 1 year ago
- clircle 1 year agoYep, the consult suite and rg are two of my favorite things. And I'm not even a SWE.
- Barrin92 1 year agoam a big fan of the whole consult/vertico/embark stack of emacs plugins. They're fantastic.
- brunoqc 1 year agodeadgrep is nice too
- TacticalCoder 1 year ago
- skunkworker 1 year agoRipgrep is probably my favorite command line tool (which replaces older solutions). It’s just so quick to search a folder for a specific line of text in a file.
- coldtea 1 year agoSame here... the program I use most aside from my editor.
In fact my current editor, VS Code, also does searching powered by rg behind the scenes:
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/node_modules.asar.unpacked/vscode-ripgrep/bin/rg
- coldtea 1 year ago
- anotherpaulg 1 year agoMy muscle memory is still dialed in to `ack`, but I recently built an open source tool called `grep-ast` [0] that serves a similar function to ripgrep, ack, etc. The difference is that it shows matching lines in the context of the functions/methods/classes/etc that contain them.
It uses the abstract syntax tree (AST) of the source code to show how the matching lines fit into the code structure. It shows relevant code from every layer of the AST, above and below the matches.
It feels quite useful when you're grepping to understand how functions, classes, variables etc are used within a non-trivial codebase.
Here's a snippet that shows grep-ast searching the django repo. Notice that it finds `ROOT_URLCONF` and then shows you the method and class that contain the matching line, including a helpful part of the docstring. If you ran this in the terminal, it would also colorize the matches.
[0] https://github.com/paul-gauthier/grep-astdjango$ gast ROOT_URLCONF middleware/locale.py: │from django.conf import settings │from django.conf.urls.i18n import is_language_prefix_patterns_used │from django.http import HttpResponseRedirect ⋮... │class LocaleMiddleware(MiddlewareMixin): │ """ │ Parse a request and decide what translation object to install in the │ current thread context. This allows pages to be dynamically translated to │ the language the user desires (if the language is available). ⋮... │ def process_request(self, request): ▶ urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
- rtpg 1 year agohave you looked at semgrep? This isn't the same thing but is similarly poking at the whole "ASTs are a thing we want to grep at" problem
- anotherpaulg 1 year agoThanks for the pointer. There are definitely a few tools that have explored the idea of searching the AST of code. Semgrep seems to do that, as does a tool called ast-grep [0].
Both of them are sort of doing the opposite of my tool. They are letting you specify your search as a chunk of code/AST.
My tool let's you grep a regex as usual, but shows you the matches in a helpful AST aware way.
- anotherpaulg 1 year ago
- indymike 1 year agoThanks for making this. Immediately useful.
- rtpg 1 year ago
- grudg3 1 year agorg is great, I use it a lot. Recently I have also used [ambr](https://github.com/dalance/amber) which can do both search (ambs) and replace (ambr) recursively in your codebase. The only problem as of yet is that it does not support globbing so I cannot filter on certain filetypes only.
- nextaccountic 1 year agoSee also ast-grep
https://github.com/ast-grep/ast-grep/
> ast-grep is a AST-based tool to search code by pattern code. Think it as your old-friend grep but it matches AST nodes instead of text. You can write patterns as if you are writing ordinary code. It will match all code that has the same syntactical structure. You can use $ sign + upper case letters as wildcard, e.g. $MATCH, to match any single AST node. Think it as REGEX dot ., except it is not textual.
- coldtea 1 year agoYou could use "find" (or even better, "fd") to find specific filetypes, then pass it to amber via xargs or some similar way.
- wwarner 1 year agoThis use case is a killer feature of emacs. Rg supports wgrep (writable grep). `rg` to match lines, and then in the resulting buffer, `e` to edit the results and save the changes back to the matched files.
- nicoburns 1 year agohttps://github.com/facebookincubator/fastmod is also great for the replace usecase.
- mirashii 1 year agoI'll throw in sd as a nice sed/find-and-replace tool. Using fd + xargs + sd is a pretty good workflow if a shell glob isn't good enough to target the files you want. https://github.com/chmln/sd
- cstrahan 1 year agoI’ll also throw in Leah Neukirche ‘s xe as a better alternative to xargs: https://github.com/leahneukirchen/xe
- ForkMeOnTinder 1 year agoI wanted to like sd but it doesn't support my main use case of recursive search/replace. Imagine if every time you wanted to grep some files you had to build a find -print0 | xargs | rg pipeline... it just takes me out of the flow too much. I'm glad people are posting other options here, I'm looking forward to trying them.
- oftenwrong 1 year agoIf you haven't discovered recursive path expansion with `**` yet, which is supported by a number of popular shells, including bash, it is about to improve your shell life.
- oftenwrong 1 year ago
- cstrahan 1 year ago
- nextaccountic 1 year ago
- markussss 1 year agoI use Ripgrep daily, and it helps me a lot when navigating codebases, and I even use it to search through my notes. A while ago, I made a script that looks for file paths in the output from Ripgrep in order to turn the paths into clickable links, as I couldn't get it to work properly back then. I'm so happy to hear that «the headlining feature in this release is hyperlink support»! I'm really looking forward to using the new update.
- goalieca 1 year agoI’m not an rg wizard by any means, but it is one of the few utilities that I end up using daily for one reason or another.
- lelandbatey 1 year agoThe notes state that the headline feature is "hyperlink support". However, the notes don't seem to really explain what that means. Can someone explain a bit more about what that feature does/is? What's a use case?
- coldtea 1 year agoSo, when you search for "foo" in mydir/, rg can find the term foo inside different places in a number of files, and then print the results like:
Hyperlink support means that the line numbers (15, 78, 123) are clickable, and will open your favorite editor to that file and that line number.mydir/myfile.java 15: return foo; 78: System.out.println(foo); 123: // TODO: change foo to bar
That's if your terminal supports hyperlinks, or has hyperlink support enabled - most do. Depending on the terminal app it might be control/cmd click, or option-click to open the hyperlink.
Note (this got me while trying): hyperlinks are not emitted when you search inside a specific file directly, e.g. "rg foo myfile.py".
- lelandbatey 1 year agoI'm fascinated! I've been living with and authoring CLI tools for about a decade now and I didn't know that there's widespread support for additional attributes on text besides styling (color, italics, underline, etc) in common terminal emulators. What a cool thing!
- burntsushi 1 year agoFor the single file case, if you pass --with-filename then it should work.
- lelandbatey 1 year ago
- citruscomputing 1 year agoSibling comments have explained, but the keyword to search to learn more is "OSC-8 hyperlinks"
- kzrdude 1 year agoTerminals (some terminals) support hyperlinks and it creates clickable links. For example ls -l --hyperlink=auto If you terminal supports it, you can click the names.
See here for more info: https://github.com/Alhadis/OSC8-Adoption/
- burntsushi 1 year agoIt creates links in the output. You click them. It opens the file. That's pretty much it.
- coldtea 1 year ago
- bomewish 1 year agoExtra life hack for Mac users — you can use mdfind first and then pipe those results into rg with xargs. Even faster. Mdfind has an index already so the results are almost instant even across huge numbers of files. Major qol improvement.
- e12e 1 year agoThanks for the pointer - I was unaware of:
- e12e 1 year ago
- piinbinary 1 year agoI'm still sad that --sort-files makes ripgrep run in single-core mode. (I know you can't make --sort-files _free_ in multi-core mode, but it would still be faster than single-core)
- gkfasdfasdf 1 year agoThe shell function from this comment works pretty well for me: https://github.com/BurntSushi/ripgrep/issues/152#issuecommen...
- insanitybit 1 year agoSeems like the issue pretty much covers this.
- gkfasdfasdf 1 year ago
- leonheld 1 year agoI'm very thankful for ripgrep, ag and fzf.
- coldtea 1 year agoI don't seem to get the hyperlinks with either Terminal or iTerm.
P.S. OK found it: it can't show hyperlinks when you explicitly pass a file name to search (for internal implementation reasons, might be fixed later). It works when you search in directories etc.
- ziml77 1 year agoHyperlink support? Hell yes! This has been such a frustration of using terminal tools to search in files. I love that the vscode format even linkifies by matched line. Thanks for this update burntsushi!
- thiht 1 year agoWhat does « hyperlink support » mean? The release notes don’t give details, except that it’s supported.
- nbenitezl 1 year agoYou have one explanation here: https://wezfurlong.org/wezterm/hyperlinks.html#explicit-hype...
- thiht 1 year agoThanks! I didn’t realize there was an escape sequence for hyperlinks
- thiht 1 year ago
- nbenitezl 1 year ago
- thiht 1 year ago
- dharmab 1 year agoRipgrep is an essential tool for navigating unfamiliar codebases. I also use it to quickly search many repositories for specific symbols when I research the consumers of libraries and APIs.
- tgv 1 year agoWhat's the improvement this time? Translate DFAs to microcode?
- burntsushi 1 year ago
- boulos 1 year agoI appreciated the Sherlock Holmes joke:
> $ regex-cli find match pikevm --no-table -p '\b\w+\b' -y 'Σέρλοκ Χολμς'
0:0:12:Σέρλοκ
0:13:23:Χολμς
- boulos 1 year ago
- burntsushi 1 year ago
- scrame 1 year agoso... its grep to ack to ag to rg, is there something next?
- bomewish 1 year agoCat to bat
- pdimitar 1 year agofind -> fd
- fuzztester 1 year agols to exa
- 29athrowaway 1 year agogit to tig
- bomewish 1 year ago
- forgotusername6 1 year agoThe release notes use the word "headling" twice instead of presumably "headline". I had to look it up in case this was a new usage of this archaic word.
- burntsushi 1 year agoAh nice catch! I meant to say "headlining." Fixed now.
- vram22 1 year agoI hope you used rg to catch the catch :)
#eatyourowndogfood
- vram22 1 year ago
- burntsushi 1 year ago
- vram22 1 year agoThere was also ack (IIRC) written in Perl, earlier.
- andrewstuart 1 year agoI wish Jetbrains would integrate ripgrep into Pycharm as a native feature.
- T3RMINATED 1 year ago[dead]