Skip to content

Can't add key bindings in config.fish #230

Closed

Description

@sjl

When add lines like:

echo foo
bind \cn clear

To my config.fish file, the foo will indeed be echoed to the screen when I start a new shell, but the new ctrl+n binding doesn't work (it does what ctrl+n usually does).

If I then run that exact same bind command manually, it does work.

Do I need to use a different syntax to bind things in the config file?

Activity

  1. maxfl commented on Jul 16, 2012

    @maxfl
    Contributor

    Define a function fish_user_keybindings setting your keybindings. It will be called in right time.

  2. sjl commented on Jul 16, 2012

    @sjl
    Author

    Ah, that works. Perhaps that could be mentioned in the bind documentation?

  3. rubycut commented on Jul 29, 2012

    @rubycut
    function fish_user_keybindings
    bind \e\[1\;5C forward-word
    bind \e\[1\;5D backward-word
    end
    

    this doesn't work for me.

  4. rubycut commented on Aug 2, 2012

    @rubycut

    where should this function be defined? in config.fish or in functions directory?

    Neither of those works for me.

  5. maxfl commented on Aug 3, 2012

    @maxfl
    Contributor

    that is strange. Can you put 'echo user keybindings' into this function. Is it really called?

    Both ways should be possible. This function should be called after sourcing config.fish.

  6. rubycut commented on Aug 3, 2012

    @rubycut

    It's not called at all. I compiled fish from this repo yesterday, master branch. e1de72d

    config.fish done
    Welcome to fish, the friendly interactive shell
    Type help for instructions on how to use fish
    *master> cat .config/fish/config.fish
    
    function fish_user_keybindings  
      bind \e\[1\;5C forward-word
      bind \e\[1\;5D backward-word
      echo bindings called from config.fish
    end
    echo config.fish done
    
    *master> cat .config/fish/functions/binds.fish 
    function fish_user_keybindings
      bind \e\[1\;5C forward-word
      bind \e\[1\;5D backward-word
      echo user keybindings from functions/binds.fish
    end
    
  7. maxfl commented on Aug 3, 2012

    @maxfl
    Contributor

    The first example works well for me.
    The second example is not valid. The filename should be the same as the function name or fish would be not able to find it and load.

    Do you see "config.fish done" message?

    What is the output of 'type __fish_config_interactive | grep fish_user_keybindings'
    the fish_user_keybindings should be called from it.

  8. rubycut commented on Aug 3, 2012

    @rubycut

    key bindings are defined in __fish_config_interactive.fish in /usr/local/share/fish/functions

    echo $fish_function_path
    /home/user/.config/fish/functions /etc/fish/functions /usr/local/share/fish/functions
    

    inside it says

    # This function is called by the __fish_on_interactive function, which
    # is defined in config.fish.
    
  9. rubycut commented on Aug 3, 2012

    @rubycut

    http://ridiculousfish.com/shell/user_doc/html/index.html#initialization

    "On startup, fish evaluates the files /usr/share/fish/config.fish (Or /usr/local/fish... if you installed fish in /usr/local)"

    This is not correct, it evaluates first /usr/share/fish/config.fish and then if that doesn't exist, it tries: /usr/local/share/fish/config.fish

    dpkg -r fish
    

    This removes /usr/share/fish/config.fish And it all works now.

  10. rubycut commented on Aug 3, 2012

    @rubycut

    Thanks for the tip, I guess I we can close this.

  11. rubycut commented on Aug 3, 2012

    @rubycut

    But as @sjl says, it should be documented before closing.

  12. MaskRay commented on Dec 18, 2012

    @MaskRay

    fish_user_keybindings -> fish_user_key_bindings

  13. tiye commented on Sep 8, 2013

    @tiye

    I got some problem on this too...
    Looks like Fish(or maybe oh-my-fish) enables history searching by default,
    but it doesn't begin from the first character of command,
    vim could get vim a sudo vim b or even touch vim c,
    I tried running bind and find these...

    bind \e\eOA history-token-search-backward
    bind \e\eOB history-token-search-forward
    bind \e\e\[A history-token-search-backward
    bind \e\e\[B history-token-search-forward
    bind \eO3A history-token-search-backward
    bind \eO3B history-token-search-forward
    bind \e\[3A history-token-search-backward
    bind \e\[3B history-token-search-forward
    bind \e\[1\;3A history-token-search-backward
    bind \e\[1\;3B history-token-search-forward
    bind \cp history-search-backward
    bind \cn history-search-forward

    What do history-token-search-forward and \cp \cn mean here?

  14. zanchey commented on Sep 8, 2013

    @zanchey
    Member

    \cp and \cn are the Ctrl-P and Ctrl-N characters. history-search-forward means what it says on the tin - search forward in history (only works once you have searched backwards).

    Note that the behaviour you describe is not what this issue is tracking; perhaps you could open a new issue?

  15. tiye commented on Sep 8, 2013

    @tiye

    Moved my problem here: #992 about rewriting up arrow for history-search-backward

  16. ndemou commented on Mar 18, 2014

    @ndemou

    I tried to add my custom key bindings in ~/.config/fish/config.fish and in ~/.config/fish/functions/fish_user_keybindings.fish but they were ignored. The reason seems to be that /usr/share/fish/functions/fish_default_key_bindings.fish is loaded after ~/.config/fish/config.fish. See output of strace bellow:

    ndemou@ndXPS13 ~> strace -eopen fish
    open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
    [...]
    open("/usr/share/fish/config.fish", O_RDONLY|O_LARGEFILE) = 4
    open("/etc/fish/config.fish", O_RDONLY|O_LARGEFILE) = 4
    open("/home/ndemou/.config/fish/config.fish", O_RDONLY|O_LARGEFILE) = 4
    /home/ndemou/.config/fish
    open("/usr/share/fish/functions/__fish_config_interactive.fish", O_RDONLY|O_LARGEFILE) = 6
    open("/usr/share/fish/functions/eval.fish", O_RDONLY|O_LARGEFILE) = 6
    open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 4
    open("/usr/share/fish/functions/fish_default_key_bindings.fish", O_RDONLY|O_LARG
    

    So my workaround is to call fish_user_keybindings just before the end of /usr/share/fish/functions/fish_default_key_bindings.fish. See:

    ndemou@ndXPS13 ~> tail -4 /usr/share/fish/functions/fish_default_key_bindings.fish
    
            fish_user_keybindings # hack to load my custom key bindings
    end
    

    Of course this is an ugly hack. Am I missing something or is this really a bug?

    ndemou@ndXPS13 ~> fish --version
    fish, version 1.23.1
    ndemou@ndXPS13 ~> cat /etc/lsb-release 
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=12.04
    DISTRIB_CODENAME=precise
    DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"
    ndemou@ndXPS13 ~> uname -a
    Linux ndXPS13 3.5.0-47-generic #71~precise1-Ubuntu SMP Wed Feb 19 22:05:41 UTC 2014 i686 i686 i386 GNU/Linux
    
  17. siteshwar commented on Mar 18, 2014

    @siteshwar
    Contributor
  18. added
    docs
    on Jul 16, 2015
  19. added a commit that references this issue on Jan 16, 2016
    7ae5136
  20. modified the milestones: , fish-future on Feb 8, 2016
  21. jeff-hykin commented on Feb 23, 2017

    @jeff-hykin

    [SOLVED]
    My issue was that I downloaded the fish Mac app, then installed fish with homebrew
    Just using the app doesn’t trigger ~/.config/fish/config.fish or /usr/local/share/fish/functions/fish_default_key_bindings.fish

    Solution
    I just used
    chsh -s `which fish``
    (ignore the second back-tic mark)
    to make fish the default shell, and then ndemou’s hack worked for me (even when I open fish via the app)

  22. ndemou commented on Feb 26, 2017

    @ndemou

    Note that according to the manual the proper solution this issue is to "put the bind statements into a function called fish_user_key_bindings, which will be autoloaded."

  23. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions