Skip to content

Commit cea3bc0

Browse files
committed
Add Fix Previous Command With fc as a Unix TIL
1 parent ee31f5b commit cea3bc0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1595 TILs and counting..._
13+
_1596 TILs and counting..._
1414

1515
See some of the other learning resources I work on:
1616
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -1532,6 +1532,7 @@ See some of the other learning resources I work on:
15321532
- [Find Newer Files](unix/find-newer-files.md)
15331533
- [Find Occurrences Of Multiple Values With Ripgrep](unix/find-occurrences-of-multiple-values-with-ripgrep.md)
15341534
- [Find Top-Level Directories Matching A Pattern](unix/find-top-level-directories-matching-a-pattern.md)
1535+
- [Fix Previous Command With fc](unix/fix-previous-command-with-fc.md)
15351536
- [Fix Shim Path After asdf Upgrade](unix/fix-shim-path-after-asdf-upgrade.md)
15361537
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
15371538
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)

unix/fix-previous-command-with-fc.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Fix Previous Command With fc
2+
3+
The `fc` command is a Bash and ZSH built-in command that allows you to interact
4+
with the history of commands issued in the shell. The most straightforward use
5+
case I know of for using this command is to fix or edit some aspect of the
6+
previous run command.
7+
8+
When `fc` is executed with no arguments or flags, it will grab the latest entry
9+
to the command history and load it into your default editor. For me, that is
10+
Vim.
11+
12+
I can make edits in that Vim session like I'd do in any other Vim session. When
13+
I write and quit (`:wq`) the file, the updated command will be executed. This
14+
is useful if, say, I've made a typo in the previous command and would prefer
15+
the ergonomics of my default editor to fix it. Or let's say I have a really
16+
long command with many flags and long file path arguments. It would be much
17+
easier and quicker to edit those paths from my editor than from the terminal
18+
prompt.
19+
20+
If I've opened my editor (Vim) with `fc` and I decide I don't want to execute
21+
the command after all, I can _compiler quit_ Vim (exit with an error code)
22+
using `:cq`. The command will not be executed in this case.
23+
24+
See `man zshbuiltins` for more details about this command and all of its flags.
25+
26+
[source](https://www.computerhope.com/unix/uhistory.htm)

0 commit comments

Comments
 (0)