| Description |
Shortcut |
| Autocomplete |
TAB |
| Clear terminal screen |
C-l |
| CUA: Cut word backward (behind cursor) |
C-w |
| CUA: Cut word forward |
M-d |
| CUA: Cycle undo list |
C-_ , C-x, C-u, C-/ |
| CUA: Kill (to clipboard) to end of line/beginning of line |
C-k, C-u |
| CUA: Paste, yank from kill ring |
C-y |
| Cursor: delete everything to beginning of line |
C-u |
| Cursor: delete everything to end of line |
C-k |
| Cursor: line - move to beginning |
C-a, Home |
| Cursor: line - move to end |
C-e, End |
| Cursor: move to beginning of word |
M-b / C-left arrow |
| Cursor: move to end of word |
M-f / C-right arrow |
| Search command history reverse isearch |
C-r |
| Transpose character / word |
C-t / M-t |
| Description |
Shortcut |
| Start/stop macro records |
C-x (, C-x ) |
| Play last macro |
C-x e |
| Print out macro |
C-x p (bound in .inputrc, default is unbound |
| Description |
Shortcut |
| Complete at point |
TAB |
| List completions |
M-? |
| Insert all completions |
M-* |
| Complete tilde |
M-~ |
- Use numeric arguments like Emacs
M-2 M-d to kill two words forward
| Description |
Shortcut |
| Insert comment |
M-# |
| Clear screen |
C-c C-l |
| Description |
Command |
| Empty file without deleting it |
cat /dev/null > filename |
| Go to home directory |
cd or cd ~ |
| List files in current directory |
ll (ls -l |
| Open Ubuntu files in folder (e.g. nautilus ~/) |
nautilus |
| Reuse entire last command (e.g. useful for sudo !!) |
!! |
| Reuse the last argument from the previous command (bash) |
!$ |
| Reuse the last argument… example: |
ls tool && cd !$ |
| Run multiple commands if previous command was successful |
command1 && command2 |
| Run multiple commands in one line |
command1; command2; command3 |
| Stop a running command |
C-c |
| Switch back to last working directory |
cd - |
| View a file in a paged fashion |
less filename |
| Watch log file for change |
tail -f logfile |
GNU Readline and Emacs share many shortcuts
GNU Readline is reused by: bash, python, GDB, psql, sqlite, and more,
allowing shortcuts to be used in those CLIs.
- Keyboard macros
- History search and navigation
- Faster editing
You can record, play back, and print out keyboard macros. Can be
written, no recording needed. Can be written on the fly.
Example use cases
apt-cache search emacs with keyboard macro transformed into
$(apt-cache search emacs | ezf -f 1)
- Wrap prompt to simple python commands like dir(…), help(…)
- Readline’s kill ring (clipboard) is not shared with the system
clipboard
- It is not universally used, like Zsh and fish use their own line
editing
- Many commands are shared with fish; however macros may not function
the same
- Prompt undo history is reset on each new prompt
- Global settings in
/etc/inputrc
- User settings in
~/.inputrc
- Uses Emacs notation like
C-x for ctrl + x and M-x for alt + x
and chords like C-x p
- Except in
.inputrc , use \e for alt (meta) and \C for control.
- Examples:
# Correct - binds to C-x q
# Correct - binds to C-M-p
# Set variables with set keyword
# Limit settings to certain programs
# By default the keyseq-timeout value is a rather ambitious 500 ms. I find that far too quick, so I change it 1200 ms:
# Colored completion of partial matches in bash
# by default color highlighting for completition is disabled
set colored-completion-prefix on