> This does not seem to be a good way, consider if we want to change:
> START -> STOP
> Start -> Stop
> start -> stop
> STart -> STop
> sTART -> sTOP

I'm only personally concerned by the first three of those. This is the
solution from my rc file. It moves the cursor, which I find annoying.
Anyone know why it would do that? Hope this helps the OP.

I use camel case, so I use the mixed case version of the string as the
initial argument, so for example, given:

HelloThere
HELLOTHERE
hellothere

typing:
:%Sub HelloThere HiThere

results in:
" HiThere
" HITHERE
" hithere

the code from my vimrc:

" Case-matching substitution
function! CaseMatchSubstitute(find, repl) range
   " As-you-typed-it substitution.
   sil exe a:firstline.','.a:lastline.'s/\C'.a:find.'/'.a:repl.'/ge'

   " All-lowercase substitution
   let casefind = tolower(a:find)
   let caserepl = tolower(a:repl)
   sil exe a:firstline.','.a:lastline.'s/\C'.casefind.'/'.caserepl.'/ge'

   " All-uppercase substitution
   let casefind = toupper(a:find)
   let caserepl = toupper(a:repl)
   sil exe a:firstline.','.a:lastline.'s/\C'.casefind.'/'.caserepl.'/ge'
endfunction

command! -range -nargs=+ Sub :<line1>,<line2> call CaseMatchSubstitute(<f-args>)

Reply via email to