Skip to content

Instantly share code, notes, and snippets.

@g0xA52A2A
Created June 5, 2022 14:07

Revisions

  1. @George-B George-B created this gist Jun 5, 2022.
    28 changes: 28 additions & 0 deletions Vim_sane_case.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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.

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

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