-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal_Shortcuts.txt
72 lines (64 loc) · 3.31 KB
/
terminal_Shortcuts.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
EMACS MODE:
Moving the cursor
CTRL-A/HOME: Move to the beginning of a line.
CTRL-E/END: Move to the end of a line.
CTRL-B/LEFT: Move left one character.
CTRL-F/RIGHT: Move right one character.
ALT-B/CTRL-LEFT: Move left one word.
ALT-F/CTRL-RIGHT: Move right one word.
CTRL-XX: Hold CTRL and press X twice to move the cursor to the beginning of the line, and hold CTRL and press X twice again to move the cursor back.
Editing text
CTRL-U: Cut all the characters.
CTRL-K: Cut the characters to the right of the cursor.
CTRL-H/BACKSPACE/DELETE (MACOS): Delete one character to the left.
CTRL-D/DELETE/FN DELETE (MACOS): Delete one character to the right.
CTRL-W: Cut one word to the left.
ALT-D: Cut one word to the right.
CTRL-Y: Paste the characters previously cut.
CTRL-_: Undo the last edit.
CTRL-XE: Open the $EDITOR to edit the line.
ALT-U: Change one word to the right to uppercase.
ALT-L: Change one word to the right to lowercase.
Command completion
TAB: Attempt shell expansion on the current word. If that fails, attempt completion.
gi<TAB> # git
ls *<TAB> # ls folder1 folder2 file3
CTRL-G: List the expansion of the current word.
Managing the screen
CTRL-L: Clear screen (just like clear).
CTRL-S: Stop screen output. Useful for preventing processes from spamming the stdout.
CTRL-Q: Resume screen output.
Managing processes
CTRL-C: Terminate the foreground process. (Also can be used to delete the whole line.)
CTRL-Z: Suspend the foreground process (use fg and bg to resume).
CTRL-D: Exit shell (just like exit).
Accessing Command History
CTRL-R: Search the command history. Accept with ENTER/RETURN, abort with CTRL-G.
CTRL-P/UP: The previous command in history.
CTRL-N/DOWN: The next command in history.
VI MODE
Just like any vi-based editor, vi mode operates in either insert mode (keys produce text on the screen) or normal mode (keys represent editing commands).
Commands
To switch to normal mode, press ESC or CTRL-[, by default, there won’t be any visual indication about which mode is currently active. If you want to switch back to insert mode, just like vi, press a (or A, i, I, depending on where you want the cursor to be).
For more commands, see this cheat sheet.
So, in vi mode, if you want to delete the whole line, you press ESC (to switch to command mode), dd (to delete the line), and a (to switch back to insert mode).
Depending on your shell, or if you have any plugins, some of the Emacs-based shortcuts might work when in insert mode.
Why not both?
If you, like me, like both modes, there’s a really good Zsh plugin that not only enhances vi mode with more features like mode visual indicator and support for surround bindings, but also makes most of the Emacs key bindings available.
Custom Keyboard Shortcuts
It’s easy to add your own keyboard shortcuts. If you are not sure what code represents a key combination (e.g ALT-Z is ^[z), first press CTRL-V followed by the key combination.
Line editor commands
For a list of Zsh-bindable commands, visit this site, for Bash’s, visit this site.
For example, to bind undo to ALT-Z:
# zsh
bindkey '^[z' undo
# bash
bind '"^[z":undo'
Macros
You can also bind strings:
# zsh
bindkey -s '^[[24~' 'You`ve just pressed F12'
# bash
bind '"\e[24~":"You`ve just pressed F12"'
Shell commands
You can also define key bindings to execute shell commands without affecting the current command line.