I love smartcase and I love the * and # search commands. But I would prefer that the * and # search commands be case-sensitive while the / and ? search commands obey the smartcase heuristic.
Is there a setting hidden away somewhere that I haven't been able to find yet? I would rather not have to remap the * and # commands.
In summary: I want smartcase behaviour for / and ? but noic behaviour for * and #.
Thank you, Keith
Not exactly what you're looking for, but if you leave smartcase
off and just prepend your /
searches with \c
when you want to ignore case, it's almost the same thing.
See the Case sensitivity section here
Edit: actually according to all the documentation I'm seeing what you want is the expected behavior, however testing it myself it looks like Vim is applying smartcase
to *
and #
as well.
You can change the value of 'ignorecase'
and 'smartcase'
for *
/ #
and for any ex-command and searching via /
turn them back on via the CmdLineEnter
autocmd event.
nnoremap <expr> * <SID>star_power('*')
nnoremap <expr> # <SID>star_power('#')
function! s:star_power(cmd)
let [&ignorecase, &smartcase] = [0, 0]
return a:cmd
endfunction
augroup StarPower
autocmd!
autocmd CmdLineEnter * let [&ignorecase, &smartcase] = [1, 1]
augroup END
Now if you do a *
and then do any ex-command then the values of 'ignorecase'
and 'smartcase'
will change. This may not be desirable. You may want to do a getcmdtype()
to restrict this to only /
and ?
modes or maybe maybe something more complex with CmdLineLeave
and/or a timer.
Note: this requires a Vim 8.0.1206+ to support CmdLineEnter
.
For more help see:
:h :map-expression
:h :let-&
:h :let-unpack
:h autocommand
:h :augroup
:h :autocmd
:h CmdLineEnter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With