Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix C: Keyboard Shortcuts

This appendix covers keyboard shortcuts for Terminal.app, command-line editing, and common terminal emulators on macOS.


Terminal.app Shortcuts

Window and Tab Management

ShortcutAction
Cmd+NNew window
Cmd+TNew tab
Cmd+Shift+NNew window with same command
Cmd+WClose tab/window
Cmd+Shift+WClose window
Cmd+1-9Switch to tab 1-9
Cmd+Shift+[Previous tab
Cmd+Shift+]Next tab
Cmd+Left ArrowPrevious tab
Cmd+Right ArrowNext tab
Cmd+Shift+DSplit pane horizontally
Cmd+DSplit pane vertically (some configs)
Cmd+Shift+EnterToggle full screen
Cmd+Ctrl+FToggle full screen

Text and Display

ShortcutAction
Cmd++ or Cmd+=Increase font size
Cmd+-Decrease font size
Cmd+0Reset font size to default
Cmd+KClear screen and scrollback
Cmd+LClear screen (keep scrollback)
Ctrl+LClear screen (shell command)
Cmd+HomeScroll to top
Cmd+EndScroll to bottom
Page UpScroll up one page
Page DownScroll down one page
Cmd+Up ArrowScroll up one line
Cmd+Down ArrowScroll down one line

Selection and Clipboard

ShortcutAction
Cmd+ASelect all
Cmd+CCopy selection
Cmd+VPaste
Cmd+Shift+VPaste escaped (for URLs, paths)
Double-clickSelect word
Triple-clickSelect line
Cmd+ClickOpen URL in browser
Option+ClickPosition cursor at click location
Cmd+DragRectangular selection
ShortcutAction
Cmd+FFind
Cmd+GFind next
Cmd+Shift+GFind previous
Cmd+EUse selection for find
Cmd+JJump to selection

Marks and Bookmarks

ShortcutAction
Cmd+UMark current line
Cmd+Shift+UMark line and send return
Cmd+Shift+MInsert bookmark
Cmd+Up ArrowJump to previous mark
Cmd+Down ArrowJump to next mark
Cmd+Shift+ASelect between marks

Shell Line Editing (Emacs Mode)

Most shells (bash, zsh) use Emacs-style keybindings by default. These work in Terminal.app and other terminal emulators.

Cursor Movement

ShortcutAction
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+FMove forward one character
Ctrl+BMove backward one character
Option+F or Esc FMove forward one word
Option+B or Esc BMove backward one word
Ctrl+XXToggle between start of line and current position

Note: On macOS, Option+F and Option+B may require enabling “Use Option as Meta key” in Terminal preferences, or use Esc followed by the letter.

Deletion

ShortcutAction
Ctrl+DDelete character under cursor (or logout if empty line)
Ctrl+HDelete character before cursor (backspace)
Ctrl+WDelete word before cursor
Option+D or Esc DDelete word after cursor
Ctrl+UDelete from cursor to beginning of line
Ctrl+KDelete from cursor to end of line
Ctrl+YPaste (yank) last deleted text
Option+YCycle through kill ring

Text Manipulation

ShortcutAction
Ctrl+TTranspose characters (swap current and previous)
Option+T or Esc TTranspose words
Option+U or Esc UUppercase word from cursor
Option+L or Esc LLowercase word from cursor
Option+C or Esc CCapitalize word from cursor

History Navigation

ShortcutAction
Ctrl+P or Up ArrowPrevious command in history
Ctrl+N or Down ArrowNext command in history
Ctrl+RReverse incremental search
Ctrl+SForward incremental search (may need to enable)
Ctrl+GCancel search and restore original line
Option+< or Esc <First command in history
Option+> or Esc >Last command in history
Ctrl+OExecute command and fetch next from history
!!Repeat last command (type and press Enter)
!nRepeat command number n from history
!stringRepeat last command starting with string
!?stringRepeat last command containing string

Process Control

ShortcutAction
Ctrl+CInterrupt (SIGINT) - cancel current command
Ctrl+ZSuspend (SIGTSTP) - pause current command
Ctrl+DEnd of file (EOF) - logout or close input
Ctrl+\Quit (SIGQUIT) - forceful termination
Ctrl+SPause output (XOFF)
Ctrl+QResume output (XON)

Completion

ShortcutAction
TabAuto-complete command, filename, or variable
Tab TabShow all completions
Option+= or Esc =List possible completions
Option+* or Esc *Insert all completions
Option+/ or Esc /Complete filename
Ctrl+X /List possible filename completions

Screen Control

ShortcutAction
Ctrl+LClear screen, redraw current line at top
Ctrl+SStop output to screen
Ctrl+QResume output to screen

Zsh-Specific Shortcuts

Zsh includes additional features beyond standard Emacs bindings:

Zsh Expansion

ShortcutAction
TabComplete and show menu if ambiguous
Ctrl+ISame as Tab
Shift+TabReverse through completions
Option+H or Esc HRun help for current command
Option+?Show command help
Ctrl+X AExpand alias
Ctrl+X GList expansions of current glob
Ctrl+X *Expand glob inline

Zsh History

ShortcutAction
Ctrl+RIncremental history search
Ctrl+P / Ctrl+NNavigate history
Option+PHistory search backward (prefix match)
Option+NHistory search forward (prefix match)
fcEdit last command in editor
rRe-run last command
r foo=barRe-run last command, replacing foo with bar

Zsh Line Editor (ZLE)

ShortcutAction
Ctrl+X Ctrl+EEdit command line in $EDITOR
Option+QPush line to buffer, clear, execute next command, then restore
Option+'Quote line
Option+"Quote region
Ctrl+X Ctrl+VShow zsh version

Vi Mode

Both bash and zsh support vi-style editing. Enable with:

# Bash
set -o vi

# Zsh
bindkey -v

Vi Command Mode (Press Escape first)

KeyAction
hMove left
lMove right
wMove forward one word
bMove backward one word
eMove to end of word
0Move to beginning of line
$Move to end of line
^Move to first non-blank character
xDelete character
dwDelete word
ddDelete line
d$ or DDelete to end of line
d0Delete to beginning of line
cwChange word
ccChange line
c$ or CChange to end of line
yyYank (copy) line
ywYank word
pPaste after cursor
PPaste before cursor
uUndo
Ctrl+RRedo
iInsert mode at cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
rReplace single character
RReplace mode
kPrevious history
jNext history
/Search forward in history
?Search backward in history
nRepeat search
NRepeat search in reverse
vEdit command in $EDITOR

Vi Insert Mode

KeyAction
EscapeReturn to command mode
Ctrl+[Return to command mode
Ctrl+CCancel and return to command mode

iTerm2 Shortcuts

iTerm2 provides additional shortcuts beyond Terminal.app:

Windows and Tabs

ShortcutAction
Cmd+NNew window
Cmd+TNew tab
Cmd+WClose tab
Cmd+Shift+WClose window
Cmd+Option+WClose all tabs except current
Cmd+1-9Switch to tab
Cmd+Left/RightPrevious/next tab
Cmd+Shift+EnterMaximize pane
Cmd+Option+EExpose all tabs

Panes (Split View)

ShortcutAction
Cmd+DSplit vertically
Cmd+Shift+DSplit horizontally
Cmd+Option+ArrowNavigate between panes
Cmd+]Next pane
Cmd+[Previous pane
Cmd+Shift+EnterToggle pane zoom
Cmd+Option+Shift+H/VMove divider

Search and Selection

ShortcutAction
Cmd+FFind
Cmd+Shift+HPaste history
Cmd+;Autocomplete
Cmd+Shift+;Open command history
Cmd+Option+/Recent directories popup
Cmd+ClickOpen URL/file
Cmd+Option+BInstant replay

Text

ShortcutAction
Cmd+KClear buffer
Cmd+Ctrl+KClear scrollback
Cmd+/Find cursor
Cmd+Option+;Open command history
Cmd+Shift+MSet mark
Cmd+Shift+JJump to mark

Profiles and Settings

ShortcutAction
Cmd+IEdit session
Cmd+,Preferences
Cmd+Option+IToggle broadcast input
Cmd+Shift+OOpen quickly (fuzzy search tabs)

Less Pager Shortcuts

When viewing files with less:

KeyAction
Space or fForward one page
bBackward one page
dForward half page
uBackward half page
j or DownForward one line
k or UpBackward one line
g or HomeGo to beginning
G or EndGo to end
/<pattern>Search forward
?<pattern>Search backward
nNext search match
NPrevious search match
&<pattern>Show only matching lines
m<letter>Mark current position
'<letter>Go to mark
FFollow mode (like tail -f)
vOpen in $EDITOR
-NToggle line numbers
-SToggle line wrapping
hHelp
qQuit

Man Page Shortcuts

Man pages use less by default, but some additional keys work:

KeyAction
hHelp
qQuit
SpaceNext page
bPrevious page
/Search
nNext match
NPrevious match

Vim Quick Reference

For quick edits in vim:

Normal Mode

KeyAction
iInsert before cursor
aInsert after cursor
oInsert new line below
OInsert new line above
xDelete character
ddDelete line
yyCopy line
pPaste
uUndo
Ctrl+RRedo
/Search
nNext match
:wSave
:qQuit
:wqSave and quit
:q!Quit without saving
ZZSave and quit
ZQQuit without saving

Quick Reference Card

Essential Shortcuts (Memorize These)

ShortcutAction
Ctrl+CCancel/interrupt
Ctrl+DExit/EOF
Ctrl+ZSuspend
Ctrl+LClear screen
Ctrl+AStart of line
Ctrl+EEnd of line
Ctrl+UDelete to start
Ctrl+KDelete to end
Ctrl+WDelete word
Ctrl+RSearch history
TabAutocomplete
Up/DownHistory navigation

Terminal.app Essentials

ShortcutAction
Cmd+TNew tab
Cmd+WClose tab
Cmd+1-9Switch tab
Cmd+KClear all
Cmd+FFind
Cmd++/-Font size

Process Control

ShortcutAction
Ctrl+CKill foreground
Ctrl+ZSuspend
bgContinue in background
fgBring to foreground
jobsList background jobs