fc — Edit and re-run the previous command in $EDITOR across all 5 shells
Equivalents in every shell
fcBuiltin (POSIX "fix command"). `fc` opens the last command in `$EDITOR`; on save the edited line runs. `fc -l` lists recent history numbers, `fc -s pat=repl` does a substitution and reruns (the basis of the `r` history alias). `fc -e -` repeats the last command outright.
fcBuiltin, same POSIX surface as bash. Zsh adds `fc -p` / `fc -P` (push / pop a private history file) and `fc -R` / `fc -W` (read / write `HISTFILE` on demand). The history widget bindings (`Ctrl-R` etc.) use `fc` internally.
funced my_functionFish has NO `fc`. To re-edit the LAST command use up-arrow / `Ctrl-P` (history search) and edit inline. For editing a FUNCTION, `funced my_function` opens it in `$EDITOR`; `funcsave my_function` persists. `history` lists past entries.
Get-History | Out-GridView -PassThru | Invoke-HistoryNo single `fc` cmdlet. `Get-History` lists entries with IDs; `Invoke-History <id>` reruns. With PSReadLine (default in PS 5.1+), `Ctrl-R` searches and `F2` toggles inline edit — the closest UX to `fc`. Use `Get-History | Out-File ...; vim ...` for editor-based bulk edits.
doskey /historyCmd has no editor-based history recall. `doskey /history` lists past commands; `F7` pops a history menu; `F8` cycles prefix-matching entries. To re-run line N, type its number then `F9`. No way to edit a past command in an external editor without copy-paste.
Worked examples
Edit the previous command in $EDITOR and rerun on save
fcfc(Get-History -Count 1).CommandLine | Set-Content $env:TEMP\h.ps1; & $env:EDITOR $env:TEMP\h.ps1; . $env:TEMP\h.ps1Repeat the last command with a substitution
fc -s foo=barfc -s foo=bar(Get-History -Count 1).CommandLine -replace "foo","bar" | Invoke-ExpressionList the last 10 commands with their history IDs
fc -l -10fc -l -10history --max 10Get-History -Count 10doskey /historyGotchas
- `fc` saves the edited command to history when you exit the editor — even if you DIDN'T change anything or you saved an empty file. Quitting your editor without saving (`:cq` in vim, `Ctrl-X N` in nano) aborts the rerun cleanly and avoids polluting history with accidental duplicates.
- `fc -s pat=repl` does a SINGLE substitution of the FIRST match in the previous command, then runs it. To replace all matches, do a manual `fc` and edit. Bash's `^pat^repl` quick-substitution shortcut is the one-keystroke variant of the same operation.
- Fish removed `fc` deliberately — its history model is per-session by default and the maintainers favoured inline editing via `Ctrl-P` + arrow keys. Scripts ported from bash that call `fc -e -` (re-run last command) must switch to the keystroke flow or wrap with `history search -- ... | tail -1 | source`.
- PowerShell `Invoke-History` reruns by ID, but the ID is PER-SESSION (history restarts at 1 each session). `Set-PSReadLineOption -HistorySaveStyle SaveIncrementally` persists across sessions but IDs still restart. Use `Get-History -Count 1` for "the previous command" reliably.
- On bash, `$FCEDIT` takes precedence over `$EDITOR` for `fc` only. Setting `EDITOR=vim` but leaving `FCEDIT` unset means `fc` falls back to `ed` (the line editor) on some distros — a notorious gotcha for newcomers who land in `ed` and cannot figure out how to escape.