Sublime Forum

Auto-complete inside associative array

#1

I’m not sure if this is possible in ST4, I want it to be auto-complete as '' => '' after typing the ' when it’s inside an associative array like the below:

$name = array (
   '' => ''
);

Does anyone know how to achieve this?

0 Likes

#2

In theory a thing like this can be done with a key binding that has a very specific context that makes the key only apply in a specific situation. I don’t see any good way to do that in this code snippet though, since the syntax (I am assuming PHP) does not have a specific scope you could target there. In addition even if it did, it would have to be extremely narrowly focused or you would lose the ability to type a single quote at all inside.

A plugin could perhaps be employed to detect such a situation and provide the context needed, but that would be rather heavyweight for a one off.

You could however bind a specific key to insert that text whenever you press it while inside of a PHP file; for example:

    {
        "keys": ["ctrl+'"], "command": "insert_snippet",
        "args": {
            "contents": "'$0' -> ''"
        },
        "context": [
            { "key": "selector", "operator": "equal", "operand": "embedding.php" },
        ],
    },
0 Likes