Search code examples
rider

Visual Studio like code snippets in Rider


Does anyone know if the JetBrains Rider IDE supports kind of "code snippets"? I usually have a snippet in Visual Studio for creating NUnit test cases, like:

[Test]
[Description("Some description")]
[MaxTime(1000)]
public void Test()
{
#region Arrange
#endregion

#region Assert
#endregion

#region Act
#endregion
}

Solution

  • Yes, there is.

    In Rider, it is called Live Templates.

    • Open menu File > Settings.
    • In the Settings window, expand Editor > Live Templates.
    • Then select the language you want. Let's say C#.
    • The settings window shows the list of shortcuts.
    • Click the New Template icon on the right.Settings
    • In the Shortcut field, define the keyword you want to use to trigger it.
    • You can select any other shortcut to have an example.
    • Save your changes.
    • Go to the editor and type the "shortcut".
    • Rider will create the code for you.

    Keep in mind that Live Templates use a different syntax from Visual Studio Code Snippets, so you can check this page - Predefined Live Templates for C# - for further reference.