Terminal Shortcuts
To move fast in the bash terminal without reaching for mouse or arrow keys, it is important to learn GNU readline shortcuts. GNU readline is what allows for features such as tab completions or scrolling through history with arrow keys in the terminal! By default GNU readline uses Emacs key bindingswhich is why you see that mentioned in a lot of terminal shortcut cheatsheets.
Movement
For horizontal movement, start with the following:
Ctrl + Amoves to the beginning of the lineCtrl + Emoves to the end of the line
For character movement:
Ctrl + Fmoves forward one characterCtrl + Bmoves back one character
For word level movement:
Alt + Fmoves forward to end of next wordAlt + Bmoves back to the start of the current or previous word
- Think
Afor start of alphabet,Efor end. - Think
Ffor forward,Bfor back.
Killing and Yanking
In Emacs killing is synonymous with cutting, and pasting is synonymous with pasting. Killing something deletes it and sends it to clipboard for pasting.
Ctrl + Kkill (cut) forward to end of lineCtrl + Ukill (cut) backward to start of line
Often when typing in passwords in the terminal, you mistype. Instead of pressing backspace and trying to delete the typed password to start over (where you don't even know how many characters you need to backspace), you can just delete it with Ctrl + U! Then retype your password.
Kill word (very useful for deleting):
Alt + Dkill (cut) forward to end of current wordCtrl + Wkill (cut) backward to the start of current word
Once you'll killed, this adds it to the kill ring. You can yank (paste):
Ctrl + Yyank (paste) from kill ring
If you want to paste something you've killed in the past, you can cycle through the kill ring history by doing Ctrl + Y and then Alt + Y multiple times to cycle through!
Alt + YafterCtrl + Yto cycle through kill ring history
The GNU readline kill ring is local to the process and not shared with other GNU readline instances or the system's clipboard. So you can't easily copy and paste it elsewhere.
Swap Words
If your cursor is between two words, you can swap them with the command:
Alt + Tswap words
Clear Screen
Ctrl + Lclears the screen
Reverse Search
One of the most useful shortcuts a person first learns is reverse search in history, using Ctrl + R. This brings up a prompt where you can search for a previous command by keyword.
Ctrl + Rsearch backward through history
FYI with fzf shell integration Ctrl + R is even more neat as it will display your command history directly above as you search. Then you can select and paste the desired command from history onto command line.
Copying Terminal Output
I struggled with figuring out how to copy terminal output to system clipboard (not the GNU Readline buffer) for the longest time. Turns out you just need to drag with your mouse over a selection on the terminal screen and release. It's automatically copied to your system clipboard and you can do Ctrl + V.