tags:

views:

162

answers:

2

I've run into the following case a few times and I was wondering if there is a fast way to handle it in Vim.

I'll have a source file like the following:

#ifndef _FOO_H_
#define _FOO_H_

class Foo {
    Foo(int foo);
};
#endif

And I would like to convert it to the following:

#ifndef _BAR_H_
#define _BAR_H_

class Bar {
    Bar(int bar);
};
#endif

So, I want all foo -> bar, but to keep the capitalization of the original. Right now, I've been doing this with 3 or 4 different regexes, but it seems there should be a better way. Any ideas?

+10  A: 

This script will do a case-preserving search/replace.

Copy the script to the plugin directory (~/.vim/plugin), then do

:set ic
:%s/foo/\=KeepCaseSameLen(submatch(0), 'bar')/g
dF
You should update your version of keepcase. I've added a :SubstituteCase command to it that simplifies substitutions a lot. :)
Luc Hermitte
A: 

Use emacs? (/runs)

Arkadiy
:) not running fast enough.
Arkadiy