我为.zshrc编写了一个小函数来加载插件并设置其键绑定
function loadPlugin() {
# Function to load external zsh plugins and set keybindings.
pluginName=$1
pluginPath=$2
if [ -r $pluginPath ];then
source $pluginPath
else
echo "$pluginName plugin can not be found at: $pluginPath"
fi
# set keybindings
shift
shift
while [[ $# > 0 ]]; do
bindkey -M emacs '$1' '$2'
shift
shift
done
}
加载部分有效,但没有设置键绑定:
loadPlugin "History search" \
"$HOME/zsh.d/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh" \
'^p' "history-substring-search-up" \
'^n' "history-substring-search-down"
没有错误输出,如果我在使用相同的参数调用它之后调用函数外部的绑定命令,它们将起作用。
bindkey -M emacs '^p' "history-substring-search-up"
bindkey -M emacs '^n' "history-substring-search-down"
答案 0 :(得分:1)
您的单引号会阻止展开$1
和$2
。改为使用双引号。
bindkey -M emacs "$1" "$2"