如何在不打开窗口的情况下添加 Vim 搜索历史记录?

Jan*_*der 2 vim

我正在编写一个功能类似于按键*但不移动光标的函数。设置当前搜索模式很简单:

let @/='...'
Run Code Online (Sandbox Code Playgroud)

所以n甚至N//预期工作。而且*还向搜索历史记录添加了一个条目。我想出的最好的办法是:

silent! normal! q/"/p
Run Code Online (Sandbox Code Playgroud)

但这会短暂打开搜索历史记录窗口,当我触发该功能时,这会导致难看的闪烁。有没有更好的办法?

mMo*_*ntu 5

检查:help histadd()

histadd({history}, {item})              *histadd()*
        Add the String {item} to the history {history} which can be
        one of:                 *hist-names*
            "cmd"    or ":"   command line history
            "search" or "/"   search pattern history
            "expr"   or "="   typed expression history
            "input"  or "@"   input line history
            "debug"  or ">"   debug command history
        The {history} string does not need to be the whole name, one
        character is sufficient.
        If {item} does already exist in the history, it will be
        shifted to become the newest entry.
        The result is a Number: 1 if the operation was successful,
        otherwise 0 is returned.
Run Code Online (Sandbox Code Playgroud)

当编写 vimscript 时,来自:help function-list 的信息可能非常有帮助(实际上是整个第 41 章)。