Home Download Buy Blog Forum Support

is there a way to enforce an auto-replace?

is there a way to enforce an auto-replace?

Postby cutcopypaste on Fri Jan 04, 2013 11:04 pm

I want sublime text to automatically replace
Code: Select all
<?

with
Code: Select all
<?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
cutcopypaste
 
Posts: 41
Joined: Tue Feb 21, 2012 9:43 pm

Re: is there a way to enforce an auto-replace?

Postby agibsonsw on Sat Jan 05, 2013 12:39 am

Code: Select all
<snippet>
    <content><![CDATA[
<?php
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>&lt;?</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>text.html.basic</scope>
</snippet>


Although, personally.. I think it's more trouble than it's worth :) - and you're more likely to forget the php in future :cry:.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: is there a way to enforce an auto-replace?

Postby cutcopypaste on Fri Jan 18, 2013 3:15 pm

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 ;)
cutcopypaste
 
Posts: 41
Joined: Tue Feb 21, 2012 9:43 pm

Re: is there a way to enforce an auto-replace?

Postby agibsonsw on Sat Jan 19, 2013 3:06 pm

cutcopypaste wrote: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 ;)


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:

Code: Select all
{ "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!
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to General Discussion

Who is online

Users browsing this forum: BestGreek, Google [Bot] and 15 guests