Jure Cuhalev

30 Nov, 2007

TextMate tip: Making single apostrophes double

Posted by: Jure Cuhalev In: javascript|Planet Kiberpipa|Planet LiveCD|Tech

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.

Related posts:

  1. Double bind() for better `this` experience
  2. Caspar Berry – Risk Taking and Decision Making, Professional Poker player [Thinking digital session notes]

5 Responses to "TextMate tip: Making single apostrophes double"

1 | Marko Samastur

December 1st, 2007 at 8:09 pm

Avatar

WTF? It doesn’t, since there’s no need to. ” works just fine everywhere in Javascript including jQuery.

2 | Jure Cuhalev

December 2nd, 2007 at 3:14 am

Avatar

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

3 | Marko

December 2nd, 2007 at 11:27 am

Avatar

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.

4 | Bonatoc

July 14th, 2008 at 1:25 pm

Avatar

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

5 | Benedikt Roßgardt

October 19th, 2009 at 1:40 pm

Avatar

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