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.
Related articles
Related Articles:
- 2011/09/04 debug call function() to debug a function in vim
- 2011/04/16 vim autocomplete – automagically without tab.
- 2010/08/02 when you press f9 ‘paste’ is on , press f9 again and ‘paste’ is off, and so forth (works in insert-mode and command-mode)
- 2010/02/03 Built-in lists in vim
- 2013/05/15 Vim – Why and where am I getting these errors from?
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.