Boost Your Terminal Productivity


So, this is going to be a short one. Today, I was looking for a quick way to jump to the start of the line in the terminal, and when searching for it, I found a lot more cool keybinds that are actually very useful. I immediately fell in love with how much these shortcuts streamline my workflow, and I just had to share them. So Enjoy! 😁
Why Keyboard Shortcuts are Your Best Friend
Keyboard shortcuts reduce the time you take to perform actions as it is much easier to just press a button combo than to use the mouse.
Come let’s play a game of “How many times has this happened to you?“—
You've typed a super long
git
command, or a complexdocker
command, and realized you made a typo right at the beginning of it?Solution:
Ctrl + A
(jump to start), fix it, thenCtrl + E
(jump to end) to continue. Much faster than holding the left arrow key.This was the original reason I looked up these keybinds!
You just ran a
kubectl apply -f path/to/my-service.yaml
and now you need to runkubectl delete -f path/to/my-service.yaml
? Or maybe you just created a file and now need togit add
it?Solution: Hit
Alt + .
to immediately bring uppath/to/my-service.yaml
(or the previous command's last argument). Typekubectl delete -f
thenAlt + .
. Boom.This one is a game-changer I used to go to the previous cmd, go to the starting of it and then change the cmd. This one is going to be my favorite!
You're working in a complex directory structure, and you need to quickly change parts of a file path in your current command, like changing
src/components/button/index.ts
tosrc/pages/about/index.ts
?Solution: Use
Alt + B
to jump back word by word (components
, thensrc
), editpages/about
, and thenAlt + F
to jump forward overindex.ts
.Well I already use
Ctrl + ←
andCtrl + →
and I think they work exactly the same asAlt + B
andAlt + F
. But If you didn’t use any of the two, well now you know!
You know you ran a specific command yesterday (maybe a
grep
or afind
), but you can't quite remember the exact syntax, and scrolling through hundreds of lines of history is a nightmare?Solution:
Ctrl + R
(reverse-incremental search). Start typing a keyword you remember, and it will magically pull up matching commands from your history. PressCtrl + R
again to cycle through matches.I’ve already had this covered with a history plugin but it’s nice to know that I didn’t even need that.
Ctrl + R
had me covered all along!
I am sure there are many other such scenarios where these commands would be very useful, So keeping them in your repertoire of tricks would be great for your productivity!
Here is a list of all the essential terminal shortcuts (Emacs-style, default for Bash and Zsh):
Essential Terminal Shortcuts
Move Cursor:
Ctrl + A
: To the start of the line.Ctrl + E
: To the end of the line.Alt + F
: Forward one word.Alt + B
: Backward one word.Ctrl + F
: Forward one character.Ctrl + B
: Backward one character.
Delete/Cut:
Ctrl + K
: Cut from cursor to end of line.Ctrl + U
: Cut the entire line (Zsh) / from cursor to beginning (Bash).Ctrl + W
: Cut the previous word.Alt + D
: Delete the next word.Ctrl + _
(or Ctrl + Shift + -): Undo last change.
Paste:
Ctrl + Y
: Paste (from the clipboard/kill ring).
History:
Ctrl + R
: Reverse-incremental search through history.Alt + .
: Insert the last argument of the previous command (press repeatedly to cycle).Ctrl + P
(or Up Arrow): Previous command.Ctrl + N
(or Down Arrow): Next command.
Other:
Ctrl + L
: Clear the screen.Ctrl + C
: Interrupt (kill current process).Ctrl + Z
: Suspend (send current process to background).
Note: Some of these commands may not work as intended because of the exact combination of terminal and shell you are using so do your own research
Subscribe to my newsletter
Read articles from Pranay Sinha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
