LoginSignup
117
117

More than 5 years have passed since last update.

SublimeText2 for Rails Developers

Last updated at Posted at 2012-12-26

追記 (2013/12/03)

最新の Sublime Text 環境を構築したので、別途、記事を作成して公開しているので、こちらも合わせてどうぞ。


SublimeText2は、"事実上のTextMate2"と高い評価を受けているテキストエディタです。
Rails界隈で有名なRailsTutorialでも、オススメのテキストエディタとして取り上げられています。

URL

公式

非公式

参考

英語

日本語

各種設定

コマンドライン

コマンドラインから、SublimeText2を起動する事が出来ます。

設定方法

SublimeText2の起動が出来るように設定します。

$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

使用方法

SublimeText2の起動に関するヘルプを参照する事が出来ます。

$ subl -h
Sublime Text 2 Build 2181

Usage: subl [arguments] [files]         edit the given files
   or: subl [arguments] [directories]   open the given directories
   or: subl [arguments] -               edit stdin

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -s or --stay:        Keep the application activated after closing the file
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).

Filenames may be given a :line or :line:column suffix to open at a specific
location.

エディタ

常用するエディタとして設定する事が出来ます。

.bash_profile
export EDITOR='subl -w'

テーマ

ここでは、RailsCastsのテーマを適用します。
まず、以下のリンクからテーマファイルをダウンロードします。

設定方法

ダウンロードしたテーマファイルを、SublimeText2のパッケージディレクトリへ配置します。

$ cp ~/Downloads/Railscasts.tmTheme ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/

SublimeText2を起動して、メニューのSublime Text 2 > Preference > Color Scheme > Railscastsを選択します。

パッケージ

SublimeText2は、パッケージという概念があり、簡単に機能を追加する事が出来ます。

Package Control

パッケージを使用する際は、別途、Package Controlを組み込む事によって、パッケージを簡単に管理する事が出来ます。

設定方法

詳細は、以下のリンクを参照して下さい。

SublimeText2を起動して、メニューのView > Show Consoleを選択し、コンソールを表示します。
以下のコマンドをコピペして実行します。

console
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

最後に、SublimeText2を再起動します。

使用方法

詳細は、以下のリンクを参照して下さい。

パッケージ一覧

Package Controlを使用する事によって、インストールが可能となるパッケージの一覧です。

For Rails Developers

Rails Developerの為に必要となるパッケージを、RailsTutorialにて用意してくれています。

Rails Tutorial Sublime Text Setup

RailsTutorialにて用意してくれているパッケージです。
こちらを参照しながら進めます。

SASS Haml Syntax Highlighting

SASSやHamlのファイルのシンタックスハイライトをサポートするパッケージです。

Rails Tutorial Sublime Text Snippets

RailsTutorialで用意されているスニペットのパッケージです。

Alternative Autocompletion

Tabトリガーによる自動補完を可能にするパッケージです。

TextMate Style ERB Block

コマンド一発でERBファイル内に、"<%= %>"や"<% %>"を挿入する事を可能にするパッケージです。

Sublime Text 2 Ruby Tests

SublimeText2上で、Rubyのテスト実行を可能にするパッケージです。

Settings - User

SublimeText2は、デフォルトで定義された設定を上書きして、独自の設定に変更する事が出来ます。
設定を変更するには、メニューのSublime Text 2 > Preferences > Settings - Userを選択します。
設定ファイル内は、jsonにて記述されています。

Preferences.sublime-settings
{
  "color_scheme": "Packages/Railscasts.tmTheme",
  "font_face": "Osaka",
  "font_size": 16.0,
  "margin": 2,
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
  "word_wrap": false,
  "highlight_line": true
}

使用方法

起動

プロジェクトのルートディレクトリにて、以下のコマンドを実行します。
画面左側にプロジェクトツリーが表示された状態で、SublimeText2が起動します。

$ subl .

キーバインド

基本

Move to Start

カーソル位置を行先頭に移動する。
^ + A

Move to End

カーソル位置を行末に移動する。
^ + E

Goto

Goto Anything...

プロジェクトツリー配下の任意のファイルへ移動する。
⌘ + P or ⌘ + T

Goto Line...

行番号で指定した行へカーソル位置を移動する。
^ + G

View

Side Bar > Hide Side Bar

プロジェクトツリーを開閉する。
⌘ + K, ⌘ + B

Layout > Columns: 2

ウィンドウを縦方向に2分割する。
⌥ + ⌘ + 2

Focus Group > Group: 1

グループ1のウィンドウをアクティブにする。
^ + 1

Focus Group > Group: 2

グループ2のウィンドウをアクティブにする。
^ + 2

Edit

Line > Indent

選択状態のコードを右にインデントする。
⌘ + [

Line > Unindent

選択状態のコードを左へアンインデントする。
⌘ + ]

Text > Delete to End

カーソル位置より後ろの文字全てを削除する。
^ + K

Selection

Expanded Selection to Line

カーソル位置のある行を選択状態にする。
⌘ + L

Tools

Command Palette...

コマンドパレットを開いて、任意のコマンドを実行する。
⇧ + ⌘ + P

117
117
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
117
117