Syntax-Specific Key Binding in sublime Text 2 – e.g. fix javascript reindent with jsFormat and Ctrl+Shift+F

Sublime Text 2 is great. period.

In short

to use Cmd-Shift-F to reindent javascript with jsFormat without affecting others, put this in the Key Bindings :

Story:

Again this supposingly simple question took me some time to figure out

My use case is: I found there is a bug in Sublime Text 2 for reindent javascript which

whenever there is a comment line, the indentation of next bracket follow the indent of the comment line instead of matching bracket

Wrong:
i.e.
          funciton(){
//something
};

JSFormat

So i installed the package JsFormat which is also closer to the my style

Then there is another problem — it is not overriding the reindent but create another command ‘jsFormat’ thus I cannot use my usual hotkey cmd + shift + f to reindent but need to use the default ctrl+alt+F. Even I change it to cmd+shift+f, other language (syntax) will be affected

The Settings - More -> Syntax-specific is for setting but not key bindings

Scope!

Finally figure out the scope concept from this SO Thread
so the scope for js is scope.js not scope.javascript

The correct way to know the scope is to check syntax’s .tmLanguage file for the key scopeName

seems the alternative -plugin ScopeHunter is not working for me

Originally I thought it is the bug, but it works now

Related SO: http://stackoverflow.com/questions/16520165/sublime-text-2-varying-macro-per-syntax

My version

Version:2.0.1, Build2217 OS: MacOSX 10.7.4

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s