Sublime Text 4で追加された設定など

昨日 (2021/05/21)、Sublime TextのメジャーアップデートであるSublime Text 4がリリースされました。

www.sublimetext.com forest.watch.impress.co.jp

デフォルトのカラースキームがMonokaiからMarianaに変わったり、Open GLによるGPUアクセラレーションが有効になったりしましたが、 他にもちょっとした設定項目の追加などがあったため、便利だと感じたものを紹介します。

目次

互換性

Sublime Text 4は、メジャーアップデートではあるものの設定ファイルやパッケージなどの互換性は維持されています。 私のインストールしている以下のようなパッケージは特に問題なく動作しています。

{
    "bootstrapped": true,
    "in_process_packages":
    [
    ],
    "installed_packages":
    [
        "A File Icon",
        "AdvancedNewFile",
        "All Autocomplete",
        "BracketHighlighter",
        "Case Conversion",
        "Clang Format",
        "CMake",
        "DoxyDoxygen",
        "EditorConfig",
        "FindKeyConflicts",
        "Git",
        "GitGutter",
        "Increment Decrement",
        "Increment Selection",
        "LSP",
        "Origami",
        "Package Control",
        "PackageResourceViewer",
        "ProjectManager",
        "SideBarEnhancements",
        "Smart Delete",
        "Sublime Files",
        "SublimeGHQ",
        "SyncedSideBar",
        "TodoReview",
        "TOML"
    ],
    "repositories":
    [
        "https://github.com/Ryooooooga/SublimeGHQ"
    ],
}

また、macOSの場合設定ファイルの保存先は ~/Library/Application Support/Sublime Text 3/ から ~/Library/Application Support/Sublime Text/ に変更されました。 ただし、~/Library/Application Support/Sublime Text/ が存在しない場合は ~/Library/Application Support/Sublime Text 3/ 以下の設定が読み込まれるため、 移行にあたっての対応は特に必要ありません。

オートコンプリートの強化

オートコンプリート機能の刷新に伴ってオートコンプリートに関する設定項目が複数追加されました。

f:id:Ryooooooga:20210522134143p:plain
Sublime Text 4の補完候補リスト

使用感としてはSublime Text 3とほぼ変わりがないものの、補完候補の種類 (スニペット、関数、型など) に対応したアイコンが表示されるようになり、単純にわかりやすくなりました。 また、補完候補の定義へのジャンプなどが可能になりました。

f:id:Ryooooooga:20210522135214p:plain
Sublime Text 3の補完候補リスト

便利な設定の追加

Sublime Text 4になり、いくつか設定項目が追加されました。 うち、特に便利だと感じたものを紹介します。

draw_white_space のカスタマイズ性の向上

draw_white_space は空白文字の可視性を設定するための項目です。

draw_white_space 自体は Sublime Text 3から存在していましたが、以下の3種類の設定のいずれかしか指定できませんでした。

  • "none": 空白文字を表示しない
  • "all": すべての空白文字を常に可視化する
  • "selection": 選択範囲のみ空白文字を可視化する

Sublime Text 4 ではより複雑な可視性の制御が行えるようになりました。

Sublime Text 4のデフォルトのdraw_white_space

  // Controls when white space is drawn. Any of the following options may be
  // combined:
  // - "selection": Draw white space under the current selection.
  // - "leading": Draw any white space between the beginning of a line and the
  //              first character.
  // - "enclosed": Draw white space enclosed by other characters.
  // - "trailing": Draw white space following the last character on a line.
  // - "isolated": Draw white space on lines containing no other characters.
  // - "all": All of the above, ie. always draw white space.
  //
  // These options may be further refined by appending any of the following
  // separated by an underscore:
  // - "none": Don't draw this kind of white space.
  // - "tabs": Only draw tabs here.
  // - "spaces": Only draw spaces here.
  // - "mixed": Only draw white space that does not match the indentation
  //            style. For example if "translate_tabs_to_spaces" is true only
  //            draw tabs.
  // - "mixed_tabs": Like "mixed" but only draw tabs.
  // - "mixed_spaces": Like "mixed" but only draw spaces.
  // - "all": Draw both tabs and spaces. This is the default.
  //
  // Note that options are applied in sequence. So a later option may override
  // an earlier one.
  //
  // Examples:
  // - ["selection", "trailing", "isolated"]:
  //     Draw white space at the end of any lines and under the selection.
  //
  // - ["all_tabs", "selection"]:
  //     Draw tabs anywhere and any white space under the selection.
  //
  // - ["all_mixed"]:
  //     Draw any white space that does not match the indentation style.
  //
  // - ["leading_mixed", "isolated_mixed"]:
  //     Draw any indentation that does not match the indentation style.
  //
  // - ["selection_mixed_tabs"]:
  //     Draw only tabs under the selection and only if the indentation style
  //     is spaces.
  //
  // - ["all_tabs", "selection"]:
  //     Draw all tabs and any white space under the selection.
  //
  // - ["all", "selection_none"]:
  //     Inverse of the default. Draw white space everywhere except under the
  //     selection.
  "draw_white_space": ["selection"],

例えば、私の場合は以下のように設定しています。

   "draw_white_space": [
        "all_tabs",  // すべてのタブ文字を表示する
        "selection", // 選択範囲の空白文字を可視化する
        "trailing",  // 行末の空白文字を可視化する
    ],

ただし、設定の記述順によって表示が変わったり、そもそもの指定方法がわかりにくかったりとなかなかに難解です。(ちょっとだめなところがSublime Textっぽくてかわいいね)

"ignored_snippets" の追加

"ignored_snippets"Sublime Text 4から追加された、スニペットを無効化するための項目です。

Sublime Text 4のignored_snippets

   // A list of wildcard patterns specifying which snippet files to ignore.
    // For example, to ignore all the default C++ snippets, set this to
    // ["C++/*"]
    "ignored_snippets": [],

Sublime Text 3でデフォルトで組み込まれているパッケージ (C++パッケージなど) のスニペットを無効化したい場合、 PackageResourceViewer などを使ってデフォルトスニペットファイルを抽出し、 それらのスニペットファイルの中身を削除する などの作業が必要でした。

Sublime Text 4では、"ignored_snippets"スニペットのファイル名を追加することで無効化できるようになりました。(なにげにこれが一番うれしかった)

   // デフォルトのC++スニペットをすべて無効化する
    "ignored_snippets": [
        "C++/*",
    ],

"hardware_acceleration" の追加

"hardware_acceleration"GPUによるハードウェアアクセラレーションの有効化に関する設定項目です。 デフォルトではmacOSでのみOpenGLによるハードウェアアクセラレーションが有効になっています。 

Sublime Text 4のhardware_acceleration

   // Enables hardware accelerated rendering. This moves rendering to your GPU,
    // allowing for faster rendering at higher resolutions. Changing this
    // setting requires an application restart to take effect.
    // - "none": Performs CPU rendering.
    // - "opengl": Uses OpenGL for rendering. Minimum required version is 4.1
    //
    // On Mac, this value is overridden in the platform specific settings.
    "hardware_acceleration": "none",

"relative_line_numbers" の追加

"relative_line_numbers"true に設定すると、行番号が相対表示になります。 (Vimset relativenumber のような感じ)

Sublime Text 4のrelative_line_numbers

   // relative_line_numbers will draw each line number as the distance from
    // the current line. Useful in conjunction with Vintage.
    "relative_line_numbers": false,

ST4のbeta版を使っていた身としては正式リリースは嬉しい限りですが、いくらなんでも遅すぎませんかね? 日本でSublime Text使ってる人はもはや私しかおらないぞ。