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.

 

Enhanced by Zemanta

Vim – Why and where am I getting these errors from?

If you have got this question in your mind, then you are in right place.

vim -V20  2>&1 |tee

You can give the debugfile as any file, where you would want to log the debug messages. This will log a lot of information in the debugfile, you can open the file, once you have got the error in the main vim window. After this, you can open the debugfile and simply search for the error that you were getting. Just look for the reason why this error is originated in the debug logs and then it should be pretty simple to fix that.

 

Enhanced by Zemanta

vim mappings for multiple files.

If you open multiple files in vim with command line option. Then the only way to move between the files is “:n” and “:N”. There is a easier way to do this. Just add mappings for this in vimrc. Here is what you can use.

map  :N
map  :n

And if you want to make sure that you move to the prev or next file after saving the file, then you modifyt the mapping like this:

map <c-left> <Esc>:w|N<CR>
map <c-right> <Esc>:w|n<CR>
Enhanced by Zemanta