Zsh#

The Z shell. Zsh ships its own line editor (ZLE) instead of GNU readline, but the default emacs keymap is binding-compatible with bash so the muscle memory carries over. bindkey -v switches to vi mode; bindkey -e returns to emacs. bindkey with no arguments lists every active binding in the current keymap; bindkey -l lists the keymaps themselves (emacs, vicmd, viins, main, isearch, command, menuselect).

For shell startup files, completion configuration, and history options, see Zsh.

Cursor Movement#

Key

Action

Ctrl-a

move to start of line (beginning-of-line)

Ctrl-e

move to end of line (end-of-line)

Ctrl-b

move back one character

Ctrl-f

move forward one character

Alt-b

move back one word

Alt-f

move forward one word

Ctrl-x Ctrl-x

jump between current position and mark

Editing#

Key

Action

Ctrl-d

delete character under cursor (EOF on empty line)

Ctrl-h

delete character before cursor

Backspace

delete character before cursor

Alt-d

delete word forward

Ctrl-w

delete word backward

Alt-Backspace

delete word backward (alphanumeric-aware)

Ctrl-k

kill to end of line

Ctrl-u

kill whole line (zsh default; bash kills to start)

Ctrl-y

yank (paste) last killed text

Alt-y

cycle through previous yanks after Ctrl-y

Ctrl-t

transpose character with previous

Alt-t

transpose word with previous

Alt-u

uppercase word from cursor

Alt-l

lowercase word from cursor

Alt-c

capitalize word from cursor

Ctrl-Space

set mark

Ctrl-x Ctrl-u

undo

Alt-_

undo (alternative)

History#

Key

Action

Ctrl-p

previous command (up-line-or-history)

Ctrl-n

next command (down-line-or-history)

Ctrl-r

incremental reverse search

Ctrl-s

incremental forward search (requires stty -ixon)

Ctrl-g

abort current search, restore line

Alt-p

history search backward on current prefix

Alt-n

history search forward on current prefix

Alt-.

insert last argument of previous command

Alt-,

cycle through previous-command last-args after Alt-.

!!

run previous command

!$

last argument of previous command

!^

first argument of previous command

!*

all arguments of previous command

!<n>

run history entry N

!<string>

run most recent command starting with <string>

^old^new

rerun previous command, substituting old for new

fc -l

list recent history entries

fc <n>

re-edit history entry N in $EDITOR

Process Control#

Key

Action

Ctrl-c

send SIGINT to foreground process

Ctrl-z

suspend foreground process (SIGTSTP)

Ctrl-d

send EOF (close stdin); exit shell on empty line

Ctrl-l

clear screen

Ctrl-s

pause terminal output (XOFF)

Ctrl-q

resume terminal output (XON)

Ctrl-\

send SIGQUIT to foreground process (core dump)

Completion#

Zsh completion (loaded by autoload -Uz compinit && compinit) is the headline feature. Tab cycles through matches in menu mode; Shift-Tab reverses.

Key

Action

Tab

complete / cycle next match

Shift-Tab

cycle previous match

Tab Tab

list all completions

Alt-?

show possible completions without inserting

Alt-*

insert all completions

Alt-/

try filename completion explicitly

Alt-~

username completion

Alt-$

variable completion

Alt-@

hostname completion

Ctrl-x t

complete command-line argument (positional)

Ctrl-x i

complete environment variable inline

Ctrl-x g

list expansions of a glob pattern

Ctrl-x ~

expand a tilde at cursor

Ctrl-x ?

show what completion would do (debug)

ZLE Specials#

Zsh-only Line Editor widgets and bindings that bash does not ship.

Key

Action

Esc q / Alt-q

push current line onto stack, get fresh prompt; auto-restored after next command

Esc h / Alt-h

run run-help on the command word at cursor

Ctrl-x Ctrl-e

edit current line in $EDITOR

Ctrl-x e

same as Ctrl-x Ctrl-e

Ctrl-x Ctrl-v

swap to vi-command keymap for one keystroke

Ctrl-x *

expand a glob in place

Ctrl-x =

expand parameter / command substitution in place

Ctrl-x a

expand alias at cursor

Ctrl-x s

history-incremental-search-backward (alt binding)

Ctrl-x u

undo

Esc !

history-expand-line; preview !! style expansion

Esc /

history-incremental-pattern-search-backward (with PCRE-style globs)

Vi Mode#

Enable with bindkey -v or set -o vi. Two keymaps: viins (insert) and vicmd (command). Esc switches from insert to command; in command mode the standard Vim motions apply.

Key

Action

Esc

enter command mode (viins -> vicmd)

i

insert at cursor

a

append after cursor

A

append at end of line

I

insert at start of line

0 / ^

move to start of line / first non-blank

$

move to end of line

w / b

word forward / backward

e

end of word forward

f<c> / F<c>

find next / previous occurrence of char c

x

delete character under cursor

dw / d$ / dd

delete word / to end of line / whole line

cw / c$ / cc

change word / to end of line / whole line

yw / y$ / yy

yank word / to end of line / whole line

p / P

paste after / before cursor

u

undo

Ctrl-r

redo (in vicmd mode)

v

open current line in $EDITOR

k / j

previous / next history line (vicmd mode)

/<pat> / ?<pat>

history search backward / forward

Misc#

Key / Command

Action

Ctrl-_ / Ctrl-/

undo last edit

Ctrl-j / Ctrl-m

newline / accept line

Ctrl-v <key>

insert next key literally (raw escape sequence)

set -o vi / set -o emacs

switch editing mode for this session

bindkey

list every active binding

bindkey -l

list keymaps

bindkey -M <map> <key> <widget>

bind a key to a widget in a specific keymap

zle -la

list every widget name

where-is <widget>

find the key bound to a widget

stty -a

list terminal-driver shortcuts (intr, susp, erase)