Home Download Buy Blog Forum Support

#{} syntax in ruby

#{} syntax in ruby

Postby NivenHuH on Thu Feb 02, 2012 5:56 am

It would be nice to be able to have #{} automatically inserted for you when you put this inside of a quoted ruby string.. Eg:

If you had the text "myVariable" highlighted in a string "myVariable" and hit #, you would get this: "#{myVariable}"
if you had the text "myVariable" highlighted in a string "myVariable and other things", you would get this "#{myVariable} and other things"
If you had no text highlighted in a string, but your cursor was inbetween quotes, it would insert the brackets too.. example string "" => "#{}" (with the cursor inbetween the {}'s)
NivenHuH
 
Posts: 3
Joined: Thu Feb 02, 2012 5:53 am

Re: #{} syntax in ruby

Postby NivenHuH on Thu Feb 02, 2012 5:59 am

Of course I read the post "submitting user requests" after submitting a user request. oops!
NivenHuH
 
Posts: 3
Joined: Thu Feb 02, 2012 5:53 am

Re: #{} syntax in ruby

Postby C0D312 on Thu Feb 02, 2012 11:27 pm

This is enabled in the dev build: http://www.sublimetext.com/dev

However, if you don't want to step up to the dev build, you can use this keymapping:
Code: Select all
  { "keys": ["#"], "command": "insert_snippet", "args": {"contents": "#{${1:$SELECTION}}$0"}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        {
        "operand": "string.quoted.double.ruby",
        "operator": "equal",
        "match_all": true,
        "key": "selector"
      }
    ]   
  }
(Place in your Preferences > Keybindings - User)

EDIT: added @castles change.
Last edited by C0D312 on Fri Feb 03, 2012 2:14 am, edited 1 time in total.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: #{} syntax in ruby

Postby sublimator on Fri Feb 03, 2012 12:28 am

Code: Select all
"args": {"contents": "#{${1:$SELECTION}}$0"}
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: #{} syntax in ruby

Postby C0D312 on Fri Feb 03, 2012 2:12 am

@castles, Glad you've got my back :)
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: #{} syntax in ruby

Postby sublimator on Fri Feb 03, 2012 3:40 am

C0D312 wrote:@castles, Glad you've got my back :)


haha, np dude :)
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: Exabot [Bot] and 9 guests