Silversearcher: Difference between revisions

From wikinotes
No edit summary
 
Line 25: Line 25:
ag 'file.touch(\n\s.*)+'      # multiline search example
ag 'file.touch(\n\s.*)+'      # multiline search example


ag 'Foo(?!Bar)'               # lookahead/lookbehind!
# lookahead / lookbehind
ag '(?<=Foo)Bar'
ag 'Foo(?!Bar)'
ag 'Bar(?=Foo)'
ag '(?<!Concurrent)::Promise'
ag '(?<=Concurrent)::Promise'


ag --pager='less -Ri' search  # ag to pager
ag --pager='less -Ri' search  # ag to pager

Latest revision as of 16:26, 5 February 2024

The silver searcher is a file-searching module ag that searches more quickly than grep, and lets you perform multiline regex.

Documentation

github https://github.com/ggreer/the_silver_searcher

Install

sudo pacman -S the_silver_searcher  # arch
brew install the_silver_searcher    # macos

Usage

ag 'file.touch(\n\s.*)+'      # multiline search example

# lookahead / lookbehind
ag 'Foo(?!Bar)'
ag 'Bar(?=Foo)'
ag '(?<!Concurrent)::Promise'
ag '(?<=Concurrent)::Promise'

ag --pager='less -Ri' search  # ag to pager

ag -G '.*\.rb$' foo             # search files matching '.*\.rb$' 

ag search \
  -l  `# print files only` \