How can I remap <CapsLock> to <Escape> in the fish shell?

67 Views Asked by At

I've just installed fish shell in my archlinux. Because I use vi-mode in fish, I want to remap my <CapsLock> to <Escape>. How can I archieve it by adding something into my ~/.config/config.fish.

I've see the document of bind, but I don't know how to express <Escape> and <CapsLock>.

1

There are 1 best solutions below

1
faho On BEST ANSWER

You do the same thing you would do for any key, as the fish documentation explains:

You run fish_key_reader, you press your key (or key combination), and you'll see what that says.

If it doesn't do anything, which I would expect for capslock, that's because the terminal doesn't pass on the key to the shell. (press another key to exit fish_key_reader)

If that is the case, it would be impossible to bind it through config.fish, and you would have to change it in your terminal or desktop settings.


If you do get a key, you wouldn't "remap it to escape", you would bind it to the same thing as escape. Assuming you're interested in insert mode, you would run

bind -M insert \e

to find out what escape (\e) is bound to in insert mode:

bind --preset -M insert \e 'if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end'

And then you would bind your key the same. E.g. if you wanted ctrl-g to do the same thing, fish_key_reader explains:

bind \cG 'do something'

so it is \cG, so you would bind:

bind -M insert \cG 'if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end'

without the --preset because that denotes a binding that belongs to the default binding preset.