8

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?

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Minor thing, but uppercase \C worked for me :) Thanks!
3

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

2 Comments

That's closer to what I want, but I also want user-defined commands to be case-insensitive; not just the files and directories.
This is exactly what I wanted. Put set wildignorecase in ~/.vimrc. Reference
1

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

nnoremap / /\C 

See :help \C.

Comments

0

After getting a hint from @mike that going down the nmap path is the right way, I came up with the following functions:

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

This solved my problem just how I wanted. The only tiny thing that bugs me is that the text :call IgnoreCase() flickers when I hit :, but I guess that can't be helped.

2 Comments

Regarding the verbose display of your command: I think there is a "silent" option somewhere,.. Please refer to the help/google. This should also be possible.
@mike <silent> mapping is no good because it doesn't show the : when I first hit it. The :silent command still shows the call to IgnoreCase because the whole :silent call IgnoreCase() is the one who's flickering. I think this is something that can't be helped.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.