Skip to content

Instantly share code, notes, and snippets.

@g0xA52A2A
Created June 5, 2022 14:07
Show Gist options
  • Save g0xA52A2A/cb2d63dbe133c71325953a74ac79c715 to your computer and use it in GitHub Desktop.
Save g0xA52A2A/cb2d63dbe133c71325953a74ac79c715 to your computer and use it in GitHub Desktop.

Let's say you want to make use of ignorecase as that's what you'd like when searching with / and ?. However you then realise how oddly pervasive this setting is in that is applies to things like :s. Rather than inserting "\C" into every pattern you think you'll use use an autocmd and so some up with something like the following config.

set ignorecase

autocmd CmdLineEnter : set noignorecase
autocmd CmdLineLeave : set   ignorecase

Only to find it doesn't work, ignorecase still seems to be in effect when using :s. This is because CmdLineLeave fires not only before you truly leave the command-line but also before the command has executed.

Here's a snippet to overcome this in a generic fashion by using a timer.

let [s:ignorecase, s:smartcase] = [&ignorecase, &smartcase]

function! s:RestoreCase(ID)
    let [&ignorecase, &smartcase] = [s:ignorecase, s:smartcase]
endfunction

augroup SaneCase
    autocmd!
    autocmd CmdlineEnter : set noignorecase nosmartcase
    autocmd CmdlineLeave : call timer_start(100, '<SID>RestoreCase')
augroup END

The far reaching effecting of ignorecase annoys me enough as it is but CmdLineLeave firing before executing the command really takes the biscuit here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment