Sublime Forum

Rule Completion and Niceties?

#1

Been using Sublime Text now for a bit and i’ve pretty much switched over completely from TextMate.

The only thing i’m missing (which im sure is a an option), is the what TextMate does while im coding up HTML/CSS. For instance TextMate automatically adds a semi-colon after a colon when working in a CSS file, and will automatically create the closing > in HTML files when im creating DOM nodes.

If anyone could point me in the right direction that would be fantastic.

0 Likes

#2

really? nothing? this seems like such an essential and easy feature it’s gotta be included.

0 Likes

#3

not really a solution, but I use breevy or textexpander to do this kind of thing.
for example, a rule

Abbreviation: :
Replacement: :%(cursor);

in either of those would type a semi-colon every time you typed a colon, and leave the cursor between them.
As I said, hardly a solution as they have to be activated manually when you are coding in CSS, but both pieces of software I mentioned are much more powerful than that, so I’m sure you can find much more uses for them

0 Likes

#4

You can do these sorts of things fairly easily with key bindings - that’s how the bracket pairing is done, for instance. Take a look through the key bindings for some examples, but for the CSS example, I’d imagine you want something along the lines of:

{ "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": "selector", "operator": "equal", "operand": "source.css", "match_all": true }
	]
}
0 Likes

#5

That’s very nice.

Selector can probably be improved a bit though, to not trigger when typing selectors like div:before for example.
This works for me:
“source.css -meta.selector.css”

0 Likes

#6

That is useful, thanks! I like to be able to jump semicolon with Tab, so here’s my modified code:

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

  { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
  { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
  { "key": "selector", "operator": "equal", "operand": "source.css -meta.selector.css", "match_all": true }

]
}[/code]

0 Likes

#7

You can instead use ctrl+enter to jump to next line.

0 Likes

#8

good to know it. still i may want to add a comment on the same line

0 Likes