Move Cursor Word by Word on Mac Terminal
To move the cursor word by word in the Mac Terminal, press Option+Left Arrow to go back one word and Option+Right Arrow to go forward one word. This works in the default bash and zsh shells, as well as in most command-line programs that use standard line editing.
Why the Default Keys Don’t Work
Many Mac users coming from Windows expect Ctrl+Left/Right to jump between words, but macOS Terminal uses Option by default. The reason is historical: the Terminal emulates the classic Unix terminal behavior where the Option key acts as the Meta key. In the readline library (used by bash and many other tools), Meta+b and Meta+f are the word-movement commands. macOS maps Option to Meta, so Option+Left/Right sends the same escape sequences that readline interprets as backward-word and forward-word.
If you’re using zsh (the default shell since macOS Catalina), the same Option+Arrow shortcuts work because zsh’s line editor (zle) also recognizes these key bindings by default.
How the Key Binding Works
When you press Option+Left Arrow, the Terminal sends the escape sequence ESC b (or \033b) to the shell. The shell’s line editor receives this and moves the cursor to the beginning of the previous word. Similarly, Option+Right Arrow sends ESC f, moving to the end of the next word.
This works in:
- bash and zsh prompts
- Python’s interactive REPL
- Node.js REPL
- MySQL and PostgreSQL command-line clients
- Any program that uses GNU readline or a compatible library
It does not work in programs that have their own custom key handling, such as vim (unless you’re in insert mode with the right settings) or emacs (which uses its own bindings).
Alternative Key Combinations
If Option+Arrow doesn’t work for you, or you prefer a different set of keys, you have several alternatives:
- Ctrl+A / Ctrl+E – jump to the beginning or end of the line (not word-by-word, but useful)
- Esc then B / F – press Escape, release, then press b or f to move word-wise (works even if Option is not mapped)
- Ctrl+Left/Right in some apps – some terminal programs (like iTerm2) let you rebind these to work
In iTerm2, you can go to Preferences → Keys and set Option+Left/Right to send the escape sequences ESC b and ESC f if they don’t work by default.
Customizing Key Bindings in zsh and bash
If you want to change the default bindings, you can edit your shell configuration file. For zsh, add this to ~/.zshrc:
bindkey "\e[1;3C" forward-word
bindkey "\e[1;3D" backward-word
For bash, add this to ~/.inputrc:
"\e[1;3C": forward-word
"\e[1;3D": backward-word
These bindings assign Ctrl+Right and Ctrl+Left (which send the escape sequences shown) to word movement. You can also use bind -P in bash to list all current bindings and find which keys are already assigned.
Common Problems and Fixes
Option+Arrow does nothing: This usually means the Terminal profile has “Use Option as Meta key” turned off. Go to Terminal → Preferences → Profiles → Keyboard and check that “Use Option as Meta key” is enabled. If it’s off, Option+Arrow might insert special characters instead.
Cursor moves but skips too much: The definition of a “word” can vary. In readline, a word is a sequence of alphanumeric characters and underscores. Punctuation like - or . is treated as a delimiter. If you want to include hyphens as part of words, you can modify the iskeyword setting in zsh or the wordchars variable in readline.
Only works in some programs: As mentioned, custom line editors (like in vim or less) may not respect these bindings. In vim, you can use w and b in normal mode to jump word-wise.
Frequently Asked Questions
Why does Option+Left not work in my Terminal?
Most likely the “Use Option as Meta key” setting is disabled. Go to Terminal → Preferences → Profiles → Keyboard and check the box. If it’s already checked, try pressing Escape then b or f manually to see if the shell receives the correct sequence.
Can I use Ctrl+Left instead of Option+Left?
By default, Ctrl+Left/Right in Terminal sends different escape sequences that are not bound to word movement. You can rebind them by editing ~/.inputrc (for bash) or using bindkey (for zsh). Some third-party terminals like iTerm2 have a built-in setting to make Ctrl+Left work.
Does this work in VS Code’s integrated terminal?
Yes, VS Code’s terminal uses the same key handling, so Option+Left/Right works there as well. If it doesn’t, check your VS Code keybindings to ensure the terminal is not intercepting those keys.
How do I move word-by-word in vim?
In vim’s normal mode, press w to move to the start of the next word, b to move back to the start of the previous word, and e to move to the end of the current word. In insert mode, you can use Ctrl+Left/Right if your terminal supports it, but it’s often easier to switch to normal mode.
Why do some people use Ctrl+Left in other apps?
On macOS, many native text fields (like in Safari or TextEdit) use Ctrl+Left/Right for word movement. This is a macOS system-wide shortcut. Terminal is different because it’s emulating a Unix terminal, which historically used Meta (Option) for such functions.
Summary of Key Combinations
Here’s a quick reference table for word movement:
| Action | Shortcut |
|---|---|
| Move back one word | Option+Left Arrow |
| Move forward one word | Option+Right Arrow |
| Move to start of line | Ctrl+A |
| Move to end of line | Ctrl+E |
| Delete previous word | Option+Delete |
Knowing these shortcuts can significantly speed up your command-line editing. Once you get used to Option+Arrow, you’ll wonder how you managed without it.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.