Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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

share|improve this answer

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

share|improve this answer
Is this fast, especially with big files? – Agos Aug 25 '11 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 Sep 1 '11 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 Sep 1 '11 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 Sep 2 '11 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 ?>.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.