> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/unix/open-last-command-in-the-editor-with-fc.md).

# open last command in the editor with fc

Some time you have a long command and you want to edit multiple word in it. for example: `$ cat foo.txt | grep foo | grep -v bar > foo_output.txt`

Say you want to execute this 5 times and each replacing `foo` and `bar` with something else.

for that you can use the `fc` command.

```
$ fc
```

It will open a text editor (vim for me. I'm guessing it will look at $EDITOR env variable).\
After that you can edit or duplicate the line easily. Each line will be treated as a single command.

You can as well do something like

```
$ fc foo=baz
```

It will replace all instance of `foo` in the command and replace it with `baz`
