Srijan R. Shetty bio photo

Srijan R. Shetty

Email Twitter LinkedIn Github RSS

Another short one but very useful trick in my moving from Linux to Mac series.

One of my most used shortcuts in the terminal is Alt + ., which I adapted from my bash workflow to my zsh workflow when I started using zsh. It basically inserts the last word from the previous command. This turns out to be very handy and I use it multiple times a day.

There is no out of the box way to accomplish this on Mac, unless you use iTerm.

The first step is opening up iTerm preferences and navigate to the keybindings section.

iTerm > Preferences > Keybindings

Once in the keybindings section:

  1. Click +.
  2. In the dialogue select any Keyboard Shortcut you want. I used Cmd + ..
  3. Select Action as Send Escape Sequence.
  4. Add altdot as the Escape Sequence.
  5. Hit Save and we’re done!
Add Keyboard Shorcut with Send Escape Sequence

The next step is configuring zsh keybindings to process the Escape sequence.

# somewhere in your zsh config
bindkey "^[altdot" insert-last-word

And viola, now the keybindings work. This process works mutatis mundis for other keybindings that you want to import from your workflow in bash/zsh from linux.