Sublime Forum

Shortcut to move cursor out of parenthesis, quotes, brackets

#1

Newb question here:

Is there a shortcut to move the cursor out of parentheses, quotes, brackets, etc? For example, in jQuery I type:
.on(
and it auto completes to this
.on()
with the cursor in between the parentheses.

Then I type

and it auto completes to this
.on(’ ')
with the cursor in between the single quotes.

Then I type
click
and it now shows this
.on(‘click’)
with the cursor to the right of the
k

Now, in order to get the cursor to the right of the last parenthesis to continue typing, I must press the right arrow key twice. Awful problem to have I know :smile: but it does take my right hand out of typing position. Is there a shortcut for this? Something more convenient? Like Cmd+Space or something? Or a way to define one? I looked at the Key Bindings in Preferences but couldn’t figure it out. And I don’t know what this technique is called, so had trouble finding it when searching on the web.

I’m on a Mac with Lion using Sublime Text 2 with ZenCode and Prefixr installed.

Thanks much.

0 Likes

#2

Hello.

Ctrl-right (arrow) normally works for me, or press the End key to go to the end of the line.

Andy.

0 Likes

#3

Add the following to your user keybindings:

[code]
{ “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 }
]   

},[/code]

Substituting “enter” with “tab” works well, too.

0 Likes

#4

Thanks. It works nicely, but I wonder why is such functionality not present out-of-the-box?

Sincerely,
Gour

1 Like

#5

Thanks everyone. You got me close enough that I was able to figure it out.

@C0D312
For some reason the code you supplied wasn’t making it work, but if I changed “enter” to “super+space” it now works. I found the “super” thing used in a bunch of the default settings. Maybe it’s a Mac thing?

But anyway it’s beautiful now! Space is just a space, and Cmd+Space moves the cursor to the end of the text on that line. Thanks so much!

0 Likes

#6

I forgot the code:

{ "keys": "super+space"], "command": "move", "args": {"by": "subword_ends", "forward": true} }
0 Likes

#7

Hey

Just posting this for anyone that comes across this beginner issue. Just type the ending ’ and it will jump you out of the ‘example’ grouping. Same goes with ] or (). Sublime highlights these so when you are typing it does the syntax highlighting.

0 Likes

#8

@C0D312

Is it possible to alter your keymap commands to something that works even when I move the cursor back in a section that is enclosed by quotes?

Atm I can only get behind one of the chars in your regex when I’m actually in such a block, not when I use the assigned keyboard shortcut to get out of it and move back via e.g. the cursor keys (or click with the mouse).

0 Likes

#9

Finally found the answer looking for, thanks!!!

0 Likes