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

问题描述:

我正在写一个函数,它的作用类似于*键,但不移动光标。设置当前搜索模式很简单:如何在不打开窗口的情况下添加Vim搜索记录?

let @/='...' 

所以nN甚至//按预期方式工作。但*也增加了一个条目到搜索历史。我想出的最好的是:

silent! normal! q/"/p 

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

+0

你可能想看看Ingo Karkat的[SearchHighlighting](http://www.vim.org/scripts/script.php?script_id=4320)插件。这是多加一点。它也有其他可能有用的类似插件的链接 – 2014-10-06 19:45:33

检查: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,实际上)。