You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
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?
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:
functionmy_vi_key_bindings
fish_vi_key_bindings
# add your own bindings here
end
set -g fish_key_bindings my_vi_key_bindings
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"
@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).
Activity
danielmatz commentedon Jun 4, 2014
You can't put custom bindings into config.fish. They get overwritten. Create a
fish_user_key_bindingsfunction in~/.config/fish/functions/fish_user_key_bindings.fishand set your bindings there.danielb2 commentedon 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 commentedon Jun 6, 2014
Redefining the
fish_user_key_bindingsinconfig.fishalso works for me.zanchey commentedon Jun 20, 2014
This isn't terribly well explained in the documentation - it's only in the
binddocumentation, 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 commentedon Jun 20, 2014
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.
lilyball commentedon Sep 22, 2014
Similarly, in a non-interactive script, using
bindbefore executing an interactive-modereadalso ignores the binding.I think the
bindbuiltin should emit an event, which should trigger__fish_config_interactivejust likefish_promptdoes. This will allowbindto work inconfig.fish. The only downside is it may be surprising to have__fish_config_interactivetriggered in the middle ofconfig.fish.lilyball commentedon Sep 22, 2014
On second thought, emitting an event for every bind seems kind of overkill. I guess if you want to use
bindin a non-interactive script with an interactivereadyou should just definefish_user_key_bindingsfor it.jhrmnn commentedon Oct 2, 2014
How does one sets custom key bindings while having
fish_vi_modeinconfig.fish? I understand the custom ones get overwritten. Should be the vi-mode turned on elsewhere?jhrmnn commentedon Oct 2, 2014
Ok, I did a quick fix for myself 257e55f. Not really sure what does
mean above the concerned part of code, so this quick fix might not be a good general solution?
lilyball commentedon Oct 2, 2014
We can't run
fish_user_key_bindingsfor all modes, because every single existing usage offish_user_key_bindingsis 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:
jhrmnn commentedon Oct 2, 2014
I see. Didn't occur to me. Thanks
faho commentedon Jul 16, 2015
Duplicate of #230.
danielb2 commentedon Jul 16, 2015
what @faho said
Keybinding needs to be in fish_user_key_binding()
ip2k commentedon 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:
(note the bind \cr re_search )
faho commentedon 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).