SPC / and
SPC s p (
spacemacs/helm-project-smart-do-search) enables a a fuzzy logic search through the content of all the files in the current project. A helm pop-up displays, typing a pattern shows matching lines from all the files in the project.
C-k to move down and up through the search results.
RET selects the search result and shows the file and line in the current buffer.
SPC s l will repeat the last search
M-p will scroll through the search patterns whenever the search pop-up window is open
Replacing text across a project
Use search results to replace text across a project.
Open files from search results
With a search open,
C-c C-f enables
helm-follow. When moving through results with
C-k the corresponding file is opened in the current buffer.
helm-follow-mode-persistent to true in
.spacemacs to remember the use of
C-c C-f follow mode for helm actions.
(helm :variables helm-follow-mode-persistent t)
Search tool binary
Searching requires an external tool to be available on your system PATH. Ripgrep is the recommended search tool, although silver searcher (ag) is a viable alternative. Using
grep is noticeably slower and has fewer options for searching.
Searching specific files
Include or exclude specific files by their names or filename extensions.
-g option for a filename to search (globbing), or
-g! for a filename to ignore.
-g*.clj map shows only results of searching for
map from files ending in
-g!*.md map will search for
map for all files except those ending in
Example search patterns
Additional search patterns that work with
-G*time - search for the word "time" in all files
-G*time -g*.clj - search for the word "time" in
.clj files only
-tclojure time - search for "time" in all
uno\ duo\ tre - search for the string "uno duo tre"
-C5 foo - search for "foo" but show 5 lines of context before and after the match
(?:^|[^\w-])time(?:[^\w-]|$) - search for "time" even in kebab-case words. i.e. search for the full word "time" including "-" to be a word character
Ripgrep documentation has many regular expression examples
Searching hidden files
Searching a project using
SPC / and
SPC s p will ignore hidden files, those that start with
-- --hidden or
-- -uu after the search pattern to include hidden files in the search
For example, to search for the pattern
scissors -- --hidden
Searching hidden files may slow searching
Ripgrep configuration and arguments
Define an environment variable called
RIPGREP_CONFIG_PATH set to the file name and path
||same as -u and show hidden files|
||same as -uu and search binary files|
||Maximum number of columns (Spacemacs default: 150)|