4

I like the behavior of smartcase while searching, and I like Vim's auto-completion options, but I don't like them together. Is there any way to keep smartcase enabled, but have auto-completion results (<C-n>, <C-p>, and all <C-x> prefixed keys) always be completely case sensitive? Maybe some clever remap?

1 Answer 1

7

Update:

I created a plugin named vim-idetools that implements this feature along with a bunch of related refactoring tools. Feel free to try it out.


Original answer:

Well, I figured out a way to do this. Just put this in your .vimrc

set smartcase
au InsertEnter * set noignorecase
au InsertLeave * set ignorecase

Now, when the popup menu opens up, noignorecase will be turned on and only case-sensitive completions will be listed. Don't know why I hadn't thought of this! Note smartcase only works when ignorecase turned on by overriding case-insensitivity whenever a capital letter is included in the search string.

On a somewhat related note, I also have in my .vimrc the lines

nnoremap <silent>  * :let @/='\C\<' . expand('<cword>') . '\>'<CR>:let v:searchforward=1<CR>n
nnoremap <silent>  # :let @/='\C\<' . expand('<cword>') . '\>'<CR>:let v:searchforward=0<CR>n
nnoremap <silent> g* :let @/='\C'   . expand('<cword>')       <CR>:let v:searchforward=1<CR>n
nnoremap <silent> g# :let @/='\C'   . expand('<cword>')       <CR>:let v:searchforward=0<CR>n

which make "*" or "#" searches for the word under the cursor case-sensitive, whether or not ignorecase is on. This was from this vi stackexchange thread.

The reasoning behind this setup is that I often use / and ? searches to quickly navigate through a file (easier to do if they are case insensitive), while I use * and # to perform word or WORD replacements with ciw and the popup menu to complete case-sensitive variable names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.