Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个片段:
insert_sudo () { zle beginning-of-line; zle -U "sudo "; zle end-of-line; } zle -N insert-sudo insert_sudo bindkey "\es" insert-sudo
但\es只将“sudo”附加到行尾,而不是我预期的行首。请帮忙!
\es
尝试以下操作:
insert_sudo() { BUFFER="sudo $BUFFER"; zle end-of-line; }
这直接修改了$BUFFER包含命令行内容的特殊变量,方法是预先添加sudo 然后将光标放在行尾。
$BUFFER
sudo
问题zle -U在于它仅在小部件完成后才会生效。从zsh手册:
zle -U
zsh
当前执行的小部件完成后,ZLE 将表现得好像字符串中的字符是由用户键入的一样。