Skip to content

bind is ignored in config.fish #1495

Closed
Closed

Description

@danielb2

I have set bind \cr rsearch in my config.fish In order to use the reverse-search implemented here: https://github.com/jbonjean/re-search

However, C-R does not invoke this program, only when I type in the bind manually does it have any affect.

Activity

  1. danielmatz commented on Jun 4, 2014

    @danielmatz
    Contributor

    You can't put custom bindings into config.fish. They get overwritten. Create a fish_user_key_bindings function in ~/.config/fish/functions/fish_user_key_bindings.fish and set your bindings there.

  2. danielb2 commented on Jun 4, 2014

    @danielb2
    ContributorAuthor

    That works, thank you. That seems like very unexpected behavior. Why would the bindings get overwritten?

    Wouldn't it be better design if such bindings were not overwritten in the config file?

  3. saschagrunert commented on Jun 6, 2014

    @saschagrunert
    Contributor

    Redefining the fish_user_key_bindings in config.fish also works for me.

  4. zanchey commented on Jun 20, 2014

    @zanchey
    Member

    This isn't terribly well explained in the documentation - it's only in the bind documentation, which could be fixed.

    I think there is some useful context in #21 but I suspect there are some potential bugs in this area.

  5. danielb2 commented on Jun 20, 2014

    @danielb2
    ContributorAuthor

    It is intuitive to put it in the config file.Think .screenrc, or .tmuxrc, .zshrc, etc. Wouldn't it be better if it was made to work in the config.fish? Why limit the behavior? That or at the very least give the user a warning on the console if a bind is detected in the file with a hint of where to put the bind.

  6. added this to the fish-future milestone on Aug 7, 2014
  7. lilyball commented on Sep 22, 2014

    @lilyball
    Contributor

    Similarly, in a non-interactive script, using bind before executing an interactive-mode read also ignores the binding.

    I think the bind builtin should emit an event, which should trigger __fish_config_interactive just like fish_prompt does. This will allow bind to work in config.fish. The only downside is it may be surprising to have __fish_config_interactive triggered in the middle of config.fish.

  8. lilyball commented on Sep 22, 2014

    @lilyball
    Contributor

    On second thought, emitting an event for every bind seems kind of overkill. I guess if you want to use bind in a non-interactive script with an interactive read you should just define fish_user_key_bindings for it.

  9. jhrmnn commented on Oct 2, 2014

    @jhrmnn

    How does one sets custom key bindings while having fish_vi_mode in config.fish? I understand the custom ones get overwritten. Should be the vi-mode turned on elsewhere?

  10. jhrmnn commented on Oct 2, 2014

    @jhrmnn

    Ok, I did a quick fix for myself 257e55f. Not really sure what does

    # Do something nasty to avoid two forks
    

    mean above the concerned part of code, so this quick fix might not be a good general solution?

  11. lilyball commented on Oct 2, 2014

    @lilyball
    Contributor

    We can't run fish_user_key_bindings for all modes, because every single existing usage of fish_user_key_bindings is written for default mode, and running it under vi mode will almost certainly cause unexpected bindings to be set.

    The real answer is to just create a custom function and set that as your key bindings:

    function my_vi_key_bindings
        fish_vi_key_bindings
        # add your own bindings here
    end
    
    set -g fish_key_bindings my_vi_key_bindings
  12. jhrmnn commented on Oct 2, 2014

    @jhrmnn

    I see. Didn't occur to me. Thanks

  13. faho commented on Jul 16, 2015

    @faho
    Member

    Duplicate of #230.

  14. danielb2 commented on Jul 16, 2015

    @danielb2
    ContributorAuthor

    what @faho said

  15. added and removed
    docs
    on Jul 16, 2015
  16. removed this from the fish-future milestone on Oct 24, 2015
  17. ip2k commented on Jan 5, 2017

    @ip2k

    Just in case anyone runs across this, it was driving me crazy, but OMF had defined this in my /Users/MY_USERNAME/.local/share/omf/init.fish , so I just stuck the bind in there:

    # Read current theme
    read -l theme < $OMF_CONFIG/theme
    # Prepare Oh My Fish paths
    set -l core_function_path $OMF_PATH/lib{,/git}
    set -l theme_function_path {$OMF_CONFIG,$OMF_PATH}/themes*/$theme{,/functions}
    # Autoload core library
    set fish_function_path $fish_function_path[1] \
                           $core_function_path \
                           $theme_function_path \
                           $fish_function_path[2..-1]
    # Require all packages
    emit perf:timer:start "Oh My Fish init installed packages"
    require --path {$OMF_PATH,$OMF_CONFIG}/pkg/*
    emit perf:timer:finish "Oh My Fish init installed packages"
    # Backup key bindings
    functions -q fish_user_key_bindings
      and not functions -q __original_fish_user_key_bindings
      and functions -c fish_user_key_bindings __original_fish_user_key_bindings
    # Override key bindings, calling original if existent
    function fish_user_key_bindings
      read -l theme < $OMF_CONFIG/theme
      # Prepare packages key bindings paths
      set -l key_bindings $OMF_CONFIG/key_binding?.fish \
                          {$OMF_CONFIG,$OMF_PATH}/pkg/*/key_bindings.fish \
                          {$OMF_CONFIG,$OMF_PATH}/themes/$theme/key_binding?.fish
      # Source all keybindings collected
      for file in $key_bindings
        source $file
      end
      # Call original key bindings if existent
      functions -q __original_fish_user_key_bindings
        and __original_fish_user_key_bindings
      bind \cr re_search
    end
    emit perf:timer:start "Oh My Fish init user config path"
    require --no-bundle --path $OMF_CONFIG
    emit perf:timer:finish "Oh My Fish init user config path"
    emit perf:timer:finish "Oh My Fish initialisation"
    

    (note the bind \cr re_search )

  18. faho commented on Jan 5, 2017

    @faho
    Member

    @ip2k: As you might notice, that will still call your original fish_user_key_bindings, so you should define that instead. I don't believe that file is meant for user customization, so you'll have a bunch of issues (your binding disappearing on OMF update, most likely).

  19. 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions