vim maps – simple commands to do stuff.

2013-08-28 146 words 1 min read

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.

 

Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it