Live template variables
When you expand a live template abbreviation, its variables either appear as input fields where you can type values or are replaced with values. These may be default values that you can modify or values calculated using functions.
To declare variables within templates, use the following format:
In expressions, use variable names without opening and closing dollar characters
$, for example,
Define each variable using an expression and provide a default value for cases when the expression fails to evaluate.
This expression may contain the following constructs:
String constants in double quotes
Names of other variables defined in a live template
Predefined functions with possible arguments
Configure template variables
In the Settings/Preferences dialog Ctrl+Alt+S, go to .
Select a template where you want to configure variables.
Specify variables in the template text and click Edit variables.
In the Edit Template Variables dialog, you can do the following for each variable:
Change the variable name
Define an expression using predefined functions
Specify the default value for cases when the expression fails to evaluate
Specify whether you want to skip the variable when prompting the user for input if the expression evaluated successfully
Predefined template variables
CLion supports the following predefined live template variables that cannot be modified:
$END$indicates the position of the cursor when the code snippet is complete, and you can no longer press Tab to jump to the next variable.
$SELECTION$is used in surround templates and denotes the code fragment to be wrapped. After the template expands, it wraps the selected text as specified in the template. For example, if you select
EXAMPLEin your code and invoke the
"$SELECTION$"template via the assigned abbreviation or by pressing Ctrl+Alt+T and selecting the desired template from the list, CLion will wrap the selection in double quotes as follows:
Functions used in live template variables
The following functions can be used to define live template variables:
|Provides the variants of type deduction in range-base |
Returns the characters that indicate the end of a block comment in the current language context.
Returns the characters that indicate the start of a block comment in the current language context.
Converts a string into camelCase.
Capitalizes the first letter of a string.
Capitalizes all the letters of a string, and inserts an underscore between the parts.
|Returns the name of the current class (where you expand the template). Can be useful for constructor templates.|
|Returns the contents of the system clipboard.|
|Returns the characters that indicate the end of a comment in the current language context. For languages with line comments, the return value is empty.|
|Returns the characters that indicate the start of a comment in the current language context. For languages with line comments, the return value is the start of a line comment, same as lineCommentStart().|
|Invokes code completion at the position of the variable.|
|Invokes smart type completion at the position of the variable.|
Returns a concatenation of all the strings passed to the function as parameters.
Returns the current system date.
By default, without a parameter, it returns the date in the current system format. To use a different format, provide a parameter according to the SimpleDateFormat specification. For example, the
Returns a list of columns for a table or a view. The
Returns a name of a table or a view. The
Replaces the first letter of a string with the corresponding lowercase letter.
Returns a list of strings suggested for completion when the template expands.
Escapes special characters so that the result can be used in a Java string.
For example, it replaces the tab character with
Returns the name of the current method using the
Returns the string format specifier for the object which is passed as a parameter of this function.
Returns the names of collections and enumerations available in the current scope.
For an example, see the
|Returns the name of the current file with its extension.|
|Returns the name of the current file without its extension.|
|Returns the absolute path to the current file.|
|Returns the current file path relative to the current project. To check what the relative path is for a given file, right-click it and select Copy Reference, or press Ctrl+Alt+Shift+C.|
Returns the first word of the string passed as the parameter.
|Returns the characters that indicate the start of a line comment in the current language context.|
|Returns the current line number.|
|Converts a string into lower case and inserts n-dashes as separators. For example, |
|Returns the name of the method in which the template expands.|
|Returns the list of visible objects that contain member functions, listed as parameters.|
|Returns the name of the current Python function.|
|Finds all occurrences of |
Declares the left-side variable with a type of the right-side expression.
Some predefined templates in the iterations group use the
Returns the parameter details when adding a parameter to a function or method.
|Converts a string into snake_case. For example, |
|Returns the specified string with spaces as separators. For example, |
|Replaces spaces with underscores in the string passed as the parameter. For example, |
|Returns the substring up to the specified delimiter. This is helpful for removing the extensions in test file names. For example, |
Returns a suggested name for the index variable in an iteration from most commonly used ones:
Some of the predefined templates in the iterations group (
Suggests the name for a variable based on the variable type and its initializer expression, according to your code style settings that refer to the variable naming rules.
For example, if it is a variable that holds an element within an iteration, CLion makes a guess on the most reasonable name taking into account the name of the iterated container. Some of the predefined templates in the iterations group (
Returns the current system time.
By default, without a parameter, it returns the time in the current system format. To use a different format, provide a parameter according to the SimpleDateFormat specification. For example, the
|Transforms a string with underscores (like snake_case) into camelCase. For example, |
|Transforms underscores in a string to spaces. For example, |
|Returns the name of the current user.|
|Returns a variable that is an instance of the object used as a range expression in a loop.|
|Returns a variables that is an instance of the object that contains |
Returns all variables that may be assigned to the type passed as the parameter. For example,.
If you pass an empty string