Reputation: 1925
If I already have this written
$company_id = isset($_POST['cid']) ? $_POST['cid'] : null;
And I want to wrap a function call around $_POST['cid']
, is there a way to put that inside the autocompleted function's parentheses?
Instead of me typing this:
$company_id = isset($_POST['cid']) ? Validate::isId()$_POST['cid'] : null;
and then having to erase the right parenthesis, is there a shortcut to wrap the param when sublime autocompletes the function for me?
$company_id = isset($_POST['cid']) ? Validate::isId($_POST['cid']) : null;
Using Mac Yosemite and SublimeText 3.
Upvotes: 0
Views: 1013
Reputation: 3823
You can create a custom snippet
that accepts a SELECTION
argument:
Packages/___Your_Snippet_Folder___/SnippetName.sublime-snippet
<snippet>
<tabTrigger>testFunction()</tabTrigger>
<description>testFunction</description>
<scope>source.php</scope>
<content>
testFunction(${1:$SELECTION}, ${2:PlaceHolder_2})
</content>
</snippet>
The use of placeholders, for example: ${1:placeholder_text_goes_here}
, allows you to assign descriptive pre-selected regions throughout your snippet that can be navigated with Tab & Shift + Tab
Additionally, you can replace one of the placeholders with $SELECTION
, for example: ${1:$SELECTION}
, which will pass the currently selected text as an argument if you execute the snippet from the command palette
or a key-binding
.
To insert the snippet:
$SELECTION
argumentSnippet:
followed by the value of the <description>
key in your sublime-snippet
fileFor more information on snippets, see:
Upvotes: 1