Shell Control Keys

From Exterior Memory
Jump to: navigation, search

In shells like zsh, sh, bash and tcsh, there are many shortcuts which help you editing. Below is a table.

Editing control keys

control-A Cursor to begin of line
control-E Cursor to end of line
control-U Delete line
conrtol-K Delete from cursor to end
control-W Delete previous word
control-B Cursor back one word (custom key)
control-N Cursor forward one word (custom key)
control-D Delete character (same as delete; not backspace)
control-H Delete previous character (same as backspace)
control-T Transpose (change order) of two characters
control-L Clear screen
control-_ Undo

Execution-related control keys

These commands directly affect a process in the shell

control-C Break
control-Z Suspend the running job. (Use the bg and fg commands to resume them in the background or foreground)
control-S Suspend flow control (input is processed, but output not send to the terminal)
control-Q Resume normal flow control
control-D Logout (exit)

Redundant control key

These keys all have an equivalent "normal" key

control-M return Carriage Return
control-J enter Carriage Return
control-B arrow left Cursor back one character (overriden by my bindkeys)
control-F arrow right Cursor forward one character
control-P arrow up Previous command in history
control-D delete Delete character
control-H backspace Delete previous character

ZSH Bindkeys

To make sure I can always use my beloved shortcuts, I put these commands in my .zshrc file. ^? is the same as the backspace key.

bindkey "^A" beginning-of-line
bindkey "^E" end-of-line
bindkey "^B" backward-word
bindkey "^N" forward-word
bindkey "^?" backward-delete-char