Small Vim Shortcut for PHP Tags

The short tags in PHP have been deprecated as of 5.3.0. Short tags provided a shorter alternative to the annoying-to-type <?php and <?php echo. Instead, you could use <? and <?= respectively. This was great but it caused problems when working with XML files, and the short_tags option was disabled in the PHP config by default on some implementations.

To make life easier, I created this vim mapping that will expand <? to <?php and <?? to <?php echo. You may change the abbreviation as you see fit. Simply place this in your .vimrc

inoremap <??    <?php echo  ?><Left><Left><Left>
inoremap <?     <?php  ?><Left><Left><Left>

Re-open vim or type use :source ~/.vimrc to reload the config. Now just type <? or <?? in insert mode.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>