The GitHub Engineering blog gave a nice list of CLI tricks every developer should know the other day. Here’s a quick recap:
Ctrl-c
: Cancel the current commandCtrl-a
: Move the cursor to the beginning of the lineCtrl-e
: Move the cursor to the end of the lineCtrl-l
: Clear the terminal screenCtrl-d
: Exit shell sessionTAB
: Auto-complete commands, file names, and pathshistory
: Type this in the terminal to access the history!!
: Execute the last commandCtrl-r
: Reverse search for a previously executed commandCtrl-n
: Move to the next command in the historyCtrl-p
: Move to the previous command in the historyCtrl-g
: Abort searchCtrl-_
: Undo the last edit
Here’s a couple left out, that I personally find really useful.
Ctrl-u
: Delete to start of line. Can also be undone withCtrl-_
.Ctrl-k
: Delete from cursor to end of line. Can also be undone withCtrl-_
.Ctrl-y
: Yank the deleted text back in place (aka paste). Can also be undone withCtrl-_
.Ctrl-z
: Move running interactive application to the background. Bring it back by typingfg
.
And a couple using Meta
(or Alt/Option
).
Meta-b
: Move back, a word at a timeMeta-f
: Move forward, a word at a timeCtrl-w
: Delete backward, a word at a time. These can also be yanked back withCtrl-Y
or undone withCtrl-_
Meta-d
: Delete forward, a word at a time. These can also be yanked back withCtrl-Y
or undone withCtrl-_
In iTerm.app you need to set the left or right option key to Meta
or Esc+
in the Profiles -> Keys -> General
menu to bring back these:
Meta-t
: Transpose words, i.e. swap a word with the previous one. Can be undone withCtrl-_
. Will respect word separators, so thatone=two
followed byMeta-t
will result intwo=one
if=
is considered a word separator.
In zsh you can adjust the exported WORDCHARS
environment variable to tune what is considered word separators.
Btw, most if not all of these work by default in Emacs as well 😉
Edit: Lowercased all commands <2023-05-06 Sat>