2

I have the following options:

set ignorecase
set smartcase
set incsearch
set wrapscan

The first two options cause the searches to be case-insensitive if there is no uppercase letter in the pattern.

I want this option to be disabled for the gd functionality, and preferably its variants.

I wanted the same for :h star, too, and got it from a vi.SE answer. Sadly, this concept cannot be used to implement gd, because gd analyzes a few choices to guess where the declaration of the variable under cursor might be (details in :h gd). One needs to implement that with the query appended with \C to make the search case-sensitive.

Emulating the default implementation of gd is the real work here.

3N4N
  • 5,684
  • 18
  • 45
  • Can't you simply unset ignorecase and smartcase before doing gd and then reset them to their previous value? – romainl Oct 13 '22 at 14:03
  • @romainl If you mean switching them manually or with a keybinding, then yes. But if you mean in a function, then I don't think so, because when I switch noic back to ic, the matches/highlights will re-sync. – 3N4N Oct 13 '22 at 14:49
  • 1
    @romainl, you're right. I just missed/overlooked a step. Working fine now. – 3N4N Oct 14 '22 at 04:51

1 Answers1

4

Implementing romainl's comment, we execute the following sequence:

  • enable case-sensitive search
  • execute normal gd key
  • enable case-insensitive search

I tried that before posting a question here. It has the limitation that after :set noignorecase, it'll highlight the case-insensitive matches.

I figured out later that we can circumvent this problem by setting the current search register itself to forcefully match in a case-sensitive manner, with :h /\C.

nnoremap <silent> gd
      \ :let _is_ic = &ic<CR>
      \:set noic<CR>
      \:normal! gd<CR>
      \:let @/ = @/ .. '\C'<CR>
      \:let &ic = _is_ic<CR>
      \:unlet _is_ic<CR>
3N4N
  • 5,684
  • 18
  • 45