I'm developing Ruby on Rails application in Textmate2. I have to use a lot of curly braces {}
syntax in Rails coding.
By default, when I type opening curly brace {
, then {}
is automatically displayed. In most Rails tutorial, it is so conventional to put spaces between curly braces at the start and end positions. For e.g.,
{ name: "aaa", email: "aaa@gmail.com" } # hash example
it { should have_selector('p', 'some text') } # rspec example
It's a little tiring to put spaces by hand in every coding sentences.
I want to put spaces between curly braces automatically. I mean when I type {
, I want { }
to be appeared by default.
I don't know which bundles do I need to modify. Please show me ways how to be get done this syntax.
To do this you'll need to create your own snippet:
Open the Bundle Editor
and select Ruby
from the list. Press Command
+ n
to create a new item, select Snippet
from the drop down.
Name your new Snippet
something appropriate, "Spaced Curly Braces" perhaps. The snippet editor should contain only:
{ $0 }
Click, in the Bundle Editor
drawer, on Key Equivalent
to bind the snippet to a key, in this case use {
This will cause this snippet to exist everywhere in TextMate, to limit it to only working in Ruby change the Scope Selector
to source.ruby
, or for the Ruby on Rails people: text.html.erb.rails, source.ruby.rails, source.ruby.rails.embedded.html, meta.rails.helper, meta.rails.unit_test, meta.rails.controller, meta.rails.functional_test, text.haml, source.ruby.rspec