41

I am looking to get the following assigned to Keybindings. I am able to make a snippet for this, yet would prefer to be able to CTRL + > just like in Textmate.

<%= %>

What do I need to add and where do I need to add it, or where could I find out.

2 Answers 2

56

If you just want to literally insert those characters, you can set up your "User Key Bindings" like this:

[
    { "keys": ["ctrl+."], "command": "insert", "args": {"characters": "<%= %>"} }
]

You can use the Default Key Bindings file as an example for possible key binding commands. Both User and Default are located in Sublime Text 2 -> Preferences on OS X.

Not sure if you really wanted "ctrl+shift+.", but it would work as well.

To move the cursor to the middle during insert, you can use insert_snippet like this:

[
    { "keys": ["ctrl+shift+."], "command": "insert_snippet", "args": {"contents": "<%=$0 %>"} }
]
5
  • Great shout - Thank you. Any idea how to get the cursor to be placed in the center of the tags for continued typing? Jul 9, 2011 at 15:43
  • @lunixbochs Is there a way to set this up so that If I press the sequence again, it would remove the = ?
    – pizza247
    Aug 25, 2011 at 3:29
  • you can play with context - look at the default key bindings. I believe you can match regex before and after a section, so you could say "if my cursor is on =, with a <% and %> on either side, remove the ="
    – lunixbochs
    Sep 1, 2011 at 19:39
  • is the following the old way? sublimetext.com/docs/plugin-examples <binding key="ctrl+alt+d" command="duplicate"/> ?
    – barlop
    Oct 15, 2013 at 10:07
  • Yep. The Sublime Text 3 documentation lives at sublimetext.com/docs/3
    – lunixbochs
    Oct 16, 2013 at 2:16
3

Just found this, thought it might be helpful: https://github.com/eddorre/SublimeERB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.