Sublime Text

開発ツール

Sublime Text

概要

Sublime TextはSublime HQ Pty Ltdが開発する軽量で高機能なテキストエディタです。高速な動作、直感的なインターフェース、豊富なカスタマイズ機能により、多くの開発者に愛用されています。

詳細

Sublime Textは2008年にリリースされ、現在はSublime Text 4が最新版として提供されています。C++とPythonで開発されており、Windows、macOS、Linuxでクロスプラットフォーム対応しています。軽量でありながら強力な機能を持ち、特にその高速性と応答性で知られています。

Sublime Textの最大の特徴は、「Goto Anything」機能、マルチカーソル・マルチ選択、ミニマップ表示、分割編集、コマンドパレット、強力な検索・置換機能などです。Package Controlによる豊富なプラグインエコシステムにより、あらゆるプログラミング言語と開発ワークフローに対応できます。

シンタックスハイライト、コード補完、スニペット機能、フォールディング、Vintageモード(Vim風編集)など、現代的なテキストエディタに求められる機能を全て備えています。また、JSONベースの設定ファイルによる細かなカスタマイズが可能で、ユーザーの好みに応じて最適化できます。

メリット・デメリット

メリット

  • 極めて軽量: デフォルトで非常に軽量で高速な起動と動作
  • マルチカーソル: 複数箇所の同時編集による高い編集効率
  • ミニマップ: ファイル全体の俯瞰表示による効率的ナビゲーション
  • 豊富なショートカット: ほとんどの操作をキーボードで実行可能
  • カラム選択: 柔軟な範囲選択による多様な編集方法
  • Vintageモード: 組み込みのVim風編集機能
  • Package Control: 豊富なプラグインによる機能拡張

デメリット

  • 有償ライセンス: 継続使用には購入が必要(試用版は機能制限あり)
  • プロプライエタリ: オープンソースではなく、ソースコード非公開
  • 購入促進メッセージ: 未購入時に定期的な購入促進ダイアログが表示
  • 印刷機能なし: ファイルの印刷機能が提供されていない
  • 限定的な統合機能: IDEレベルの統合開発機能は限定的
  • プラグイン依存: 高度な機能にはプラグインのインストールが必要
  • アップデート頻度: メジャーアップデートの間隔が長い

主要リンク

書き方の例

基本設定例

// Preferences.sublime-settings - 基本設定
{
    "theme": "Adaptive.sublime-theme",
    "color_scheme": "Monokai.sublime-color-scheme",
    "font_face": "Fira Code",
    "font_size": 12,
    "font_options": ["gray_antialias", "subpixel_antialias"],
    "line_numbers": true,
    "rulers": [80, 120],
    "word_wrap": true,
    "wrap_width": 80,
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "ensure_newline_at_eof_on_save": true,
    "show_encoding": true,
    "show_line_endings": true,
    "highlight_line": true,
    "highlight_modified_tabs": true,
    "show_full_path": true,
    "preview_on_click": false,
    "folder_exclude_patterns": [".git", "node_modules", "__pycache__"],
    "file_exclude_patterns": ["*.pyc", "*.class", "*.o", "*.so", "*.dll"],
    "binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"]
}

キーバインド設定

// Default (Windows).sublime-keymap - カスタムキーバインド
[
    { "keys": ["ctrl+shift+p"], "command": "show_overlay", "args": {"overlay": "command_palette"} },
    { "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
    { "keys": ["ctrl+shift+f"], "command": "show_panel", "args": {"panel": "find_in_files"} },
    { "keys": ["ctrl+`"], "command": "show_panel", "args": {"panel": "console", "toggle": true} },
    { "keys": ["ctrl+shift+`"], "command": "new_window" },
    { "keys": ["ctrl+k", "ctrl+b"], "command": "toggle_side_bar" },
    { "keys": ["ctrl+k", "ctrl+m"], "command": "toggle_minimap" },
    { "keys": ["alt+shift+1"], "command": "set_layout", "args": {"cols": [0.0, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1]]} },
    { "keys": ["alt+shift+2"], "command": "set_layout", "args": {"cols": [0.0, 0.5, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]} },
    { "keys": ["alt+shift+3"], "command": "set_layout", "args": {"cols": [0.0, 0.33, 0.66, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1], [2, 0, 3, 1]]} },
    { "keys": ["ctrl+shift+t"], "command": "reopen_last_file" },
    { "keys": ["ctrl+shift+a"], "command": "expand_selection", "args": {"to": "tag"} },
    { "keys": ["ctrl+shift+j"], "command": "expand_selection", "args": {"to": "indentation"} },
    { "keys": ["ctrl+shift+space"], "command": "expand_selection", "args": {"to": "scope"} },
    { "keys": ["ctrl+alt+up"], "command": "select_lines", "args": {"forward": false} },
    { "keys": ["ctrl+alt+down"], "command": "select_lines", "args": {"forward": true} }
]

プロジェクト設定例

// project_name.sublime-project - プロジェクト設定
{
    "folders": [
        {
            "name": "Source",
            "path": "./src",
            "folder_exclude_patterns": ["__pycache__", "*.egg-info"],
            "file_exclude_patterns": ["*.pyc", "*.pyo"]
        },
        {
            "name": "Tests",
            "path": "./tests"
        },
        {
            "name": "Docs",
            "path": "./docs"
        }
    ],
    "settings": {
        "tab_size": 4,
        "translate_tabs_to_spaces": true,
        "trim_trailing_white_space_on_save": true,
        "ensure_newline_at_eof_on_save": true,
        "rulers": [79, 99],
        "word_wrap": true,
        "wrap_width": 79
    },
    "build_systems": [
        {
            "name": "Python",
            "cmd": ["python", "-u", "$file"],
            "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
            "selector": "source.python",
            "working_dir": "${project_path}"
        },
        {
            "name": "Node.js",
            "cmd": ["node", "$file"],
            "selector": "source.js",
            "working_dir": "${project_path}"
        }
    ]
}

スニペット例

<!-- python_class.sublime-snippet - Pythonクラステンプレート -->
<snippet>
    <content><![CDATA[
class ${1:ClassName}:
    """${2:Class description}"""
    
    def __init__(self${3:, param}):
        """Initialize ${1:ClassName}.
        
        Args:
            ${3:param}: ${4:Parameter description}
        """
        ${5:pass}
    
    def ${6:method_name}(self${7:, param}):
        """${8:Method description}.
        
        Args:
            ${7:param}: ${9:Parameter description}
            
        Returns:
            ${10:Return description}
        """
        ${11:pass}
]]></content>
    <tabTrigger>class</tabTrigger>
    <scope>source.python</scope>
    <description>Python Class Template</description>
</snippet>

マクロ例

// Default.sublime-macro - コメントトグルマクロ
[
    {
        "command": "move_to", 
        "args": {"to": "bol", "extend": false}
    },
    {
        "command": "move_to", 
        "args": {"to": "bol", "extend": true}
    },
    {
        "command": "toggle_comment"
    },
    {
        "command": "move", 
        "args": {"by": "lines", "forward": true}
    }
]

Package Control設定

// Package Control.sublime-settings - パッケージ管理設定
{
    "bootstrapped": true,
    "in_process_packages": [],
    "installed_packages": [
        "A File Icon",
        "All Autocomplete",
        "Anaconda",
        "AutoFileName",
        "BracketHighlighter",
        "Color Highlight",
        "DocBlockr",
        "Emmet",
        "GitGutter",
        "HTML-CSS-JS Prettify",
        "Markdown Preview",
        "Package Control",
        "SideBarEnhancements",
        "SublimeLinter",
        "SublimeLinter-eslint",
        "SublimeLinter-flake8",
        "Theme - Spacegray"
    ],
    "repositories": []
}

シンタックス定義例

# CustomLanguage.sublime-syntax - カスタム言語シンタックス
%YAML 1.2
---
name: Custom Language
file_extensions: [cust]
scope: source.custom

contexts:
  main:
    - match: '#.*$'
      scope: comment.line.number-sign.custom
    
    - match: '"'
      scope: punctuation.definition.string.begin.custom
      push: double_quoted_string
    
    - match: '\b(function|if|else|while|for)\b'
      scope: keyword.control.custom
    
    - match: '\b\d+\b'
      scope: constant.numeric.custom
    
    - match: '\b[a-zA-Z_][a-zA-Z0-9_]*\b'
      scope: variable.other.custom

  double_quoted_string:
    - meta_scope: string.quoted.double.custom
    - match: '\\.'
      scope: constant.character.escape.custom
    - match: '"'
      scope: punctuation.definition.string.end.custom
      pop: true