sponsor Vim development Vim logo Vim Book Ad

keepcase.vim : Functions for doing case-persistant substitutions

 script karma  Rating 181/62, Downloaded by 3709  Comments, bugs, improvements  Vim wiki

created by
Michael Geddes
script type
Usage: Using KeepCase or KeepCaseSameLen defined here, do a substitution like this:

%s/\u\<old_word\>/\=KeepCaseSameLen(submatch(0), 'new_word')/g

* KeepCase( original_word , new_word )  
  returns the new word maintaining case
  simply uses heuristics to work out some different common situations
    given   NewWord
    Word   --> Newword
    WORD    --> NEWWORD
    word    --> newword
    WoRd    --> NewWord
    woRd    --> newWord

* KeepCaseSameLen( original_word , new_word )    
Returns the new word maintaining case
  Keeps the case exactly the same letter-for-letter
  It does work if the words aren't the same length, as it truncates or
  just coppies the case of the word for the length of the original word.

* :SubstituteCase#\ctoto\(Titi\)tata#\1Tutu#g
     totoTitiTata -> titiTutu
     TotoTitiTata -> TitiTutu
     tototititata -> tititutu
     tototitiTata -> titiTutu
     TototitiTata -> TitiTutu
install details
Place in plugin directory

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
keepcase.vim 2.0 2007-04-04 6.0 Michael Geddes Version from Luc Hermitte.  Includes :SubstituteCase command as well as some extra cases handled.
keepcase.vim 1.1 2001-05-29 6.0 Michael Geddes Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github