How to remap escape insert mode to 'jk' in fish shell?

Here is a blog post that does exactly what I was looking for:

https://fedragon.github.io/blog/2015/03/22/vimode-fishshell-osx/

TLDR;)

~/.config/fish/functions/fish_user_key_bindings.fish
---------------------------------------------------
function fish_user_key_bindings
  fish_vi_key_bindings
  bind -M insert -m default jk backward-char force-repaint
end

And

~/.config/fish/config.fish
---------------------------------------------------
set fish_key_bindings fish_user_key_bindings

I'm assuming you've already enabled vi mode by executing fish_vi_key_bindings. Otherwise the question doesn't make sense :-)

Create a file named ~/.config/fish/functions/fish_user_key_bindings.fish that contains this:

function fish_user_key_bindings
    bind -M insert jk "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char force-repaint; end"
end

You can run the bind interactively but it won't be persistent across new fish sessions unless you create that autoloaded function. Also, if you switch between vi and emacs binding you'll want to guard that bind so it's only done for vi mode:

if test "$__fish_active_key_bindings" = "fish_vi_key_bindings"
    bind ....
end

Tags:

Vi

Vim

Shell

Fish