Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind is ignored in config.fish #1495

Closed
danielb2 opened this issue Jun 4, 2014 · 15 comments
Closed

bind is ignored in config.fish #1495

danielb2 opened this issue Jun 4, 2014 · 15 comments

Comments

@danielb2
Copy link
Contributor

danielb2 commented Jun 4, 2014

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.

@danielmatz
Copy link
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.

@danielb2
Copy link
Contributor Author

danielb2 commented Jun 4, 2014

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?

@saschagrunert
Copy link
Contributor

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

@zanchey
Copy link
Member

zanchey commented Jun 20, 2014

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.

@danielb2
Copy link
Contributor Author

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.

@zanchey zanchey added this to the fish-future milestone Aug 7, 2014
@lilyball
Copy link
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.

@lilyball
Copy link
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.

@jhrmnn
Copy link

jhrmnn commented Oct 2, 2014

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?

@jhrmnn
Copy link

jhrmnn commented Oct 2, 2014

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?

@lilyball
Copy link
Contributor

lilyball commented Oct 2, 2014

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

@jhrmnn
Copy link

jhrmnn commented Oct 2, 2014

I see. Didn't occur to me. Thanks

@faho
Copy link
Member

faho commented Jul 16, 2015

Duplicate of #230.

@danielb2
Copy link
Contributor Author

what @faho said

@zanchey zanchey added duplicate and removed docs An issue/PR that touches or should touch the docs labels Jul 16, 2015
@faho faho removed this from the fish-future milestone Oct 24, 2015
tasuten added a commit to tasuten/dotfiles-obsolated that referenced this issue Dec 14, 2016
@ip2k
Copy link

ip2k commented Jan 5, 2017

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 )

@faho
Copy link
Member

faho commented Jan 5, 2017

@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).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants