Sublime Text for Drupal - Key Bindings and Snippets
Kommentare

bandar bola
18th Mai 2013 - 07:05
It's nearly impossible to find knowledgeable people on this subject, but you seem like you know what you're talking about! Thanks
bandar bola

1
This is the third and final part of my Sublime Text 2 (ST2) blog series. After giving an introduction and looking installation and configura- tion of ST2, I will talk about the key bindings and snippets.
Key Bindings
One of the biggest advantages of ST2 is that you have full control over most of its settings. It is really easy to configure ST2 to your personal needs.
As you can see, there are two major parts of the settings. The first being the general configuration and the second one for the key bindings. This is the feature you should be really excited about. Imagine you can configure a text-editor exactly to your needs. ST2 let your dreams come true. To start, just open the "Key Bindings - Default" settings. There you can see all the predefined key bindings like:
{ "keys": ["super+c"], "command": "copy" }, { "keys": ["super+k", "super+b"], "command": "toggle_side_bar" },These are simple definitions of key bindings. As you can see it contains a key-definition and a command (here you can find a full list of available commands). You also can chain key strokes to start an action. But this isn't where the customization ends. There are more complex key bindings, where you can pass arguments and contexts like:
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context": [ { "key": "setting.auto_indent", "operator": "equal", "operand": true }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true }, { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true } ] }If you want to create new key bindings or overwrite existing ones just open the "Key Bindings - User" file and create your own bindings there. After saving the new bindings will be active.
For a detailed documentation of customizing your key bindings please visit the unofficial documentation of ST2. There is a part for the customization and a reference for the more complex configs.
The last item I have left to share on this matter is a free tool availabled for Mac users called Cheat Sheet (AppStore Link). Once installed, it shows you all available key bindings for your currently active application.
My most used keyboard commands
CMD + T
CMD + R
CMD + P followed by @
CMD + P followed by :
Snippets (for Drupal)
Another great feature of ST2 are the snippets. Snippets are intelligent templates that will convert some short codes into a predefined text block with placeholders.
To create a snippet, simply go to Tools -> New Snippet... you will get a some lines of code which you can adapt easily. Let's say you write PHP code and you need a lot of functions. You can create a snippet for exactly this purpose
<snippet> <content><![CDATA[ // ${1: description} // ${2: variable} function ${3:functionname}() { // ${4:some comment} } ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>fct</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.php</scope> </snippet>Full credit to Márton Juhász who has done some great work for the Drupal community. He created a package for ST2 which contains a lot of nice snippets for the use with Drupal.
You can install it by pressing "cmd+shift+p" type "install" and search for "Drupal Snippets". Hit the "return" key and you're all set up.
But there is one problem... you don't know all the tab triggers of these Drupal snippets yet. I can help you with that: Just hit "cmd+shif+p" and type "sn hoo" or "sn h_" and you will get a list with all available tab triggers for the Drupal snippets. It's that easy.
There is a more in depth documentation of snippets available.
Conclusion
As you can see, there is a lot of community love around ST2. And if you take your time, you will love all the features and configuration possibilities. I am still getting used to the editor, but my addiction to this piece of software is growing from day to day.