SmartCase : replacing words while keeping original lower/uppercase style
| script karma
Downloaded by 1049
Comments, bugs, improvements
|An example, you may want to replace any FileSize appears in your program into LastModifiedTime. Since it appears everywhere as both uppercases and lowercases, you have to write it several times:
:%s/FileSize/LastModifiedTime/g " function names
:%s/file_size/last_modified_time/g " variable names
:%s/FILE_SIZE/LAST_MODIFIED_TIME/g " macros
:%s/File size/Last modified time/g " document/comments
This script copes with the case style for you so that you need write just one command:
An alternative way:
first search for the string: /\cfile\A\?size
then run a command: :%SmartCase "LastModifiedTime"
By the way, SmartCase can also cope with the circumstance where you want to replace the string's case style while keeping its words. For example:
FileSize => file_size
LastModifiedTime => last_modified_time
This can be done with the following command:
To sum up: the first argument to SmartCase is the reference words, the secend argument is the reference styles, if the second argument omitted, it's submatch(0).
Rating scripts is only available on the
script versions (upload new version)
Click on the package to download.
ip used for rating: 126.96.36.199
||Trivial improvement: Treat numbers using last style, and will not lose numbers when replacing.
||changed <q-args> to <args> for multiple arguments capability.
changed some usage help.
||1) Added a command interface :SmartCase
2) a bug fixed
Thank Salman Halim for the bug report and advices.