Line-Edit Mode
Line-edit mode lets you emulate many features of the vi and Emacs editors. The history list is treated like a file. When the editor is invoked, you type editing keystrokes to move to the command line you want to execute. In the Terminal, the arrow keys work in both Emacs mode and vi command mode. You can also change the line before executing it. See Table 5-32 for some examples of common line-edit commands. When you’re ready to issue the command, press Return. The default line-edit mode is Emacs. To enable vi mode, enter:
$ set -o viNote that vi starts in input mode; to type a vi command, press Esc first.
The mode you use for editing bash commands is entirely separate from the editor that is invoked for you automatically within many commands (for instance, the editor invoked by mail readers when you ask them to create a new mail message). To change the default editor, set the VISUALor EDITOR variable to the filename or full pathname of your favorite editor:
$ export EDITOR=emacs|
vi |
Emacs |
Result |
|
K |
Ctrl-p |
Get previous command. |
|
J |
Ctrl-n |
Get next command. |
|
/ |
Ctrl-r |
Get previous command containing |
|
H |
Ctrl-b |
Move back one character. |
|
L |
Ctrl-f |
Move forward one character. |
|
b |
M-b |
Move back one word. |
|
w |
M-f |
Move forward one word. |
|
X |
Del |
Delete previous character. |
|
x |
Ctrl-d |
Delete one character. |
|
dw |
M-d |
Delete word forward. |
|
db |
M-Ctrl-h |
Delete word back. |
|
xp |
Ctrl-t |
Transpose two characters. ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access