A question about TextMate. For example, I just typed var_dump($codes);, and I forgot to write <?php ?>. So, now I want to highlight the area that I want to wrap the php tags around. How can I do this?

3 Answers 3


Simply add a new command called for ex 'Wrap in ' in your php bundle editor (Bundles->Bundle Editors->Show Bundle Editor)

In the Activation choose: Key Equivalent and hit: CMD+SHIFT+W (or whatever you'd like that's not already taken).

Leave the scope selector to source.php

In the snippet window write:


Now select anything and hit CMD+SHIFT+W and you're done

Sorry I couldn't upload an image to show you I've just signed up.

EDIT I now have enough reputation to upload the image:

enter image description here


You could select the line your PHP command is on and do a Search and Replace operation with a regular expression. Search for


and replace it with

<?php $1 ?>

as seen in the screen shot. The regular expression will match everything on the line and wrap the PHP tag around it.

TextMate Screenshot

  • Is this fast, especially with big files?
    – Agos
    Commented Aug 25, 2011 at 12:08
  • That I don't know, I'm a BBEdit user myself :) I did download a TextMate demo to figure out that one.
    – Kiezpro
    Commented Sep 1, 2011 at 19:56
  • I was asking because sometimes Textmate is really really slow with regexes, and this looks like it might make it choke.
    – Agos
    Commented Sep 1, 2011 at 21:40
  • That's very possible. I'm kind of a Unix person, so my approach was a little Unix-ish. The other mentioned solutions are obviously better suited for this particular problem.
    – Kiezpro
    Commented Sep 2, 2011 at 21:10

The HTML bundle has a command to wrap in <?= ?>:

You could assign a keyboard shortcut to this from the Bundle Editor, and if you're so inclined you could even add a new command for <?php ?>.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .