USECASE
The aim of this page 📝 is to explain how to paginate the results of ripgrep (rg
) using less
. This is especially useful for querying my knowledge base, which is a simple file tree full of markdown files, edited in Visual Studio Code.
less
is a powerful terminal pager program used to view the contents of a file one screen at a time. It allows backward and forward navigation through the file, and it is more feature-rich than other pagers like more
. With less
, you can search within the file, navigate by lines or pages, and even view files with color formatting.
- Ripgrep (
rg
) is a powerful tool for searching within files. - To handle large search results, pipe the output to a pager like
less
. - The
-R
flag is crucial for displaying colors correctly inless
. - Using ripgrep with the
--pretty
flag andless
provides a great combination.
rg --pretty '<search_term>' | less -R
- Benefits of this approach:
- Scroll up/down through results: Navigate large outputs easily.
-
Search within results: Press
/
inless
to search (like vim) - Preserved colors and formatting: Keep syntax highlighting.
- Line numbers and file names remain visible.
-
Easy exit: Press
q
to quitless
. - Hyperlinks + preview: with Warp, I'll get the contents of the linked file OOTB
Top comments (0)