Question

On my sublime-keymap file I already have this:

{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "following_text", "operator": "regex_contains", "operand": "^[ )'\"\\}\\]>: ]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
}

So, when my cursor is before any of these characters )}]:;> the shift+space will move the cursor to the right, jumping the character. This is very useful and already well known.

Now I was thinking that would be nice to have the inverse too. Imagine that I just jumped a closing } but then I remember that I still had something to type inside the {}. It would be great to be able to do shift+space again and get back inside the {}.

I was checking this documentation but everything I tried didn't worked.

Any help or ideas on this? Tks!

EDIT : BASED ON CORRECT ANSWER:

So, based on @skuroda's answer, this is what I came up with. For more information, read the comments below his answer.

{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": false}, "context":
    [
        { "key": "preceding_text", "operator": "regex_contains", "operand": "[)'\"\\}\\]>,\\;:]$", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
},
{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\\}\\]>,\\;:]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
},

The order of the code is important (preceding_text command must come before following_text one).

UPDATE: I think I found a much simpler and better solution for this:

{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": true} },
{ "keys": ["super+shift+space"], "command": "move", "args": {"by": "characters", "forward": false} }

So, the context doesn't really matter here. Shift + Space will advance one character, CMD + Shift + Space will go back one character. Pure joy!

Was it helpful?

Solution

Have you tried the preceding_text key, so something like

{ "keys": ["shift+space"], "command": "move", "args": {"by": "characters", "forward": false}, "context":
    [
        { "key": "preceding_text", "operator": "regex_contains", "operand": "[ )'\"\\}\\]>: ]$", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
}

If you have tried that, it's probably worth posting what you have already tried, so we don't repeat things you have already done (rather than just stating you have tried stuff). I also modified the regex slightly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top