# Surround code fragments

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

RubyMine provides standard templates for surrounding code fragments with various constructs based on the language of the source code. This includes `if...else` conditional statements,  `do...while` and `for` loops,  combinations of `try...catch...finally`, XML tags,  folding regions, and other constructs.

Procedure: Surround a code block with language constructs

1. Select a code fragment.

2. Press `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)) or go to `Code | Surround With` in the main menu.

3. Select the necessary surround statement from the list.

![Preview for surround with options](https://resources.jetbrains.com/help/img/idea/2026.3/rm_surround_with_preview.png)

> **Note:**
> If live templates contain the [$SELECTION$ variable](using-live-templates.html#variables_predefined), they can be used as surround statements.
>
>
>
> To create your own surround statement,  [create a live template](using-live-templates.html#create_simple) and use the `$SELECTION$` variable in the template text.

This feature applies to the following languages (contexts):

| Context | Surround with |
| --- | --- |
| Ruby statements |      * `(...)`    * `BEGIN{}`    * `END{}`    * `if...then...end`    * `while...do...end`    * `unless...then...end`    * `begin...end`    |
|  XML/HTML   /RHTML tags  |      * Tag    * CDATA section    * <% ... %>    * [Emmet](using-zen-coding-support.html)    |
| JavaScript statements |      * `(expr)`    * `!(expr)`    * `if`    * `if / else`    * `while`    * `do / while`    * `for`    * `try / catch`    * `try / finally`    * `try / catch / finally`    * `with`    * `function`    * `{ }`    * `function expression`    |
|   Custom folding region comments  | Any fragment of code, where Surround With is applicable. |

> **Note: Known shortcut conflict**
> The same default shortcut (`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))) may be used by macOS for launching other apps (for example, Harvest) installed on your computer. To avoid the conflict, [configure](configuring-keyboard-and-mouse-shortcuts.html) your IDE keyboard shortcuts.

