Live data from Hacker News

Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

blog.burntsushi.net

141–150 of 198 posts

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#141
post #132
post #98

I've been using ripgrep for about 2 years now and I find in indispensable. The main reason I switched from grep was ease of use. From the README: "By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files." Typing `rg search_term directory` is much better than the corresponding grep command, but the speed improvement is also a nice bonus. Random other helpful fl…

Yeah, the -M command is wonderful (super handy for ignoring minified files that you don't want to see results from, etc), and also great is the -g command (eg `-g *.cs` and you'll just search in files that have the .cs extension). 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…

If you're a fan of the -g flag to ripgrep then I also recommend checking out the -t flag, short for --type, which lets you search specific file types. You can see the full list with `rg --type-list`. For example, you could just search .cs files with `rg -tcs`.

This flag is especially convenient if you want to search e.g. .yml and .yaml in one go, or .c and .h in one go, etc.

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#142

Earlier quoted context omitted.

Vim is almost broken for me without fzf+rg. Feels like I’m manually grinding coffee instead of using electricity.

Which integration for ripgrep do you use with Vim?

I modified some functions from: https://github.com/junegunn/fzf.vim

And added my keyboard shortcuts.

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#143

Earlier quoted context omitted.

1. Thanks for this, instantly added to my dotfiles 2. You nerd-sniped me into getting rid of the unnecessary `cut` process :) file=${result%%:*} line=${result#*:} line=${line%%:*}

Thanks! I have tried using bash substitution to solve it but failed (I just learned the difference between "#" and "##").

FYI, these substitutions are POSIX:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

Also a couple mnemonic hints:

% vs #. On US keyboards, # is shift-3 and is to the left of % which is shift-5. So # matches on the start (left) and % matches on the end (right).

# vs ## (or % vs %%). Doubling the character makes the match greedy. It's twice a wide so it needs to eat more.

Bash also supports ${parameter/pattern/string} and ${parameter//pattern/string} (and a bunch others besides) which are not POSIX:

https://www.gnu.org/software/bash/manual/html_node/Shell-Par...

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#144

Earlier quoted context omitted.

Which integration for ripgrep do you use with Vim?

Can't speak for OP, but I use telescope for neovim and I don't think I could use (neo)vim without it.

Telescope is cool, but last I checked it was neovim only or recommended and I’m a regular-Vim holdout.

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#145
post #3

It's fast indeed. And I can't help keeping promoting the combination with fzf :) For those who want to try it out, this is a Powershell function but the same principle applies in any shell. Does ripgrep then puts fuzzy searching in the resulting files+text on top while showing context in bat: function frg { $result = rg --ignore-case --color=always --line-number --no-heading @Args | fzf --ansi ` --color 'hl:-1:underl…

With fzf you can add lots of files to git while skipping some if you want: 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 sham…

That blew my mind. I've used fzf a couple time here and there, but now I Get It. Thanks!

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#146
post #3

It's fast indeed. And I can't help keeping promoting the combination with fzf :) For those who want to try it out, this is a Powershell function but the same principle applies in any shell. Does ripgrep then puts fuzzy searching in the resulting files+text on top while showing context in bat: function frg { $result = rg --ignore-case --color=always --line-number --no-heading @Args | fzf --ansi ` --color 'hl:-1:underl…

Vim is almost broken for me without fzf+rg. Feels like I’m manually grinding coffee instead of using electricity.

[deleted]

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#147
post #141
post #132

Earlier quoted context omitted.

Yeah, the -M command is wonderful (super handy for ignoring minified files that you don't want to see results from, etc), and also great is the -g command (eg `-g *.cs` and you'll just search in files that have the .cs extension). 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…

If you're a fan of the -g flag to ripgrep then I also recommend checking out the -t flag, short for --type, which lets you search specific file types. You can see the full list with `rg --type-list`. For example, you could just search .cs files with `rg -tcs`. This flag is especially convenient if you want to search e.g. .yml and .yaml in one go, or .c and .h in one go, etc.

-t is useful but -g doesn't require lookup in help first. Maybe the worse is better principle?

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#148
post #141

Earlier quoted context omitted.

If you're a fan of the -g flag to ripgrep then I also recommend checking out the -t flag, short for --type, which lets you search specific file types. You can see the full list with `rg --type-list`. For example, you could just search .cs files with `rg -tcs`. This flag is especially convenient if you want to search e.g. .yml and .yaml in one go, or .c and .h in one go, etc.

-t is useful but -g doesn't require lookup in help first. Maybe the worse is better principle?

Tbh I've always just typed -t followed by something that feels intuitive and it's always worked. Never really bothered looking in help until I made the above comment.

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#149

Earlier quoted context omitted.

Vim is almost broken for me without fzf+rg. Feels like I’m manually grinding coffee instead of using electricity.

This comment got me to get out my French press and manually grind some beans. It wasn't a meditative and calming as I remember, and the coffee tastes a little...dusty. I guess it's time for me to update my vimrc.

I’m glad my analogy sprouted another branch in this conversation :)

Re: Ripgrep is faster than grep, ag, Git grep, ucg, pt, sift (2016)

#150
post #143

Earlier quoted context omitted.

Thanks! I have tried using bash substitution to solve it but failed (I just learned the difference between "#" and "##").

FYI, these substitutions are POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... Also a couple mnemonic hints: % vs #. On US keyboards, # is shift-3 and is to the left of % which is shift-5. So # matches on the start (left) and % matches on the end (right). # vs ## (or % vs %%). Doubling the character makes the match greedy. It's twice a wide so it needs to eat more. Bash also supports ${parameter/…

Thanks for the great information!
Post reply on HN