abbr -a gc git commit
After expanding gc
via pressing space
, I want to undo via pressing ctrl+space
in fish shell.
How do i do that?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityTo bind a key in fish, use
bind sequence thing-to-bind-to
or
bind -k keyname thing-to-bind-to
To find out the sequence, use fish_key_reader
and press whatever you want [0].
So, if we do that, we get:
Press a key: bind -k nul 'do something'
So we bind the keyname "nul" to "undo" [1]:
bind -k nul undo
Note: This is a bad idea because ctrl-space is already bound to insert a space without expanding an abbreviation by default. So now you'd have to expand your abbreviation, undo it, press space again which expands the abbreviation again, ...
You would need to bind another key to insert a space without expanding. E.g. to make ctrl-g do that:
bind \cg 'commandline -i " "'
Instead you can simply use ctrl-z to undo, which is bound by default, and then press ctrl-space to insert your space without expanding the abbreviation.
[0]: If fish_key_reader doesn't print anything, that means your terminal doesn't send anything for your key combination. This can happen e.g. if the terminal uses it for its own bindings.
Also the protocol terminals use to send key combinations by default is fairly horrible and can't express a lot of combinations - e.g. there is no way to distinguish ctrl-i from tab, or ctrl-shift-X from ctrl-X. There are alternatives, but none have widespread buy-in.
[1]: If you use vi-mode, bind
without a mode will set it in vi-normal mode. To set something in e.g. insert mode, add -M insert
. Or -M visual
for visual mode.