GNU Readline
Source: Things You Didn't Know About GNU Readline
GNU Readline
GNU Readline is an unassuming little software library that people relied on for years without realizing that it was there. It's integrated in Bash and basically augments any command-line interface with a common set of keystrokes that allow you to move around within and edit a single line of input.
Keyboard Shortcuts
Note: The Meta key is mapped to different keys in different systems:
- Linux and Windows keyboard:
Alt
key orEsc
key - MacOS keyboard:
Esc
key
On MacOS, you can also map Option
key to Meta key: Click Profiles > choose the profile you want (you must do it for each profile here) > click Keyboard > Enable “Use Option as Meta Key”
Cursor movement:
Command | Description |
---|---|
Ctrl + A | Move to the beginning of the line |
Ctrl + E | Move to the end of the line |
Meta + B | Move to the previous word |
Meta + F | Move to the next word |
Ctrl + U | Cuts to the beginning of the line |
Ctrl + K | Cuts to the end of the line |
Ctrl + W | Cuts the previous word |
Ctrl + P | Browse previously entered commands |
Ctrl + R | Reverse search for previously entered commands |
Ctrl + Y | Pastes the text in buffer |
Bash histroy:
Command | Description |
---|---|
!! |
Run previous command (e.g. sudo !! ) |
!cmd |
Run previous command that begins with cmd |
!cmd:p |
Print last command in history beginning with cmd |
!$ |
Last argument of last command |
!^ |
First argument of last command |