Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BrandonSurowiec/ec8fa59bde53487c9640 to your computer and use it in GitHub Desktop.
Save BrandonSurowiec/ec8fa59bde53487c9640 to your computer and use it in GitHub Desktop.
SublimeText: Autocompletion of $this-> and $this;

Add to Preferences > Key Bindings - User:

Auto replace to $this-> after typing $-

  // Auto replace to $this-> after typing $-
    { "keys": ["-"], "command": "insert_snippet", "args": {"contents": "this->"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\$$", "match_all": true },
            { "key": "selector", "operator": "equal", "operand": "source.php - source.js" }
        ]
    }

Auto replace to $this; after typing $;

 	// Auto replace to $this; after typing $;
	{ "keys": [";"], "command": "insert_snippet", "args": {"contents": "this;"}, "context":
		[
			{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\$$", "match_all": true },
			{ "key": "selector", "operator": "equal", "operand": "source.php - source.js" }
		]
	},

Automatically adds -> after typing $this when in PHP context only.

// Autocompletion of -> after typing $this
{ "keys": ["s"], "command": "insert_snippet", "args": {"contents": "s->"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\$thi$", "match_all": true },
            { "key": "selector", "operator": "equal", "operand": "source.php - source.js" }
        ]
    }

Like PHPStorm: Automatically adds > after typing $this- (I don't use this one)

	// Autocompletion of > after typing $this-
	{ "keys": ["-"], "command": "insert_snippet", "args": {"contents": "->"}, "context":
		[
			{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
			{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
			{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\$this$", "match_all": true },
		]
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment