Skip to content
shellmap

fcEdit and re-run the previous command in $EDITOR across all 5 shells

Equivalents in every shell

Bashunix
fc

Builtin (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.

Zshunix
fc

Builtin, 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.

Fishunix
funced my_function

Fish 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.

PowerShellwindows
Get-History | Out-GridView -PassThru | Invoke-History

No 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.

cmd.exewindows
doskey /history

Cmd 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

Bash
fc
Zsh
fc
PowerShell
(Get-History -Count 1).CommandLine | Set-Content $env:TEMP\h.ps1; & $env:EDITOR $env:TEMP\h.ps1; . $env:TEMP\h.ps1

Repeat the last command with a substitution

Bash
fc -s foo=bar
Zsh
fc -s foo=bar
PowerShell
(Get-History -Count 1).CommandLine -replace "foo","bar" | Invoke-Expression

List the last 10 commands with their history IDs

Bash
fc -l -10
Zsh
fc -l -10
Fish
history --max 10
PowerShell
Get-History -Count 10
cmd.exe
doskey /history

Gotchas

  • `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.

WSL & PowerShell Core notes

pwshPSReadLine (bundled in pwsh 7+) provides the closest `fc`-style UX on every platform: `Ctrl-R` reverse search, `F2` inline toggle, `Get-History` + `Invoke-History` for ID-based recall. `fc` itself is NOT defined in pwsh — `fc.exe` on Windows is the unrelated "File Compare" utility.
WSLInside WSL bash, `fc` works exactly like native Linux and reads `$EDITOR`. Setting `EDITOR=code` (VS Code) opens the buffer in the Windows-side editor over WSL's integration and returns immediately — set `EDITOR="code --wait"` so `fc` actually waits for you to save and close before re-running.

Common tasks using fc

Related commands