vim maps – simple commands to do stuff.
Some time back, I was working on some script for logging and I wanted to change the class to function like this:
$logger->Debug("Test string"); loggerFunc("Debug", "Test String");
As you can see, this change could be quite frustrating if you have quite a few references. And thus vim comes to rescue.
Simple map like ::
:map ,mm :s/(.*)$logger->(.*)((.*)).*/1loggerFunc("2",3);/
and then I can do “/$logger->” and then “n” to go to next match. Just do “,mm” and the line is re-factored.
Break down of the regex :
.* :search for any spaces before $logger->
(.*) :match anything
( : upto (
(.*) :match anything
) : till )
and then replace as required.
Related articles