Search code examples
linuxshellfish

Fish programming: Why are `bind` commands in config.fish not executed?


At end of /usr/share/fish/config.fish, I have the following commands:

bind \e\[1\;5C forward-word
bind \e\[1\;5D backward-word
echo foo

Afterwards I run fish, it prints "foo". I then run bind to print a list of all binded key combinations, however there are no "forward-word" and "backward-word" entries in the output of bind.

Did I miss something?


Solution

  • EDIT: fish 3.0+ allows you to create key bindings during startup inside your config.fish or configuration snippets (conf.d/*.fish). See fish-shell/pull/5195


    Since those keybindings are already defined in fish_default_key_bindings I am guessing the problem lies with your terminal emulator and that it doesn't send the correct escape sequence.

    You should also not edit the global config /usr/share/fish/config.fish. Your custom config goes in ~/.config/fish/config.fish

    If you want to specify your custom key bindings it should be done inside the function fish_user_key_bindings.

    You can do this manually through editing: ~/.config/fish/functions/fish_user_key_bindings.fish.

    Or use the tools provided:

    If the function does not exist you can do:

    function fish_user_key_bindings
      bind \e\[1\;5C forward-word
      bind \e\[1\;5D backward-word
    end
    funcsave fish_user_key_bindings
    

    Or if you already have the function:

    funced fish_user_key_bindings
    funcsave fish_user_key_bindings
    

    The reason why you cannot specify these in your config is that they are reset at a later point, here inside fish_default_key_bindings.