I use jk as my escape sequence in vim as well as vi-mode for bash and zshell. How do I do this in fish shell?
i.e. in vim:
inoremap jk <esc>
bash:
bind -m vi-insert '"jk": vi-movement-mode'
zsh
bindkey -M viins 'jk' vi-cmd-mode
What is the fish shell equivalent?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With