LoginSignup
67
66

More than 5 years have passed since last update.

SublimeText2設定メモ

Last updated at Posted at 2012-10-14

Package Control

パッケージなる拡張機能を使うには下記参照。

View→Show Consoleでコンソールを表示、下記Pythonのワンライナーを貼り付けEnter。

コンソール表示

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(' ',' ')).read()); print 'Please restart Sublime Text to finish installation'

設定

全体の設定

Sublime Text2 > Preferences > Settings - Userから設定を編集できる。
設定できる内容はDefaultの方を参考にする。
Defaultを修正してもいいけどUserに上書きされる。

設定

現在の設定

{
    "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
    "font_size": 12.0,

    // カーソル行をハイライト
    "highlight_line": true,
    // 未保存タブを強調表示
    "highlight_modified_tabs": true,
    // 使用しないパッケージはなし、これでVimのキーバインドが使える
    "ignored_packages":
    [
    ],
    // インデントガイドラインを常に表示
    "indent_guide_options":
    [
        "draw_active",
        "draw_normal"
    ],
    // 規定のタブサイズ
    "tab_size": 4,
    // タブをスペースに変換
    "translate_tabs_to_spaces": true,
    // 保存時に行末のスペースなどを削除
    "trim_trailing_white_space_on_save": true,
    // Ctrlキーを含めたVimのキーバインドを使用する
    "vintage_ctrl_keys": true,
    // 開始時はコマンドモード
    "vintage_start_in_command_mode": true
}

キーマップ

[
    // シンボルへの移動
    { "keys": ["ctrl+s"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
    // ;でVimのコマンドを入力するウィンドウを表示
    {
        "keys": [";"], "command": "vi_colon_input",
        "context":
        [
            { "key": "setting.command_mode", "operator": "equal", "operand": true }
        ]
    },

    {
        "keys": [";"], "command": "vi_colon_input",
        "args": {
            "initial_text": ":'<,'>"
        },
        "context":
        [
            { "key": "setting.command_mode", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": false }
        ]
    },

    // Ctrl + [でオートコンプリートのパネルを閉じる
    { "keys": ["ctrl+["], "command": "hide_auto_complete", "context":
        [
            { "key": "auto_complete_visible", "operator": "equal", "operand": true }
        ]
    },

    // タブの切替を表示順にする
    { "keys": ["ctrl+tab"], "command": "next_view" },
    { "keys": ["ctrl+shift+tab"], "command": "prev_view" },

    // Vim風タブの切替
    { "keys": ["g", "t"], "command": "next_view",
        "context":
        [
            { "key": "setting.is_widget", "operand": false },
            { "key": "setting.command_mode" }
        ]
    },
    { "keys": ["g", "T"], "command": "prev_view",
        "context":
        [
            { "key": "setting.is_widget", "operand": false },
            { "key": "setting.command_mode" }
        ]
    },

    // Commandモードで0を押した際、入力文字がない本当の先頭ではなく
    // 文字の先頭に行くように変更
    {
        "keys": ["0"], "command": "move_to", "args": {"to": "bol", "extend": false} ,
        "context":
        [
            { "key": "setting.is_widget", "operand": false },
            { "key": "setting.command_mode" }
       ]
    },
    {
        "keys": ["9"], "command": "move_to", "args": {"to": "eol", "extend": false} ,
        "context":
        [
            { "key": "setting.is_widget", "operand": false },
            { "key": "setting.command_mode" }
       ]
    }
]

DashDocのデフォルトのキーバインドを変更。
ユーザ用の設定ファイルに書いたけど上書きされないっぽいのでパッケージ内のファイルを直接編集。

[
    { "keys": ["ctrl+shift+h"], "command": "dash_doc"}
]

Vintageモードを使いやすくする

こんなちょっとしたプラグインを作った。
保存時にINSERT MODEを抜けるのと、AutoComplete表示時にEscなどに割り当ててEscが押されたらAutoCompleteを非表示にしてINSERT MODEを抜ける。

import sublime, sublime_plugin

class OnSaveComannd(sublime_plugin.EventListener):
  def on_post_save(self, view):
    if not view.settings().get('command_mode'):
      view.run_command('hide_auto_complete')
      view.run_command('exit_insert_mode')

class HideAutoCompleteAndExitInsertModeCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    if not self.view.settings().get('command_mode'):
      self.view.run_command('hide_auto_complete')
      self.view.run_command('exit_insert_mode')

言語ごとの設定

該当の言語のファイルを開いた状態でSublime Text2 > Preferences > Settings - More

言語ごとの設定

インストールしたパッケージ

{
    "auto_upgrade_last_run": 1344431907,
    "installed_packages":
    [
        // 開いているすべてのファイルから補完
        "All Autocomplete",
        // カッコを強調表示
        "BracketHighlighter",
        "Git",
        "Gitignore",
        "Package Control",
        "RubyMotion Autocomplete",
        "RubyMotionBuilder",
        "RubyTest",
        // サイドバーからgitを操作
        "SideBarGit",
        // ブロックカーソル
        "SublimeBlockCursor",
        "SublimeCodeIntel",
        // Vintageを強化
        "VintageEx"
        // 選択した文字列をDashで検索
        "DashDoc",
        // irbなどをSublime Text2上で実行
        "SublimeREPL",
        "Milkode_Sublime"
    ]
}

その他

Vimモードでキーリピートが効かない場合(Mac版)

ターミナルから下記を実行。

defaults write com.sublimetext.2 ApplePressAndHoldEnabled -bool false

元に戻す場合。

defaults write -g ApplePressAndHoldEnabled -bool false

パッケージを探す

ターミナルから呼び出せるようにする

sublなるファイルがあるので適当にリンクを貼る。

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/

SublimeREPL

Mac + rbenv環境でシステム規定の古いRubyが使用されてしまう場合はSublimeREPLの設定ファイルに環境に応じたPATHを設定する。

{
 "default_extend_env": {
   "PATH": "{HOME}/.rbenv/bin:{HOME}/.rbenv/shims:/usr/local/bin:{PATH}"
 }
}

rbenv環境で使う

sublでターミナルから立ち上げた方が環境変数なんかを引き継いでくれるようなので、こちらのほうが良さ気?
milkodeがSubilme Text2から動作せず往生した。

アイコンを変更する

/Applications/Sublime Text 2.app/Contents/Resources/Sublime Text2.icnsを置き換える。

最新版

その後もあれやこれやと変更しています。
最新の設定は下記に置いてあります。

toshinori/SublimeText2 · GitHub

67
66
0

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
67
66