zsh 中的历史扩展

history expansion in zsh

根据文档,!! 应该在点击 <tab> 后扩展到最后一个命令。但是,我的设置并非如此(我使用默认的 oh-my-zsh)。这是一个例子: $ echo 1 1 $ echo 2 2 $ !!<tab> $ echo 1

此外,!#不会扩展到当前行输入的内容。相反,它扩展到最后一个命令 $ echo 1 1 $ echo 2 2 $ echo 3 !#<tab> $ echo 3 echo 2

有什么选项控制这个吗?

我查看了 github and it look like parameter expansion is not enabled out of the box. According to oh-my-zsh documentation 上的默认 oh-my-zsh 完成设置,任何覆盖都应进入 custom/ 目录,在以 *.zsh 结尾的文件中。使参数扩展起作用应该就像将包含以下内容的文件放在那里一样简单:

zstyle ':completion:*' completer _expand _complete

您正在寻找的完成函数称为 _expand,这是 man zshcompsys 对它的评价:

_expand

This completer function does not really perform completion, but instead 
checks if the word on the command line is eligible for
expansion and, if it is, gives detailed control over how this
expansion is done. For this to happen, the completion system needs to
be invoked with complete-word, not expand-or-complete (the default
binding for TAB), as otherwise the string will be expanded by the
shell's internal mechanism before the completion system is started.
Note also this completer should be called before the _complete
completer function.

The tags used when generating expansions are all-expansions for the
string containing all possible expansions, expansions when adding the
possible expansions as single matches and original when adding the
original string from the line. The order in which these strings are
generated, if at all, can be controlled by the group-order and
tag-order styles, as usual.

The format string for all-expansions and for expansions may contain
the sequence '%o' which will be replaced by the original string from
the line.

The kind of expansion to be tried is controlled by the substitute,
glob and subst-globs-only styles.

It is also possible to call _expand as a function, in which case the
different modes may be selected with options: -s for substitute, -g
for glob and -o for subst-globs-only.