# External commands

## `%` and `!`

`%` resolves to the current filename. `!` calls an external function. Together, `%!` executes a command over the file, and replaces the current buffer with the output.

## Mapping over files with `:w`

You can generate derived JSON from an existing file with `jq`, which I sometimes use to generate and manipulate test vectors:

```bash
:w !jq '.key-to-filter-by' > filtered.json
```

You can easily pass Markdown (or any other text format) files straight through `pandoc`. This is useful for exporting documentation for sharing with non-engineers.

```bash
:w !pandoc -o FILENAME.pdf
```

## Buffer processing with `:%:`

Processing can be achieved by calling `%! !external_fn` to replace buffer contents in-place.

In this example, we pipe a JSON file through `jq` to prettify:

```bash
:%: !jq '.'
```

In this example, we convert the current file from Markdown to HTML using `pandoc`:

```bash
:%: !pandoc -f markdown -t html
```


---

# 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/external-commands.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.
