There are two ways to do this, depending on what functionality you want. If all you want is to print exactly what you indicated, then create the following snippet:
<snippet>
<content><![CDATA[
/**
* @var $0
*/
]]></content>
<tabTrigger>vardoc</tabTrigger>
</snippet>
To do so, create a new file with XML syntax, paste the above exactly as shown, then save the file as Packages/User/vardoc.sublime-snippet
where Packages
is the directory opened when you select Preferences -> Browse Packages
. To trigger the snippet, type vardoc
and hit Tab. Your cursor will be positioned where the $0
is in the snippet.
This should work fine, except you'll have to type *
if you need a new line, and there's nothing intelligent about it. Instead, what I'd recommend is DocBlockr
, a Sublime Text plugin that auto-generates documentation for several languages, including PHP. Typing /**
and hitting Tab or Enter will give you
/**
* |
*/
Where |
is your cursor position (this is also a built-in Sublime feature, I believe). It can also auto-document functions. If you have
function foo(MyClass $cls,
Array $arr,
$num=42,
$val=false,
$str="sweet function, dude!") {
return $something;
}
and you place your cursor on the line above the function definition and type /**
and hit Tab, you'll get
/**
* [foo description]
* @param MyClass $cls
* @param Array $arr
* @param integer $num
* @param boolean $val
* @param string $str
* @return [type]
*/
with [foo description]
highlighted so you can enter your own description. Hitting Tab again will subsequently highlight MyClass
, Array
, etc. so you can alter them if you wish.
More to your question, you can declare a variable
var $foobar = "I love unicorns";
Placing your cursor above that declaration and entering /**
Tab will give you
/**
* [$foobar description]
* @var string
*/
There are other features of DocBlockr
as well, check out the link above for more details.
I hope this helps!