# Find and replace in Skink (regex, case, whole word)

> Search the current file in Skink with Ctrl+F, step through matches with Ctrl+N and Ctrl+P, toggle regex, case and whole word, and replace all in one undo step.

Source: https://skink.cc/editing/find-and-replace/

Press Ctrl+F and type. Skink searches as you type from the cursor, marks every visible match and shows "N of M".

Enter keeps the match, Esc goes back to where you were. Later, Ctrl+N and Ctrl+P jump to the next and previous match.

To replace, press Tab in the find bar, type the replacement and press Enter. Every match is replaced as one undo step.

To search all files in the project, see [Project search](https://skink.cc/code/project-search/).

## Find bar keys

| Key | Does |
|---|---|
| Ctrl+F (also F3, F7) | Open the find bar |
| Enter | Keep this match and close the bar |
| Esc | Close and return to where you started |
| Alt+R | Toggle regex |
| Alt+C | Toggle case-sensitive |
| Alt+W | Toggle whole word |
| Alt+S | Search only inside the selection |
| Tab | Move to "Replace with" |
| Ctrl+N / Ctrl+P | Next / previous match, after the bar is closed (`:findnext` / `:findprev`) |
| Ctrl+L | Go to line (not part of find, but close by) |

These Alt keys mean something else in the editor. They only toggle options while the find bar is open.

The active toggles show in the prompt: `.*` for regex, `Aa` for case, `\b` for whole word.

## Case: smart by default

Without the case toggle, search uses smart case: a lowercase query matches any case, and a query with a capital letter matches exactly.

`foo` finds `Foo` and `FOO`; `Foo` finds only `Foo`.

## Search in a selection

Select some lines, then press Ctrl+F. A selection that spans several lines starts the search inside it, shown as `[sel]`.

With a smaller selection, press Alt+S in the bar to limit the search to it. Replace then only touches matches in the selection.

## Replace all matches in a file

1. Press Ctrl+F and type what to find.

2. Press Tab and type the replacement.

3. Press Enter. Every match in the selection, or in the whole file, is replaced.

The status line reports how many matches were replaced. Ctrl+Z undoes all of them at once.

### Capture groups in regex mode

In regex mode the replacement can use capture groups: `$1` for a numbered group and `${name}` for a named one.

For example, find `(\w+): (\w+)` and replace with `$2: $1` to swap both sides.

### Replace from the command line

`:replace FIND WITH` replaces every literal `FIND` with `WITH`, in the selection or else the whole file, as one undo step.

Quote text that contains spaces: `:replace "two words" "other words"`. `:replaceall` is the same command.

## Tips

- The editor's last column is a scrollbar that marks find matches in orange, so you can see where matches are across the whole file.
- Jumping to a match inside a closed fold opens the fold.

**Note:**
For replacing across files, use project search and then `:greprep`, which goes through a preview so you can check each change. See [Project search](https://skink.cc/code/project-search/).
