Thanks--keepcase.vim is great.  So now with
        :%s/firstname/\=KeepCase(submatch(0), 'LastName')/ig
I can replace all instances of
        firstname with lastname
        firstName with lastName
        FirstName with LastName

But \=KeepCase(submatch(0), '') is a mouthful.
Not a problem; that exact expression does what I'll want 99% of the time, so I've already mapped it to a control-key. And there are other ways to abbreviate.

Still, this seems *such* a useful function in a programmer's editor, it seems worthwhile to build it into the :substitute command as some kind of optional behavior.

How about one of these:

:s/firstname/LastName/k ['k' for keepcase]

:set MaGiC

or some kind of delimiter that can be stuck into a pattern to say "use KeepCase() on this part". OK, I know there aren't many delimiters that are available at this point.

Does this make any sense as a possible future feature?


Marshall



On Jul 7, 2006, at 4:26 AM, Yakov Lerner wrote:

On 7/7/06, Marshall Abrams <[EMAIL PROTECTED]> wrote:
Hate to ask this because I'm sure the answer is already out there
somewhere, but I've searched help and vim.org until I was blue in the
fingers....  I could swear that I remember from a few years back that
there's a way to do this. Can't remember whether it required something
special in the patterns or some special :set variable or loading a
plugin.

I want to the replace pattern in a substitution to be able to figure
out whether I want an upper or lower character in the replacement,
depending on whether the search pattern matched an upper or lower
character.  Very useful for substitutions on studlyCaps.

For example, suppose I want to replace all instances of 'first' with
'last' and of 'First' with 'Last'.  Can I do that with a slinge :s///
line?

Try this script:
   http://www.vim.org/scripts/script.php?script_id=6
   keepcase.vim : Functions for doing case-persistant substitutions

Yakov


Marshall Abrams                                       Programmer
[EMAIL PROTECTED]                                  5points.net, LLC
Voice: 518-392-5505          www.5points.net          Fax: 518-392-8410

CONFIDENTIALITY NOTICE:
This communication and any accompanying document(s) are confidential
and privileged. They are intended for the sole use of the addressee.
If you receive this transmission in error,  you are advised that any
disclosure,  copying,  distribution,  or the taking of any action in
reliance upon the communication is strictly prohibited.  If you have
received this communication in error,  please contact us by email at
[EMAIL PROTECTED],  or by telephone at  (518) 392-5505.
Thank you.

Reply via email to