Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Case-insensitive ex command completion

I'd like to have case-insensitive ex command completion in Vim.

I can accomplish this with:

set ignorecase
" Maybe with
set smartcase

However, the problem with this is that this (obviously) makes the search with / case-insensitive, which I don't want.

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

This plugin did enable case-insensitive ex command completion (and even more functionality), but it also disabled the completion after that. For example, when I mapped <Tab> to the "expand" key, :NeoBundleUpdate <Tab> didn't list all the plugins managed by neobundle.vim but entered the <Tab> character.

I tried doing something like:

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

but this made Vim go crazy...

Is there any way I can achieve my goal of having case-insensitive command completion while retaining case-sensitive search?

like image 738
NigoroJr Avatar asked Aug 03 '14 05:08

NigoroJr


3 Answers

The help :h /c says:

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

That would suggest something like nnoremap / /\c or \C (if you need to change case-sensitivity) in your proposed way.

like image 53
mike Avatar answered Sep 20 '22 17:09

mike


I think you are looking for the 'wildignorecase' option.

like image 32
Christian Brabandt Avatar answered Sep 18 '22 17:09

Christian Brabandt


You can keep ignorecase and smartcase for command-line completion and make your search case-sensitive with this mapping:

nnoremap / /\C

See :help \C.

like image 36
romainl Avatar answered Sep 20 '22 17:09

romainl