【问题标题】:Autocomplete search word in vimvim中的自动完成搜索词
【发布时间】:2019-11-20 13:25:52
【问题描述】:

如何在 Vim 中自动完成搜索词?

我有以下一段代码,我想搜索单词pgnExists_f

if(hj1939stack->pgnArray[index] == newPgn)
{
  /* newPgn already exists in the pgnArray */
  pgnExists_f = TRUE;
}

在搜索命令中,我在输入 pgn 后按了 TAB,希望该词会自动完成为 pgnExists_f。但是,pgn 之后是^I

/pgn[TAB] 导致

/pgn^I

【问题讨论】:

    标签: vim autocomplete


    【解决方案1】:

    是的,有办法。

    • 这是常见的方式,将光标移动到单词pgnExists_f,然后按*#

    • 使用命令行窗口。在普通模式下按q/然后i进入插入模式,输入pgn,然后ctrl-nctrl-p你会看到弹出窗口,你可以选择你要搜索的词。

      李>

    【讨论】:

    • 我知道这两个。但是,我正在寻找一种搜索命令本身的方法。使用箭头标记或其他东西代替 [TAB]。还是谢谢
    • 你能回答这个问题吗? stackoverflow.com/questions/32069492/…
    • @SagarJain AFAIK,没有内置的方式来做你想做的事。
    • @SagarJain q/ 一个搜索命令,它可以满足您的要求。
    【解决方案2】:

    有一个plugin SearchComplete 可用,它允许这样做。

    【讨论】:

      【解决方案3】:

      我认为这可以使用插入函数返回的cmap 来实现:

      function! SearchCompletions()
          return "SearchCompletion"
      endfunction
      
      cnoremap <Tab> <c-r>=SearchCompletions()<cr>
      

      现在在命令行中按Tab 将插入文本“SearchCompletion”。 现在的问题是编写一个 SearchCompletions() 函数,它可以提前搜索当前缓冲区中的匹配项。这应该不会太难,但问题是它会有多慢。

      另一个问题是,只要光标在命令行上,映射就会起作用,而不仅仅是搜索提示。我不知道如何进一步限制它。

      【讨论】:

        【解决方案4】:

        看看这个插件:

        https://github.com/vim-scripts/sherlock.vim

        By default, it use <C-Tab> for forward completion, and <C-S-Tab> for backward completion.
        
        For example:
        :%s/tes<C-Tab> list all word which begin with 'tes' after current cursor position;
        :%s/tes<C-S-Tab> list all word which begin with 'tes' before current cursor position;
        /tes<C-Tab> list all word which begin with 'tes' after current cursor position;
        /tes<C-S-Tab> list all word which begin with 'tes' before current cursor position;
        ?tes<C-Tab> list all word which begin with 'tes' after current cursor position;
        ?tes<C-S-Tab> list all word which begin with 'tes' before current cursor position;
        
        In ':' mode, completion is available only after a '/'.
        
        When the right string is in command line, you can:
        1) Validate it with <Enter>, or type <Esc> to go away from command line if you are in '?' or '/' mode;
        2) Validate it with <Enter> or '/', or type <Esc> to go away from command line if you are in ':' mode.
        
        You can override the default mapping with something like that in your .vimrc:
        cnoremap <Whatever you want here> <C-\>esherlock#completeBackward()<CR>
        cnoremap <Whatever you want here> <C-\>esherlock#completeForward()<CR>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-23
          • 2016-06-23
          相关资源
          最近更新 更多