# Surround code fragments

CLion 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,  folding regions, and other constructs.

| Before | After |
| --- | --- |
|    ![The 'Surround with' options](https://resources.jetbrains.com/help/img/idea/2026.2/cl_qsg_surroundwith_before.png)  |    ![The result of surrounding with while](https://resources.jetbrains.com/help/img/idea/2026.2/cl_qsg_surroundwith_after.png)  |

Procedure: Surround a code block with language constructs

1. Select a code fragment.

2. Call `Code | Surround With` from the main menu or 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)), `⌘ ⌥ T` (Xcode), `Ctrl+Alt+T` (Visual Studio), `Ctrl+Alt+T` (Visual Studio (macOS)), `Ctrl+Alt+T` (ReSharper), `Ctrl+Alt+T` (ReSharper (macOS)), `Ctrl+Alt+T` (QtCreator), `⌘ ⌥ T` (QtCreator (macOS)), `Ctrl+Alt+T` (NetBeans), `Alt+Shift+Z` (Eclipse), `⌘ ⌥ Z` (Eclipse (macOS)).

3. Select the necessary surround statement from the list. When you hover over an option, you will see a preview of the change that will be applied if you select that statement.

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

