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
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.