Skip to content
Darin Larimore
All posts

Option and Command arrow keys

3 min read
On this page
  1. The four moves
  2. Editors
  3. The terminal is where it breaks
  4. The short version

Most of the editing I do in a day is not typing new code. It is moving a cursor to the right place in a line that already exists and changing part of it. On a Mac that is almost entirely two modifiers and the arrow keys, and the same muscle memory works in every text field, in my editor and, with one setting, in the terminal.

The four moves

Option is the word key and Command is the line key.

  • Option plus Left or Right jumps to the previous or next word boundary.
  • Command plus Left or Right jumps to the start or end of the line.
  • Command plus Up or Down goes to the start or end of the document.
  • Hold Shift with any of those and it selects instead of moving.

Delete follows the same rule. Option plus Delete removes the word before the cursor; Command plus Delete removes everything back to the start of the line.

That is macOS behaviour, not an editor feature. It works in the Safari address bar, a Slack message and a Finder rename field. The payoff is that I never think about it.

Editors

VS Code ships those bindings on the Mac, and my keybindings.json does not touch arrows at all. The only custom entries are Command-backslash for zen mode, Control-Command-C to open a native terminal, and Shift-Enter inside the integrated terminal sending a backslash and a newline so a multi-line command keeps going:

{
  "key": "shift+enter",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "\\\r\n" },
  "when": "terminalFocus"
}

Zed is set to "base_keymap": "VSCode", so the same hands work there. The one related setting I change is "multi_cursor_modifier": "cmd_or_ctrl", so adding a cursor is Command-click and Option stays reserved for words.

The terminal is where it breaks

A terminal does not know what Option means. Out of the box the shell sees Option-Left as a character, not as a request to move a word. There are two fixes: tell the terminal that Option is Meta, so Option-B and Option-F become the Emacs word movements zsh already understands, or map the arrow combinations to escape sequences directly.

My iTerm2 profile does the second. Option is left as a normal key (the profile's "Option Key Sends" is Normal, not Esc+), and the keyboard map translates:

  • Option-Left and Option-Right to Esc b and Esc f
  • Command-Left and Command-Right to 0x01 and 0x05 (Control-A and Control-E)
  • Option-Delete to Esc Delete, which kills the word backwards
  • Command-Delete to 0x15 (Control-U), which kills to the start of the line

Those are the mappings iTerm2's Natural Text Editing preset gives you. I prefer them to Option-as-Meta because Option still types characters when I need one, and the Command versions, which Meta cannot give you, come for free.

The shell side is stock. My .zshrc has no bindkey lines and no WORDCHARS; oh-my-zsh's defaults do the rest. Two consequences are worth knowing. zsh's default WORDCHARS treats /, - and . as part of a word, so Option-Left from the end of a path jumps the whole path, which is what I want in a shell and not what an editor does. And zsh-autosuggestions lists forward-word as a partial-accept widget, so Option-Right accepts one word of a grey suggestion while End or Right takes all of it.

The short version

Option for words, Command for lines, Shift to select, and Delete follows the same rule. Set the terminal to translate the arrow combinations and the same hands work in the shell. Everything else is configuration I have never had to touch.