SPICY SPACE BLOG

愛犬家WEBエンジニアの日常。

Sublime Text2 PHP用スニペット

sublime text。カスタマイズしやすく人気のエディタですね!
皆さん使ってますか?僕は使っています。

軽いし、ちょっとした便利機能がいっぱいあっていいんですよねー。

で、中でも便利なコードスニペット機能ですが、自分用PHP向けスニペットを作ったので晒します。

スニペット作成方法

Tool->New Snippetから新規作成できます。 保管場所はwinデフォルトでは↓です。

C:\Users\UserName\AppData\Roaming\Sublime Text 2\Packages\User\xxx.sublime-snippet

macはココ↓

/Users/UserName/Library/Application Support/Sublime Text 2/Packages/User/xxx.sublime-snippet

自分用スニペット集

  • print_r 「#$+Tab」で起動。 変数名のところにカーソルが合うようにしてみました。
    pre要素をつけてブラウザでそのまま表示されるようにしました。
    これ大分はかどります。
<snippet>
    <content><![CDATA[
//###
echo "<pre><-";
print_r(\$${1:xxx});
echo "-></pre>";
exit;
//###
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>#$</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.php</scope>
</snippet>
  • title なんか毎回----が違う長さになっちゃうのでつくってみた、、、笑
<snippet>
    <content><![CDATA[
//--------------------------------------------------
// ${1:TITLE}
//--------------------------------------------------
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>#tit</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.php</scope>
</snippet>
  • 関数(説明つき) Tabキーで順番に書いて行けばキレイなソースの出来上がり、と。
<snippet>
    <content><![CDATA[
/**
* ${3:関数の説明}
*
* @param ${5:string} \$${6:_path}
* @return ${4:void}
*/
function ${1:func_name}(\$${2:param}){
    
}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>#func</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.php</scope>
</snippet>

まぁ使って行くうちにもうすこし改良していくか。