Terminal keyboard shortcuts

Common

  • Command-Z: Undo the last change, supported in Bash and Zsh
  • Command-Right Click: (Or middle mouse click, if any) Paste last selected string

Bash / Zsh

Moving the Cursor

  • Command–Left Arrow or Control-A or Home: Beginning of line
  • Command–Right Arrow or Control-E or End: End of line
  • Control-F: Forward one character
  • Control-B: Back one character
  • Option-Left Arrow or Meta-B: Back one word
  • Option-Right Arrow or Meta-F: Forward one word
  • Control-XX: Move between the beginning of the line and the current cursor position. This allows you to press Control-XX to return to the start of the line, change something, and then press Control-XX to go back to your original cursor position. To use this shortcut, hold the Control key and tap the X key twice.

Select Text in Alternate Screen

Modern terminals have two screen buffers: the primary screen buffer (used by bash, zsh etc.) and alternate screen buffer (used by vim, nano, htop, less, screen, tmux etc.).

While the alternate screen is displayed, mouse events may be captured by the programs that support Mouse Reporting. For this case, press and hold the Fn key and drag to select text.

Delete Text

  • Option-Delete or Meta-Delete: Delete the Word before the cursor
  • Meta-D: Delete the Word after the cursor
  • Control-D: Delete the character under the cursor
  • Control-H or Delete: Delete one character (backwards)

Cutting and Pasting

  • Option-Delete or Control-W: Cut one word (backwards), adding it to the clipboard
  • Control-K: Cut to end of line, adding it to the clipboard
  • Control-U: Cut to beginning of line, adding it to the clipboard
  • Control-Y: Paste the last text you cut from the clipboard (yank)

Capitalizing Characters

  • Meta-U: Upper capitalize every character from the cursor to the end of the current word
  • Meta-L: Lower the case of every character from the cursor to the end of the current word
  • Meta-C: Capitalize the character under the cursor and move to the end of the word.

Fixing Typos

  • Control- _: Undo the last change
  • Meta-T: Swap current word with previous
  • Control-T: Swap the last two characters before the cursor

Tab Completion

  • Tab: Automatically complete the file, directory, or command you’re typing

History Search

Press Control-R to search through the history. Continue pressing Control-R until you find the entry you're looking for. Press Enter to execute the current expression. Press Right Arrow to modify the current expression. Press Control-G to escape from search mode.

Screen Control

  • Control-L: Clear screen
  • Control-S: Stop output to screen (for long running verbose commands)
  • Control-Q: Re-enable screen output

Process Control

  • Control-C: Kill current process
  • Control-D: Exit shell
  • Control-Z: Suspend process

Meta Key

To have the Option key on the keyboard act as a meta key, select “Use Option (⌥) as Meta key.” This is useful for computers running X11 and for some text editors.