Srinivas Rao. M wrote:
Hi Vimmers,
I am tasked to replace the pattern
log("module_name", LOG_LEVEL_DEBUG, "The Value of status=%d message",
status);
to
log("module_name", LOG_LEVEL_DEBUG, "%s:The Value of status=%d
message",__FUNCTION__, status);
This pattern is appearing in hundreds of source files. Does anybody have
a quicker way/script to do this task ?.
I know it is possible through macro substitution by writing another
macro on top of this, But again it is not a cleaner way..
Are those linebreaks really in there? I doubt it as one of them is in
the middle of a string.
OK, assuming they're not there, that its just a mailer thinking its
smarter than you...
:%g/log("module_name",/s/"The Value of status=%d
message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
message",__FUNCTION__,status);
That'll do the trick for one file; then, of course, you'll want to save it:
:w
OK, now let's see how to automate this:
qa
:%g/log("module_name",/s/"The Value of status=%d
message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
message",__FUNCTION__,status);
:w
:n
q
That will store the command sequence into a register (I picked register
a). To use it:
vim PatternForHundredsOfSourceFiles
qa
:%g/log("module_name",/s/"The Value of status=%d
message",status/LOG_LEVEL_DEBUG, "%s:The Value of status=%d
message",__FUNCTION__,status);
:w
:n
[EMAIL PROTECTED]
Assuming you don't have 10,000 of these, eventually vim will report an
error. A "PatternForHundredsOfSourceFiles"
might be *.c */*.c */*/*.c (etc.)
Regards,
Chip Campbell