ripgrep

Notes on ripgrep

ripgrep

ripgrep is a command line tool that allows for quickly searching exact matches to regex patterns.

Default use is rg <query> [PATH]

Using it as a grep replacement to pipe to fzf, using in Vim as line search for wiki

  • Was looking into how I might be able to truncate the context around a match in a line. Every now and again there will be a match in a very long line, and using rg on its own will print the entire thing. When used with fzf, the actual match typically cant be seen because fzf just uses one line to show the preview, and the match is likely way beyond the front portion of the line. After doing some digging, I found -M {n} --max-columns-preview options for rg, but they don’t really do what I want. Those options just say, if the current matched line is longer than n bytes long, cut off the tail after the n bytes. So these options pretty much do exactly what fzf does, which is unhelpful. There does not appear to be a way of doing this is in ripgrep alone. A small workaround, when using in conjunction with fzf, is just typing that text out in the preview to actually show a match. You can then keep searching from there. This is the functionality implemented in the current backlink and unlinked reference commands.