作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的 .zshrc 文件中使用这个优秀的脚本来完成 zsh 缩写: http://zshwiki.org/home/examples/zleiab
上面的效果很好。
这是我的问题:
如何修改这些缩写或脚本,使光标在缩写的特定部分结束,而不是像这样结束:
"ac" "ack -C 5 {cursorHere} --ignore-dir=.build"¬
应缩写为:
ack -C 5 [cursor] --ignore-dir=.build
最佳答案
更新魔术缩写扩展为
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
command=${abbreviations[$MATCH]}
LBUFFER+=${command:-$MATCH}
if [[ "${command}" =~ "__CURSOR__" ]]
then
RBUFFER=${LBUFFER[(ws:__CURSOR__:)2]}
LBUFFER=${LBUFFER[(ws:__CURSOR__:)1]}
else
zle self-insert
fi
}
缩写将设置为
"ac" "ack -C 5__CURSOR__--ignore-dir=.build"
"Ii" "Hello__CURSOR__! How are you"
完整脚本
setopt extendedglob
typeset -Ag abbreviations
abbreviations=(
"ac" "ack -C 5__CURSOR__--ignore-dir=.build"
"Ii" "Hello__CURSOR__! How are you"
"Im" "| more"
"Ia" "| awk"
"Ig" "| grep"
"Ieg" "| egrep"
"Iag" "| agrep"
"Igr" "| groff -s -p -t -e -Tlatin1 -mandoc"
"Ip" "| $PAGER"
"Ih" "| head"
"Ik" "| keep"
"It" "| tail"
"Is" "| sort"
"Iv" "| ${VISUAL:-${EDITOR}}"
"Iw" "| wc"
"Ix" "| xargs"
)
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
command=${abbreviations[$MATCH]}
LBUFFER+=${command:-$MATCH}
if [[ "${command}" =~ "__CURSOR__" ]]
then
RBUFFER=${LBUFFER[(ws:__CURSOR__:)2]}
LBUFFER=${LBUFFER[(ws:__CURSOR__:)1]}
else
zle self-insert
fi
}
no-magic-abbrev-expand() {
LBUFFER+=' '
}
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
bindkey -M isearch " " self-insert
关于bash - 如何在 Zsh 缩写后移动光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28573145/
我是一名优秀的程序员,十分优秀!