# Search and replace

Canonical HTML: [Search and replace](https://getred.dev/docs/editor/search). Website source: `b212874eefaf200143affa21c770fbb8855a4f5c`. Documented Red release: v0.9.1. Installer source: `b86a2ca4b92e9547d3b174910c82db8a259f5171`.

Search one buffer, the whole project, or the file tree, and make controlled replacements with Red's regular-expression syntax.

<a id="search-the-current-buffer"></a>

## Search the current buffer

`/`Search forward with a live preview

`?`Search backward

`n / N`Repeat in the same or opposite direction

`*`Search for the word under the cursor

`:noh`Clear search highlighting

Search patterns use Rust regular-expression syntax. Search history is shared between `/` and `?` and persists across restarts.

<a id="search-the-project"></a>

## Search the project

Press `Space g` to open project search. Type a query, move through matches with the arrow keys or `Ctrl-n`/`Ctrl-p`, and press `Enter` to open a result. Project search runs `rg`, so install ripgrep if Red reports that the process is unavailable.

<a id="search-the-file-tree"></a>

## Search the file tree

Press `Ctrl-e` to open the file tree, then `/` to search paths recursively. `Enter` opens a file or reveals a directory, `Ctrl-Enter` reveals without opening, and `Esc` restores the tree. Press `D` to search only directories, `f` to keep a filter, and `Ctrl-x` to clear it.

<a id="replace-text"></a>

## Replace text

```red-command
:%s/old/new/g
:%s/(old)-([0-9]+)/$1-$2/g
:'<,'>s/old/new/gc
```

Red supports the current line, the whole buffer with `%`, numeric line ranges, and the last Visual selection. Add `g` for every match on a line, `i` for case-insensitive matching, or `c` to confirm each replacement.

> **Replacement syntax**
>
> Captures use Rust forms such as `$1` and `$name`. Use `\r` to split a line. Vim magic modes and expression replacements aren't supported.
