0

I found a great keybinding that jumps over sublimes code compeletion by hitting enter here's the link: quora. My code in my keymap file is:

// BEGIN keymaps for skipping to the end of " ) and ] code compeletion
{ "keys": ["enter"], "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 }
    ]   
},
// END keymaps for skipping to the end of " ) and ] code compeletion

and it defintely works how I'd like...most of the time. For example if I'm typing in some javascript:

function(p1, p2|)|
hitting enter..^.^

and I hit enter when the cursor is at the first carrot then it will jump over to the second carrot which is what I want. However, there's another case which is when you open up, say square brackets in a sublime settings file.

[|]|
.^.^

Now because of the keymapping the cursor jumps over the right square bracket, when in reality what you want is to insert a new line like:

[|
.^
    |
....^
]

and move the carrot from the first to the second carrot, just like the behavior that happens when you create a javascript function:

function myFunction(){|
    | <-- cursor tabbed over
} <--curly on bottom

My problem is I don't really understand regex that well yet, or how to use them in combination with keymaps in sublime. Really what I need to figure out (I think) is how to insert some sort of conditional into the keymap that basically just checks:

if (next char is a ] and the char before it is a [)
then don't do any completion hoping
else do exactly like the keymap is already set up to do

How would I go about doing this? Thanks for your help :)

mbigras
  • 7,664
  • 11
  • 50
  • 111

1 Answers1

0

If I understand your question correctly, you want the functionality to work when the cursor is inside parentheses () but not when inside square brackets []. If that's the case, simply change this line:

{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\\]]", "match_all": true },

to this:

{ "key": "following_text", "operator": "regex_contains", "operand": "^[)'\"\]", "match_all": true },

All I did was change the "operand" from this

"^[)'\"\\]]"

to this

"^[)'\"\]"

by removing

\]
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Hey, thanks for the response. It's actually not that I want it to work with parenthesis or brackets it's more like: specifically for square brackets how can I make it work (that is jump over the bracket) when the brackets aren't right next to each other like: `[some code|]` but not work (that is open up a newline) when the brackets are right next to each other like: `[|]`. The vertical pipe is supposed to represent where my cursor is. Does that make more sense? – mbigras Apr 27 '16 at 15:57
  • Hey Matt, just wondering if you've had a chance to take another look at this yet. I'm still trying to figure it out myself, and I would definitely appreciate it if you found a way :) – mbigras May 10 '16 at 19:16