Search tool – How to use ripgrep?

Installation

$ brew install ripgrep

Usage

How to search all files in the current directory (and its subdirectories) for a string?

# Output file path & line number & content
$ rg 'hung-nb'

# Output 2 lines before and after
$ rg 'hung-nb' -C 2

# Output 2 lines after
$ rg 'hung-nb' -A 2

# Output only file path
$ rg -l 'hung-nb'

How to search specific language files?

# Javascript files (*.js, *.jsx, and *.vue)
$ rg -t js 'hung-nb'

# Markdown files (*.markdown, *.md, *.mdown, and *.mkdn)
$ rg -t md 'hung-nb'

Be the first to comment

Leave a Reply

Your email address will not be published.


*