MacOS – What’s the fish shell equivalent to `set -o vi` to get vi/vim key bindings to access command history and edit

bashcommand linefishhomebrewmacos

I'm one of the "cursed ones" that got their start in vi instead of emacs so the shell editing commands I am used to are set in bash with set -o vi but this doesn't work in the fish shell.

How can I enable vi / vim style key commands in the friendly interactive shell that runs when you install fish from https://brew.sh?

Best Answer

There is a command in fish to enable this one time and that command is:

fish_vi_key_bindings

To set this at every start up for all instances of the shell, create a startup file if it doesn't exist (or touch the date in case it exists) and then add that command to the startup file.

mkdir -p ~/.config/fish 
touch ~/.config/fish/config.fish
echo fish_vi_key_bindings >> ~/.config/fish/config.fish

This is well documented on Stack Overflow as well, but I figured a clear answer here would help some people find the setup sooner. https://stackoverflow.com/questions/28444740/how-to-use-vi-mode-in-fish-shell