dongzhabo2796 2016-04-22 17:50
浏览 160
已采纳

Sublime Text自动完成功能,括号中是否有变量?

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.

  • 写回答

1条回答 默认 最新

  • drt41563 2016-04-22 20:57
    关注

    You can create a custom snippet that accepts a SELECTION argument:

    SnippetDemo


    Save The Code Below @:

    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 <kbd>Tab</kbd> & <kbd>Shift + Tab</kbd>


    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:

    • select the text to be passed as the $SELECTION argument
    • use <kbd>Ctrl + Shift + P</kbd> to launch the command palette
    • type Snippet: followed by the value of the <description> key in your sublime-snippet file

    For more information on snippets, see:

    SublimeText / Unofficial Docs / Snippets

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊