Last Updated: November 26, 2016
·
1.959K
· codegasm

Get alt-arrow keys working in fish on OSX

In trying out the fish shell I stumbled upon a bit of a hurdle with the shortcuts mapped to alt-left (previous directory), alt-right (next directory), alt-up and alt-down (pick section from previous command). It turns out that Terminal.app uses escape as the Meta key by default but fish responds to escape so it doesn't work for this purpose.

It's possible to use alt as the meta key by checking the "Use option as Meta key" checkbox in the preferences. This has a downside in that you can't access characters that require alt (the @ sign is alt-2 on my Swedish keyboard layout for example).

After much googling and no answers I managed to piece together a solution that gave me the alt-arrow shortcuts without giving up my alt modifier in general.

In the keyboard preferences for Terminal.app I setup the bindings for all the alt-arrows thusly:

alt-up: \033[1;3A
alt-down: \033[1;3B
alt-right: \033[1;3C
alt-left: \033[1;3D

The bindings break down like this:

  • \033 is the code for the escape key.
  • [1;3 is code for the Meta modifier (You'll see that the control and shift mappings for arrows have 5 and 2 instead of 3).
  • A/B/C/D are the codes for the arrows.

Warning! This is specific to fish, don't do this if you aren't using fish as your shell.

Now we can enjoy these neat features of fish, hope this helps anyone trying to get the most out of fish on OSX.

1 Response
Add your response

over 1 year ago ·