Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto insert text into vim

Tags:

php

vim

When debugging some php scripts it would be very handy if I had a shortcut that would insert a piece of text like an echo with the current linenumber and filename.

echo "Hello at filename.php at linenumber";

Even auto inserting some text like a comment with a static echo would be sweet.

/* DEBUG */ echo "in here";

Is this possible in php?

Thanks.

like image 513
Shane Avatar asked May 17 '09 13:05

Shane


1 Answers

The variables you are looking for are called __FILE__ and __LINE__. A simple mapping in vim could give you the desired result:

:map <C-L> oecho __FILE__ . ':' . __LINE__ . " - ";<C-O>h
  • o - Start inserting below current line
  • echo __FILE__ . ':' . __LINE__ . " - "; - Write this string
  • <C-O> - Perform a single command in command mode
  • h - Go one character to the left, which should position your cursor at the end of the string so you can insert your debug statement.

While this should be ok for quick fixes, you might consider using a logger for debug messages (maybe Pear::Log?)

like image 72
soulmerge Avatar answered Sep 22 '22 18:09

soulmerge