Sublime Forum

Is there a way to enforce an auto-replace?

#1

I want sublime text to automatically replace

<? 

with

<?php 

while in HTML or PHP code.

Is there any way to do that?

I tried even setting it up as a regular snippet but including a < makes it so Sublime won’t save the snippet bc there’s an error parsing the snippet xml

0 Likes

#2

[code]
<![CDATA[

<?php ]]> <? text.html.basic [/code] Although, personally.. I think it's more trouble than it's worth :smile: - and you're more likely to forget the **php** in future :cry:.
0 Likes

#3

That is pretty good… is there any way to make so I don’t need to hit tab to complete it? There isn’t, is there…

I know it’s potentially ‘bad habit forming’… but I want this for a passive insurance system, and I will continue to type the PHP. I nearly always do… but the one time you don’t and spend a long time debugging and being very confused makes me wish that could just get taken care of behind the scenes :wink:

0 Likes

#4

[quote=“cutcopypaste”]That is pretty good… is there any way to make so I don’t need to hit tab to complete it? There isn’t, is there…

I know it’s potentially ‘bad habit forming’… but I want this for a passive insurance system, and I will continue to type the PHP. I nearly always do… but the one time you don’t and spend a long time debugging and being very confused makes me wish that could just get taken care of behind the scenes :wink:[/quote]

If you look in the default key-bindings then you will see that you could create a key-binding to insert a snippet, with the snippet itself defined as part of the key-binding. An example:

{ "keys": "\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":

You could ignore (delete) the context part.

You *could *use the on_modified event so that it would happen automatically but I think this is way overkill!

0 Likes

#5

Of course it is. And its trivial:

{ "keys": ["<", "?"], "command": "insert_snippet", "args": {"contents": "<?php"} },
0 Likes