Sublime Forum

Selection and quotes

#1

Hi, as pointed out here: https://forum.sublimetext.com/t/vintage-surrounding-double-quotes/2875/3&hilit=quotes+selection#p16634, typing single or double quotes when some text is selected just replaces the selection.

I’d like to change this behavior, via settings if possible, otherwise if not.

Whether it’s configurable or not, I also want another feature, aid for string interpolation, which is present in textmate for the ruby bundle: if there’s a selection in text delimited by double quotes, the selection must be wrapped in #{…}; if no selection is present and the cursor is in a string, #{} should appear; in the other cases, just a plain # should appear.

Something similar is also present in javascript, where many template libraries use %{} for string interpolation.

Now:

  • is it possible to make quotes do the right thing with selections, or writing a plugin is needed to achieve this?
  • would you please suggest me what to read and where to look (maybe some existing similar plugins?) to implement aid for string interpolation?

Thank you.

0 Likes

#2

Typing a quote with text selected will surround the text with quotes, unless you have disabled the auto_match_enabled setting. This is implemented via key bindings: have a look through the default key bindings for auto_match_enabled.

0 Likes

#3

[quote=“jps”]
Typing a quote with text selected will surround the text with quotes, unless you have disabled the auto_match_enabled setting. This is implemented via key bindings: have a look through the default key bindings for auto_match_enabled.[/quote]

It isn’t working for me: I’m using build 2139, I have auto_match_enabled, default key bindings are as you describe, but still, while brackets do the right things, quotes do not. How can I investigate further?

May I, for instance, access current settings and key bindings from console, to spot if some package may be overriding something?

Thanks.

0 Likes

#4

You might want to try this: http://www.sublimetext.com/docs/2/revert.html

0 Likes

#5

I’m missing the String interpolation feature and more importantly, the syntax highlight that is available in Aptana for ruby.

Syntax Highlight
“Hi, I’m #{name}” - name should be highlighted.
‘Hi, I’m #{name}’ - no highlight should be done, single-quote strings in ruby does not interpolate

selection in a double-quoted string and pressing # will auto wrap the selection in #{ }
selection in a single-quoted string and pressing # will simply replace the text with #

Is there any way this can be added? Searching through the forum, this feature has been requested since Sept 2011 in a number of threads.

Thanks for looking at this.

0 Likes

#6

This works for me:

[code] // Auto-pair string interpolation for ruby
{ “keys”: “#”], “command”: “insert_snippet”, “args”: {“contents”: “{$0}”}, “context”:

  { "key": "setting.auto_match_enabled", "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 },
  { "key": "selector", "operator": "equal", "operand": "source.ruby", "match_all": true }
]

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

  { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
  { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
  { "key": "preceding_text", "operator": "regex_contains", "operand": "\"$", "match_all": true },
  { "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true },
  { "key": "selector", "operator": "equal", "operand": "source.ruby", "match_all": true }
]

},
[/code]

0 Likes