Skip to main content
  1. Posts/

Ripgrep_search_hidden_files

·234 words·2 mins·
Table of Contents

Notes about how to use ripgrep to search hidden files and configuration related to Neovim.

Search hidden files
#

By default, ripgrep will ignore hidden files and directories. To search hidden files/directories, we need to add --hidden option.

rg --hidden my_term

ripgrep config file
#

Unlike other tools, ripgrep does not really have a default place to store its config. Instead, you can store the config anywhere and use the env variable RIPGREP_CONFIG_PATH to point to it.

For example, you can store it in ~/.config/ripgrep/config, then set the env variable in your .bashrc or .zshrc:

export RIPGREP_CONFIG_PATH=$HOME/.config/ripgrep/config

For the content of the config, it is in facet just a list of command line options.

# show line and column number for each match
--line-number
--column

# do not print the file heading
--no-heading

--color=always
--smart-case

--max-columns=4096

# use regex by default
# --regexp

# search hidden files and directories
--hidden

# do not search .git
--glob=!.git/

glob pattern in ripgrep
#

Note that for globbing, the pattern foo/ and foo/** is not the same. It seems that for negative globbing, they work similarly. However, for positive globbing, i.e., when you only want to search in a certain directory, they are totaly different.

rg --glob=foo/ my_term

This will find nothing, and no directory is searched.

rg --glob=foo/** my_term

This works and will find my_term if it exists in some file under foo/ directory or sub-directories.

Related