Textmate single quotes autoclosure

5

I’m using TextMate 1.5.10 on OS X Lion, and for some weird reason I don‘t get autocomplete for single quotes ('). Double quotes (") work fine.

Since I personally prefer to use single quotes whenever I code in JavaScript or PHP, that thing annoys me a little. And as far I have googled, TextMate is actually supposed to autoclose single quotes by default.

So why doesn’t this work for me and how do I force-enable this feature?

Arnold

Posted 2011-07-25T11:41:23.847

Reputation: 741

Answers

6

Which pairs are auto-inserted depends on the actual language and the bundle that is loaded for it.

The actual character pairs are defined in the bundle preferences with different settings for different languages and contexts. For example, in source code an apostrophe is set up to have itself as a closing character, except for comments and strings. This is achieved using scope selectors.

For example, if you want to enable single quote autocompletion for Plain Text, you will have to edit the preferences of this bundle according to the TextMate manual.


Go to BundlesBundle EditorShow Bundle Editor. In the left pane, select "Text", and "Miscellaneous". Here, add the following line to smartTypingPairs (note that you have to enter the single quotes within double quotes):

( "'", "'" ),

enter image description here

Close the Bundle Editor, and it should work for every file recognized as Plain Text. If it doesn't work instantaneously, reload the bundles with BundlesBundle EditorReload Bundles.

To change it for other languages (like JavaScript or PHP), you will have to inspect the preferences of the corresponding bundles.

slhck

Posted 2011-07-25T11:41:23.847

Reputation: 182 472

Obviously, if the preferences don't exist yet, you may create them using the + button. – slhck – 2011-07-25T12:02:46.897

I am also confident that I was able to auto-complete single-quotes before my update to Lion, but alas, upon reading the OP's question, I tried it and it didn't work. Then, in reading this, I was able to add ( "'", "'" ), to the first line of smartTypingPairs and it works perfectly again. Thanks, @slhck! – mkoistinen – 2011-07-25T12:32:41.477

Great, thank you. Indeed, just like @mkoistinen, for some weird reason I didn’t have that last line highlighted in the screenshot. Added it, and it works. – Arnold – 2011-07-26T11:59:06.897