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

时间:2014-10-06 19:08:23

标签: vim

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

let @/='...'

所以nN甚至//按预期工作。但*还会在搜索记录中添加一个条目。我提出的最好的是:

silent! normal! q/"/p

但是这会短暂地打开搜索历史记录窗口,当我触发该功能时会导致丑陋的闪烁。还有更好的方法吗?

1 个答案:

答案 0 :(得分:3)

检查: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.

在编写vimscript时,来自:help function-list的信息非常有用(实际上是第41章)。