November 25, 2012 #sublimetext

If you find yourself typing these kind of similar codes very often, and want a snippet to save your time, this is it.

@topic = Topic.find(params[:topic_id])
@car_item = CarItem.find(params[:car_item_id])
@user = User.find(params[:id])

It maps the variable name to its model name by converting the first character or the character after a underscore to uppercase, which is a convention in Rails framework.

Demo Video

The Snippet

I put it and named as SublimeText/Packages/User/Snippets/model_find.sublime-snippet.

<snippet>
  <content><![CDATA[
@${1} = ${1/^(.)|_(.)/\U\1\2/g}.find(params[:${2:${1}_}id])
]]></content>
  <tabTrigger>mf</tabTrigger>
  <scope>meta.rails.controller</scope>
</snippet>

So now I just have to hit mf -> tab to trigger it.

SublimeText Document

Here I'm using the Substitutions feature of SublimeText 2 snippet.

The substitution syntax has the following syntaxes:

  • ${var_name/regex/format_string/}
  • ${var_name/regex/format_string/options}

e.g.

Original: ${1:Hey, Joe!}
Transformation: ${1/./=/g}

# Output:

      Original: Hey, Joe!
Transformation: =========
September 22, 2012 #sublimetext

If you’re using SublimeText and also a fan of iA Writer , you may want to check this plugin called MarkdownEditing. It provides a iA Writer-like interface to your SublimeText.

How does it look like?

A picture is worth a thousand words:

MarkdownEditing

Install

Use cmd+shift+P then Package Control: Install Package, type MarkdownEditing to install it, then any markdown file will get associated.

Other Features

Besides iA Writer-like UI it also has many other features like:

  • Asterisks, underscores and parenthesis are auto paired and will wrap selected text
  • ⌘⌥V will paste the contents of the clipboard as an inline link on selected text
  • ⌘⌥K inserts a standard inline link, ⌘⇧K inserts an inline image
  • ⌘⌥B and ⌘⌥I are bound to bold and italics (Markdown).

So, how do you think?

September 22, 2012 #sublimetext

Overview

In order to sync SublimeText2 settings with Dropbox, you need to symlink these folders of SublimeText to your dropbox.

  • Packages
  • Installed Packages
  • Pristine Packages

On your main machine

cd to your dropbox folder where your want to symlink to.

cd ~/Dropbox/99_Sync/SublimeText
ln -s "/Users/your_user_name/Library/Application Support/Sublime Text 2/Packages/" Packages
ln -s "/Users/your_user_name/Library/Application Support/Sublime Text 2/Installed Packages/" 'Installed Packages'
ln -s "/Users/your_user_name/Library/Application Support/Sublime Text 2/Pristine Packages/" 'Pristine Packages'

On your second machine

cd "/Users/your_user_name/Library/Application Support/Sublime Text 2"
rm -rf Installed\ Packages
rm -rf Packages
rm -rf Pristine\ Packages
ln -s ~/Dropbox/99_Sync/SublimeText/Installed\ Packages 'Installed Packages'
ln -s ~/Dropbox/99_Sync/SublimeText/Pristine\ Packages 'Pristine Packages'
ln -s ~/Dropbox/99_Sync/SublimeText/Packages Packages
September 6, 2012 #sublimetext

Sublimetext2 Build System

Sublimetext2 ships with its Build System. You can run a ruby file by Cmd + B (or through Tools -> Build menu).

One thing bothers me is you have to SAVE that file first, you can’t run “untitled” ruby code even you specified which build system (language) to use. This was the reason I still keep Textmate in my Mac, thanks to this plugin called Anypreter I can finally say goodbye to Textmate.

About Anypreter

You can install it through Package Control. It supports PHP, Python and Ruby.

After specify the language (suppose you haven’t saved it), Ctrl + Shift + X to run and check the result. Rightclick in the document works too.

Futher Reading