> For the complete documentation index, see [llms.txt](https://docs.vale.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vale.sh/fixes/replace.md).

# replace

Learn how to write a rule's replacements into the rule.

```go
func replace(match string) []string
```

`replace` returns the replacements listed in the rule.

```yaml
extends: existence
message: "Use '%s' for '%s'."
action:
  name: replace
  params:
    - color
tokens:
  - colour
```

A parameter can name the token's capture groups, `$1`, `$2`, and the whole match as `$0`; see [the token's groups](/fixes/edit.md#the-tokens-groups). Several parameters are several suggestions. The message joins them, `'color or hue'`, and an editor offers each as its own quick fix.

Rules that extend `substitution` or `capitalization` know their own replacement, so the parameters can be left out:

```yaml
extends: substitution
message: "Use '%s' instead of '%s'."
action:
  name: replace
swap:
  Javascript: JavaScript
```

A `substitution` entry whose value is written as alternatives, `color|hue`, yields one suggestion per alternative.

With [`matchcase`](/topics/styles.md#the-header) set on the rule, each replacement takes the case of the text it replaces, so a swap written as `a-ok` still suggests `A-OK` for `A OK`. The `capitalization` check ignores that setting: it decides the case, and changing its suggestion's case would undo the correction.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.vale.sh/fixes/replace.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
