Move the Cursor by Word at the Command Prompt on the Mac (iTerm)

iTerm is a great replacement for the default Terminal app on the Mac, comes with lots of nice features like horizontal & vertical spits, necessities like tmux integration and a whole lot more. When I made the switch, I had to figure out how to bring over the ability to move the cursor by word or delete words at the prompt instead of one character at a time.

The short video below demonstrates what it looks like to have that ability:

This requires making a few minor changes to the settings.

Open the Preferences pane for iTerm and navigate to Profiles -> Keys. At the bottom of this pane, you’ll see the Keyboard Behaviour section. Change the Left option key acts as: and Right option key acts as: to the +Esc option.

iTerm Preferences – Keys

Note: the Terminal.app equivalent of this is the Use Option as Meta key checkbox as shown in this screenshot. iTerm recommends using +Esc instead in the FAQ.

The change you just made will let your delete by word (instead of single character) at the prompt if you hit the delete key while holding down the option () key.

Next we’ll setup the arrows keys to move by word when the option key is held down.

  • Option + Left arrow (⌥ + ←) – Move one word left
  • Option + Right arrow (⌥ + →) – Move one word right

In the same preferences window, scroll in the Key Mappings section until you see the ⌥← key combination and double click it to edit.

Change the action to Send Escape Sequence and the value for the Esc+ input to b

Option + Left Arrow

Do the same for the ⌥→ key combination and this time use f for the value.

Option + Right Arrow

Now you are set. You can navigate by word using the arrow keys when combined with the option () key and can delete words using option + delete at the iTerm prompt, like everywhere else on the Mac.

Dec 2015

రామ్ . राम . Rām