Built-in IDE macros
CLion provides a number of built-in macros, which are variables that you can use to specify various paths, options, and other command-line arguments for external tools and run configurations. Dialog fields that accept macros as values have a plus icon on them:
![Add an IDE macro Add an IDE macro](https://resources.jetbrains.com/help/img/idea/2024.2/add_macros_icon.png)
The value of a macro depends on the current context. For example, if you need to pass the name of the directory that contains the current file, you can use $FileDirName$
. Or if you need the full path: $FileDir$
.
Macro | Description |
---|---|
| The path to the workspace where the current project belongs. The workspace is the root of the open file hierarchy and can include multiple projects. |
| The root of the project where run.json is located. A project is typically a collection of files for developing and building an application such as a Maven or Node.js project. |
| User home directory. |
| The absolute path to the current file, including the extension. |
| The names of modules that are related to the current file, separated by commas. |
| The complete classpath of the project. |
| The entry in the classpath related to the current file. |
| The current contents of the system clipboard. |
| The column number where the caret is located in the current file. |
| The path to the content root to which the current file belongs. |
| The name of the class defined by the current file. |
| The absolute path to the directory that contains the current file. |
| The name of the directory that contains the current file. |
| The path to the directory that contains the current file relative to a parent directory specified as the parameter |
| The path to the directory that contains the current file relative to the module's content root. |
| The path to the directory that contains the current file relative to the sourcepath root. |
| The encoding of the current file. |
| The extension of the current file. |
| The fully qualified package name of the current file. For example, in the case of com.example.mypackage.MyClass, the fully qualified name of the package is com.example.mypackage. |
| The name of the current file (including all extensions). |
| The name of the current file without any extensions. This is useful when the file's extension got duplicated. It will remove any periods and everything that follows. For example, if the file is hello.txt.txt, the |
| The name of the file without the extension. This removes only one occurrence of a period followed by an extension. For example, if the file is hello.txt.txt, the |
| The immediate package name (not fully qualified) of the current file. For example, in the case of com.example.mypackage.MyClass, the name of the package is mypackage. |
| The name of the parent directory to the directory where the current file is located. |
| The absolute path to the current file. |
| The path to the current file relative to the module's content root. |
| The path to the current file relative to the sourcepath root. |
| Shows the file system dialog to select the file. |
| The path to the directory where the current file is located relative to the module's content root. |
| The path to the current file relative to the module's content root. |
| Returns |
| The line number where the caret is located in the current file. |
| The absolute path to the directory where the current module file is located. |
| The absolute path to the current module file. |
| The name of the current module file without the extension. |
| The current module's source path. |
| The name of the operating system in lower case. It returns the value of |
| The current module's output path. |
| The absolute path to the current project directory. |
| The name of the current project directory. |
| The current project's source path. |
| Shows a dialog to pass an arbitrary string. You can optionally specify prompt text and the default value separated by colons, for example: |
| The absolute path to the project directory on a remote server. |
| The text currently selected in the editor. |
| The column number where the selection ends. |
| The line number where the selection ends. |
| The column number where the selection starts. |
| The line number where the selection starts. |
| The complete sourcepath of the project. |
| The entry in the sourcepath related to the current file. |
| The directory for temporary files. On Windows, it either returns the value of the On other operating systems, |
| Takes a path as the parameter and converts all separators to forward slashes. For example, |
Paths to resources outside the project
You can use path variables to point to resources outside the project. Add configured path variables the same way as you add macros – with dollar signs before and after the variable: $MY_VAR$
.
Custom macros
You can define a custom macro for your plugin by using the com.intellij.ide.macro.Macro
extension point. After that, register the macro in plugin.xml:
For more information about the available extension points, refer to IntelliJ Platform Plugin SDK documentation.