Terminal shortcuts on a Mac: move around the command line fast

To move around the command line in Terminal on a Mac, press Control-A to jump to the start of the line and Control-E to jump to the end, Option-Left Arrow and Option-Right Arrow to move a word at a time, and hold Option and click to put the cursor where you click. Control-U deletes the line, Control-K deletes everything after the cursor, Control-W deletes the word before it, and Control-R searches the commands you have run before. Command-K clears the window.

Most of these come from zsh, the shell macOS has used by default since macOS Catalina, rather than from Terminal itself. That is why they work in other terminal apps too, and why they are not listed in any menu. Over SSH, the remote machine’s shell handles them; bash, the usual one on Linux servers, uses nearly the same keys.

Move the cursor without the arrow keys

Holding Left Arrow to get back to a typo at the start of a long command is the habit to break first.

  • Control-A and Control-E: start and end of the line.
  • Option-Left Arrow and Option-Right Arrow: back and forward one word. Terminal’s default keyboard settings send the shell’s word-jump codes for these, so they work without any setup.
  • Option-click: put the cursor there. Hold Option and click a spot in the command you are typing, and Terminal moves the cursor to it. It works on the line you are editing, not on old output above it.
  • Control-B and Control-F: back and forward one character, if you would rather not leave the home row.

Control-A and Control-E are worth learning for another reason: they also work in most Mac text fields, from TextEdit to the Safari address bar, along with Control-K. Text editing shortcuts that work in almost every Mac app lists the rest of that family.

Delete, and get it back

  • Control-U: delete the whole line. In zsh this clears the entire line wherever the cursor is. (In bash, the shell older Macs used, Control-U deletes only from the cursor back to the start.)
  • Control-K: delete from the cursor to the end of the line.
  • Control-W: delete the word before the cursor. In zsh a “word” here can include slashes, so on a path it may take more than you expect.
  • Control-Y: paste back what you just deleted. Text removed with Control-U, Control-K or Control-W is kept, so Control-K followed by Control-Y later is a quick way to move the end of a command somewhere else.
  • Control-C: abandon the line, or stop a running command. In Terminal, Command-Period does the same.

Two Escape combinations are worth knowing. Press Esc, let go, then press Q, and zsh parks the line you were typing and gives you an empty prompt; run something else, and the parked line comes back. Press Esc, then a period, to insert the last word of the previous command, which is usually the file or folder you just used.

Search your history with Control-R

Pressing Up Arrow fifteen times to find a command from yesterday is slow. Control-R is faster.

  1. Press Control-R. The prompt changes to a search.
  2. Type any part of the command you remember, such as docker or ssh prod. The most recent match appears.
  3. Press Control-R again to step to older matches.
  4. Press Return to run it, or press Control-E to stop searching and edit it first.
  5. Press Control-G to cancel the search.

Make Option work as Meta

The shell has more word commands than the ones above, such as deleting the next word, and they are bound to Meta, an old modifier key Mac keyboards do not have. Terminal can make Option act as Meta: open Terminal > Settings, click Profiles, choose your profile, click Keyboard, and turn on “Use Option as Meta key”. Edit > Use Option as Meta Key (Option-Command-O) switches it on and off from the menu.

With it on:

  • Option-B and Option-F move back and forward a word.
  • Option-D deletes the word after the cursor.
  • Option-Period inserts the last word of the previous command.

The cost is that Option stops typing special characters in that profile. On a US layout, Option-B types ∫ until you turn the setting on; on a British layout, Option-3 is how you type #, which you will need at the command line. Type special characters on a Mac with the Option key shows what Option normally types.

If you would rather keep Option as it is, Esc does the same job: Esc then B, Esc then F, Esc then D. Press Esc, let go, then press the letter.

Terminal’s own shortcuts

These belong to the Terminal app, and most of them are in its menus.

Shortcut What it does
⌘T / ⌘N New tab / new window
⌃⇥ / ⌃⇧⇥ Next / previous tab
⌘K Clear to Start (empties the window)
⌥⌘K Clear Scrollback
⌘↑ / ⌘↓ Jump to previous / next mark
⌘D / ⇧⌘D Split pane / close split pane
⌘+ / ⌘- / ⌘0 Bigger / smaller / default text
⌃⌘V Paste Escaped Text
⌘. Same as Control-C
⌥⌘O Use Option as Meta Key

A few notes on these:

  • Command-K versus Control-L. Command-K (Edit > Clear to Start) empties the window, including what you could scroll back to. Control-L is the shell’s clear: it gives you a clean screen, but earlier output is still there if you scroll up.
  • Marks. With Edit > Marks > Automatically Mark Prompt Lines ticked, Terminal marks each command you run, and Command-Up Arrow jumps back to the previous one. It is the fastest way to find the start of a long block of output.
  • Split pane. Command-D splits the window into two views of the same session, so you can scroll back through output in one half while you type in the other. It does not start a second shell.
  • Paths. Drag a file from the Finder into the Terminal window and its full path is typed for you. Control-Command-V pastes copied text with spaces and special characters escaped, ready for the shell.

When the shortcuts do nothing

If Control-A types something odd or does nothing, zsh may be in vi mode. zsh starts in vi mode when the EDITOR or VISUAL environment variable contains “vi”, which is common for people who set EDITOR=vim. Add bindkey -e to ~/.zshrc to keep the Emacs-style keys this page describes, then open a new window.

Inside a program, the program decides. In vim, less or man, Control-A and friends mean something else or nothing, and Control-R in vim is redo.

Learning them, and showing them on a recording

Because the line-editing keys live in the shell, no Terminal menu lists them, which makes them hard to discover and easy to forget. Typebar has a hand-made Terminal pack for exactly this kind of shortcut: it covers Control-A, Control-E, Control-U, Control-K, Control-W and Control-R alongside Terminal’s own menu shortcuts. Hold Control in Terminal for a moment and its on-screen keyboard can label those keys with what they do there.

If you record terminal tutorials, Control-R and Control-U are exactly the moves viewers miss, because nothing on screen says what happened. Typebar lights each key on an on-screen keyboard and shows the keys in its pill as you press them, so a Control-R is on screen even though the shell shows nothing. Record a terminal session that shows every key you press covers that setup.

Typebar is $9 once, with a 24-hour free trial, on macOS 14 or later.

Questions

Does Control-U work the same in bash and zsh?

No. In zsh, the default shell on current Macs, it deletes the whole line. In bash it deletes from the cursor back to the start of the line.

Why does Option-B type a symbol instead of moving back a word?

Because Option types special characters until you turn on “Use Option as Meta key” in Terminal > Settings > Profiles > Keyboard. Without it, use Esc then B.

How do I clear the Terminal window completely?

Press Command-K, or choose Edit > Clear to Start. Control-L only gives you a clean screen; the earlier output is still in the scrollback.