Hi meino.cramer!

On Sa, 21 Nov 2009, [email protected] wrote:

> In my file I have (for example) the following words
> 
>     Uppercase
>     uppercase
>     UPPERCASE
> 
> Doing a 
> 
>     :s/uppercase/frankenstein/g
> 
> produces
> 
>     frankenstein
>     frankenstein
>     frankenstein
> 

Really simple and stupidly written down function:
fu! SmartReplace(old, new)
   let r=''
   let i=0
   for char in split(a:old, '\zs')
       if i>strlen(a:new)
      return r
       endif
       if char2nr(char) > 64 && char2nr(char) < 91
      let r.=toupper(a:new[i])
       else
      let r.=a:new[i]
       endif
       let i+=1
   endfor
   if i < strlen(a:new)
       let r.=a:new[i :]
   endif
   return r
endfu

Then doing 
:%s/uppercase/\=SmartReplace(submatch(0), "frankenstein")/
on 

"uppercase
"Uppercase
"UPPERCASE

yields:
"frankenstein
"Frankenstein
"FRANKENSTein

Is that what you want?



Mit freundlichen Grüßen
Christian
-- 
Die Realität ist eine Illusion, die durch
einen Mangel an Whisky hervorgerufen wird.
                -- Schottisches Sprichwort

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to