【问题标题】:Vim: Case-insensitive ex command completionVim:不区分大小写的 ex 命令完成
【发布时间】:2014-09-25 22:29:34
【问题描述】:

我想在 Vim 中完成不区分大小写的 ex 命令。

我可以做到这一点:

set ignorecase
" Maybe with
set smartcase

但是,这样做的问题是,这(显然)使搜索不区分大小写 /,这是我不想要的。

https://github.com/thinca/vim-ambicmd

这个插件确实启用了不区分大小写的 ex 命令补全(甚至更多功能),但之后它也禁用了补全。例如,当我将<Tab>映射到“expand”键时,:NeoBundleUpdate <Tab>并没有列出所有neobundle.vim管理的插件,而是输入了<Tab>字符。

我尝试做类似的事情:

nmap / :set noignorecase<CR>/
nmap : :set ignorecase<CR>:

但这让 Vim 发疯了……

有什么方法可以实现不区分大小写的命令完成同时保留区分大小写的搜索的目标吗?

【问题讨论】:

    标签: vim case-sensitive case-insensitive


    【解决方案1】:

    您可以保留ignorecasesmartcase 用于命令行补全,并使用此映射使您的搜索区分大小写:

    nnoremap / /\C
    

    :help \C

    【讨论】:

      【解决方案2】:

      在得到@mike 的提示后,沿着nmap 路径是正确的方法,我想出了以下函数:

      nnoremap : :call IgnoreCase()<CR>:
      function! IgnoreCase()
          set ignorecase
      endfunction
      nnoremap / :call NoIgnoreCase()<CR>/
      function! NoIgnoreCase()
          set noignorecase
      endfunction
      

      这解决了我想要的问题。唯一让我烦恼的是,当我点击: 时,文本:call IgnoreCase() 会闪烁,但我想这无济于事。

      【讨论】:

      • 关于您的命令的详细显示:我认为某处有一个“静音”选项,..请参阅帮助/谷歌。这也应该是可能的。
      • @mike &lt;silent&gt; 映射不好,因为当我第一次点击它时它没有显示::silent 命令仍然显示对IgnoreCase 的调用,因为整个:silent call IgnoreCase() 是闪烁的。我认为这是无可奈何的事情。
      【解决方案3】:

      帮助 :h /c 说:

      7. Ignoring case in a pattern                                   /ignorecase
      
      If the 'ignorecase' option is on, the case of normal letters is ignored.
      'smartcase' can be set to ignore case when the pattern contains lowercase
      letters only.
                                                              /\c /\C
      When "\c" appears anywhere in the pattern, the whole pattern is handled like
      'ignorecase' is on.  The actual value of 'ignorecase' and 'smartcase' is
      ignored.  "\C" does the opposite: Force matching case for the whole pattern.
      {only Vim supports \c and \C}
      Note that 'ignorecase', "\c" and "\C" are not used for the character classes.
      
      Examples:
            pattern   'ignorecase'  'smartcase'       matches
              foo       off           -               foo
              foo       on            -               foo Foo FOO
              Foo       on            off             foo Foo FOO
              Foo       on            on                  Foo
              \cfoo     -             -               foo Foo FOO
              foo\C     -             -               foo
      

      这将建议您以您建议的方式使用 nnoremap / /\c 或 \C(如果您需要更改区分大小写)。

      【讨论】:

      • 太棒了!小事,但大写 \C 为我工作:) 谢谢!
      【解决方案4】:

      我认为您正在寻找“wildignorecase”选项。

      【讨论】:

      • 这更接近我想要的,但我也希望用户定义的命令不区分大小写;不仅仅是文件和目录。
      • 这正是我想要的。将set wildignorecase 放入~/.vimrcReference
      猜你喜欢
      • 2012-05-05
      • 2018-11-04
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      相关资源
      最近更新 更多