# コード箇所を囲む

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/ja-jp/help/ruby/llms.txt).

RubyMine は、ソースコードの言語に応じてさまざまな構造を使ってコード箇所を囲むための標準テンプレートを提供します。 これには、  `if...else 構文`  条件文、  `do...while 構文`  と  `for`  ループ、  `try...catch...finally 構文`  の組み合わせ、XML タグ、折りたたみ領域、その他の構造が含まれます。

Procedure: 言語構造でコードブロックを囲む

1. コードフラグメントを選択します。

2. `Ctrl+Alt+T` (Windows), `⌘ ⌥ T` (macOS), `⌘ ⌥ T` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ T` (macOS System Shortcuts), `Ctrl+Alt+Shift+B` (XWin), `Ctrl+Alt+Shift+B` (GNOME), `Ctrl+Alt+Shift+B` (KDE), `Ctrl+Alt+T` (Emacs), `Ctrl+Alt+T` (Sublime Text), `⌘ ⌥ T` (Sublime Text (macOS)), `Ctrl+Alt+T` (Visual Studio), `Ctrl+Alt+T` (Visual Studio (macOS)), `Meta+Alt+T` (TextMate), `Ctrl+Alt+T` (NetBeans), `Alt+Shift+Z` (Eclipse), `⌘ ⌥ Z` (Eclipse (macOS)) を押すか、メインメニューで  `コード | 囲む`  に移動します。

3. リストから必要なサラウンドステートメントを選択します。

![オプション付きサラウンドのプレビュー](https://resources.jetbrains.com/help/img/idea/2026.3/rm_surround_with_preview.png)

> **Note:**
> ライブテンプレートに [$SELECTION$ 変数](using-live-templates.html#variables_predefined)が含まれている場合は、サラウンドステートメントとして使用できます。
>
>
>
> 独自のサラウンドステートメントを作成するには、 [ライブテンプレートを作成し](using-live-templates.html#create_simple)、テンプレートテキストで  `$選択範囲$`  変数を使用します。

この機能は、次の言語（コンテキスト）に適用されます：

|  コンテキスト  |  囲む  |
| --- | --- |
|  Ruby ステートメント  |      * `(...) 構文`    * `BEGIN{} ブロック`    * `END{} ブロック`    * `if...then...end 構文`    * `while...do...end 構文`    * `unless...then...end 構文`    * `begin...end 構文`    |
|  XML/HTML/RHTML タグ  |      * タグ    * CDATA セクション    * <% ... %>    * [Emmet](using-zen-coding-support.html)    |
|  JavaScript ステートメント  |      * `(expr)`    * `!(expr) 構文`    * `if`    * `if / else 構文`    * `while`    * `do / while 構文`    * `for`    * `try / catch`    * `try / finally 構文`    * `try / catch / finally`    * `with 構文`    * `function`    * `{ } ブロック`    * `関数式`    |
|  カスタム折りたたみ領域のコメント  |   囲む が適用可能なコードの任意のフラグメント。  |

> **Note: 既知のショートカットが競合する場合**
> macOS は、同じデフォルトのショートカット（ `Ctrl+Alt+T` (Windows), `⌘ ⌥ T` (macOS), `⌘ ⌥ T` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ T` (macOS System Shortcuts), `Ctrl+Alt+Shift+B` (XWin), `Ctrl+Alt+Shift+B` (GNOME), `Ctrl+Alt+Shift+B` (KDE), `Ctrl+Alt+T` (Emacs), `Ctrl+Alt+T` (Sublime Text), `⌘ ⌥ T` (Sublime Text (macOS)), `Ctrl+Alt+T` (Visual Studio), `Ctrl+Alt+T` (Visual Studio (macOS)), `Meta+Alt+T` (TextMate), `Ctrl+Alt+T` (NetBeans), `Alt+Shift+Z` (Eclipse), `⌘ ⌥ Z` (Eclipse (macOS)) ）を、コンピューターにインストールされている他のアプリ（たとえば Harvest）の起動に使用する場合があります。 この競合を避けるには、IDE のキーボードショートカットを [設定してください](configuring-keyboard-and-mouse-shortcuts.html)。

