Sublime Forum

[Solved] ST3 PHP -> symbol

#1

Hi all,

I am new in sublime. there is any way I can added automatically every time I type $this the symbol -> after $this ?

Thank you.

0 Likes

#2

Try with a snippet: http://docs.sublimetext.info/en/latest/extensibility/snippets.html

0 Likes

#3

or a keybinding for the s key, that operates in a source.php scope, and checks the rest of the line after the caret is blank and the contents of the line before the caret are just optional whitespace followed by $thi, and… inserts a snippet :slight_smile:

EDIT: turns out a snippet is not necessary, because we don’t need to manipulate the selection or anything within the text being inserted. see post below.

0 Likes

#4

add this to your user keybindings file:

{ "keys": ["s"], "command": "insert", "args": { "characters": "s->" }, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.php", "match_all": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*\\$thi$", "match_all": true },
        { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
    ]
},
3 Likes

#5

Thank you so much ti works.

0 Likes