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.
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 lineecho __FILE__ . ':' . __LINE__ . " - ";
- Write this string<C-O>
- Perform a single command in command modeh
- 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?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With