Sublime Forum

Autopair quotes inside anything autopaired

#1

First of all, what and impressive editor, its really superb, im trying it for one week and im really astonished.

I dont know if im missing something, or this is normal behaviour, but when i type a quote " the autopair funcionality works fine and automatically the second quote appears “”.

But if im writing the quote inside anything autopaired (like, for example, parenthesis) the quote autopair never appears. To be more concrete:

$foo = "bar";

the second quote will appear automatically, but if i do

if ($foo == "bar") {

i’d to write the second quote manually.
This is normal behavior?

Thanks in advance,
Gonzalo

ps: sorry if this was talked in another topic, i did a search and i cannot find anything related it.

0 Likes

#2

The auto-inserting of quotes only happens if there’s whitespace to the right of the cursor, otherwise it can get a bit annoying. You can change this though: if you add the following key binding to your user key bindings (Preferences/User Key Bindings):

<binding key="&quot;" command="insertSnippet 'Packages/Default/Quote.sublime-snippet'">
	<context name="option" value="autoMatchEnabled"/>
	<context name="allSelectionsEmpty" value="true"/>
</binding>

…then it will always add in the paired quote, irrespective of the text around the cursor. For reference, the original key binding is:

<binding key="&quot;" command="insertSnippet 'Packages/Default/Quote.sublime-snippet'">
	<context name="option" value="autoMatchEnabled"/>
	<context name="allSelectionsEmpty" value="true"/>
	<context name="allFollowingText" value="^(\t| |$)"/>
	<context name="noPrecedingText" value="&quot;a-zA-Z0-9_]$"/>
</binding>

This differs from the above binding by having two extra contexts that inhibit the paring if there’s something other that whitespace to the right of the cursor, or alpha-numeric characters to the left. If you do find the always-auto-pairing annoying, you may want to consider just modifying the ‘allFollowingText’ context to have value="^(\t| |)|$)", i.e., it’ll also insert the quote if there’s a close bracket to the right.

0 Likes

#3

Thanks jon!! Excellent to know, i love the fact that everything is configurable in Sublime.

Thanks again,
gonzalo

0 Likes