Sublime Forum

How do I emulates TMs "#{}" for Ruby

#1

The single feature I miss the most after switching from TM is while editing ruby, when the cursor is inside double-quotes (""), and you type “#” it expands to “#{}” and moves the cursor inside the curly braces. Awfully darn handy, I must say.

How can I do this in Sublime?

0 Likes

#2

Add this to your user keybindings (Preferences > Keybindings - User)

[code] { “keys”: “#”], “command”: “insert_snippet”, “args”: {“contents”: “#{$1}$0”}, “context”:

    { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
    {
    "operand": "string.quoted.double.ruby",
    "operator": "equal",
    "match_all": true,
    "key": "selector"
  }
]   

} [/code]

0 Likes

#3

Beautiful! Thank you very much.

0 Likes

#4

This seems to be enabled by default now. I looked in my key bindings and could not find it. Is there a way to disable this feature as it drives me crazy.

Thanks,
JB

0 Likes

#5

Seems that I posted too soon. Once I stumbled into the packages directory a quick grep for “keys” in the Ruby directory came up with
Default.sublime-keymap
which has a single keymap for automatically adding the {} after a # inside double quotes. I just deleted that file and reloaded sublime and it does not automatically add the {} anymore.

I don’t know how to code snippets. Is there a way to just comment out the text in the file so it can be added back at a later date if I should so choose?

0 Likes