Vim - how can I use smartcase for search, but noic for * search?

I like smartcase and I like search * and # commands. But I would prefer the search commands * and # to be case sensitive, and / and? search commands obey smartcase heuristics.

Is there a hidden setting somewhere that I could not find yet? I would prefer not to reassign the * and # commands.

In short: do I want smartphone behavior for / and? but noic behavior for * and #.

Thanks Kit

+4
source share
3 answers

Not quite what you are looking for, but if you leave it smartcaseturned off and just add search queries /with \cwhen you want to ignore case, it's almost the same.

.

: , , , , , , , , Vim smartcase * #.

+3

'ignorecase' 'smartcase' */#, ex- / CmdLineEnter autocmd.

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

, *, ex-command, 'ignorecase' 'smartcase' . . , getcmdtype(), / ? , , - CmdLineLeave / .

: CmdLineEnter Vim 8.0.1206+.

.:

:h :map-expression
:h :let-&
:h :let-unpack
:h autocommand
:h :augroup
:h :autocmd
:h CmdLineEnter
+3

: /? noic * #.

, , "smartcase" "ignorecase" . , * # 'smartcase' .

, , :set smartcase noignorecase ? , CmdlineEnter CmdlineLeave ? /:

:au CmdlineEnter /,\? :set noignorecase
:au CmdlineLeave /,\? :set ignorecase

(Something like this, adapt to taste). Please note that this requires auto-commands CmdlineEnterand CmdlineLeave, which are available only in the next 8.0 releases.

+3
source

Source: https://habr.com/ru/post/1693941/


All Articles