# Batch editing

## Opening a list of files

```bash
vim `ag -lQ TERM`
```

## Operating on a list of files within vim using `cdo`, `cfdo`

The following takes an existing quickfix list (for example, from `:Ack TERM`), applies the replacement, and saves them.

`cdo` runs the command for each entry in the quickfix list while `cfdo` runes the command for each file in the quickfix list.

```
:cfdo %s/TERM/REPLACEMENT/g
```

## Operating on a list of files using argument list

### Batch editing files outside vim using `argdo`

The following command takes a list of files including `TERM`, applies the replacement, and saves them.

```bash
vim `ag -lQ TERM` +"argdo %s/TERM/REPLACEMENT/g | update"
```

### Bulk editing files from within vim

The following allows adding all files matching a glob to the arglist, where you can then operate on them. This example uses `:exec` and string concatenation to open all files matching the extension `.tsx` in the parent directory of the current file.

```
:exec 'args ' . expand('%:h') . '/**.tsx'
```


---

# Agent Instructions: 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:

```
GET https://timhwang21.gitbook.io/index/cli/vim/batch-editing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
