Skip to content

TextMate tip: Making single apostrophes double

imageComing from Python world where most of text is in double apostrophes like:


"Hello world"

to JavaScript where, e.g. jQuery , expects you to write:


$('#foobar')

with single quotes, it can be quite annoying to always have to type it twice, since for double quotes (“), TextMate it always does it automatically. This feature is called Auto-Paired Characters.

Here is a procedure how to extend your Auto-Paired characters to also include ‘, in the default list (or any other character for that matter).

Go to Bundle Editor, and locate Text bundle (you might have to turn it on using Filter List in bottom left corner). Now locate Text -> Miscellaneous with (p) next to it. Inside it you should see a snippet of text that says:


...
smartTypingPairs = (
( '"', '"' ),
( '(', ')' ),
( '{', '}' ),
( '[', ']' ),
( '“', '”' ),
( "', '" ),
);
...

edit that snippet to look like this:


...
smartTypingPairs = (
( '"', '"' ),
( '(', ')' ),
( '{', '}' ),
( '[', ']' ),
( '“', '”' ),
( "', '" ),
( "'", "'" ), <--- insert this line
);
...

And that’s it! Just restart TextMate for Bundle to reload and try it out by typing ‘ and observe its new auto-pairing powers.

5 responses to “TextMate tip: Making single apostrophes double

  1. I know it works fine. But coding standards seem to expect usage of ‘ instead of “.

  2. Coding standards by whom? The only relevant standard is the one agreed upon by your team.

    And it’s not just me saying that. It’s also Yahoo on @media Ajax 😉

    Still, nice tip for those who’d like that.

  3. Very useful for PHP when echoing html tag attributes wrapped into double quotes. Thanks.

  4. To apply this changes TextMate-wide, just Drag&Drop the ‘Miscellaneous’ preference from the ‘Text’-bundle to the ‘TextMate’ bundle.

Comments are closed.