Built-in IDE macros | PyCharm (original) (raw)

PyCharm provides a number of built-in macros — variables that you can use to define paths, options, and other command-line arguments for external tools and run configurations. Dialog fields that support macros display a plus icon next to them:

Add an IDE macro

The value of a macro depends on the current context. For example, to insert the name of the directory that contains the current file, use $FileDirName$. To insert the full path to the directory, use $FileDir$.

Macro Description
WORKSPACEDIRWORKSPACE_DIRWORKSPACEDIR 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.
PROJECTDIRPROJECT_DIRPROJECTDIR 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.
USERHOMEUSER_HOMEUSERHOME User home directory.
FILEFILEFILE The absolute path to the current file, including the extension.
AffectedModuleNamesAffectedModuleNamesAffectedModuleNames The names of modules that are related to the current file, separated by commas.
ClipboardContentClipboardContentClipboardContent The current contents of the system clipboard.
ColumnNumberColumnNumberColumnNumber The column number where the caret is located in the current file.
ContentRootContentRootContentRoot The path to the content root to which the current file belongs.
FileDirFileDirFileDir The absolute path to the directory that contains the current file.
FileDirNameFileDirNameFileDirName The name of the directory that contains the current file.
FileDirPathFromParent(dir)FileDirPathFromParent(dir)FileDirPathFromParent(dir) The path to the directory that contains the current file relative to a parent directory specified as the parameter dir.Argument 1: /Users/jetbrains/myProjects/FileDirPathFromParent/ Argument 2: 1
FileDirRelativeToProjectRootFileDirRelativeToProjectRootFileDirRelativeToProjectRoot The path to the directory that contains the current file relative to the module's content root.
FileDirRelativeToSourcepathFileDirRelativeToSourcepathFileDirRelativeToSourcepath The path to the directory that contains the current file relative to the sourcepath root.
FileEncodingFileEncodingFileEncoding The encoding of the current file.
FileExtFileExtFileExt The extension of the current file.
FileNameFileNameFileName The name of the current file (including all extensions).
FileNameWithoutAllExtensionsFileNameWithoutAllExtensionsFileNameWithoutAllExtensions 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 FileNameWithoutAllExtensionsFileNameWithoutAllExtensionsFileNameWithoutAllExtensions macro will return hello.
FileNameWithoutExtensionFileNameWithoutExtensionFileNameWithoutExtension 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 FileNameWithoutExtensionFileNameWithoutExtensionFileNameWithoutExtension macro will return hello.txt.
FileParentDirFileParentDirFileParentDir The name of the parent directory to the directory where the current file is located.
FilePathFilePathFilePath The absolute path to the current file.
FilePathRelativeToProjectRootFilePathRelativeToProjectRootFilePathRelativeToProjectRoot The path to the current file relative to the module's content root.
FilePathRelativeToSourcepathFilePathRelativeToSourcepathFilePathRelativeToSourcepath The path to the current file relative to the sourcepath root.
FilePromptFilePromptFilePrompt Shows the file system dialog to select the file.
FileRelativeDirFileRelativeDirFileRelativeDir The path to the directory where the current file is located relative to the module's content root.
FileRelativePathFileRelativePathFileRelativePath The path to the current file relative to the module's content root.
IsMakeIsMakeIsMake Returns true if compilation was performed with make.
LineNumberLineNumberLineNumber The line number where the caret is located in the current file.
ModuleFileDirModuleFileDirModuleFileDir The absolute path to the directory where the current module file is located.
ModuleFilePathModuleFilePathModuleFilePath The absolute path to the current module file.
ModuleNameModuleNameModuleName The name of the current module file without the extension.
ModuleSdkPathModuleSdkPathModuleSdkPath The path to the project interpreter.
ModuleSourcePathModuleSourcePathModuleSourcePath The current module's source path.
OSNameOSNameOSName The name of the operating system in lower case. It returns the value of System.getProperty("os.name") truncated to the first space character. So it doesn't contain specific versions, only the OS family, such as windows, mac, or linux.
PasswordPasswordPassword Shows a dialog to specify a password. Similar to $Prompt$, but with masked input.You can optionally specify prompt text by adding it after a colon, for example: Password:APItokenPassword:API tokenPassword:APItoken
ProjectFileDirProjectFileDirProjectFileDir The absolute path to the current project directory.
ProjectNameProjectNameProjectName The name of the current project directory.
ProjectpathProjectpathProjectpath The current project's source path.
PromptPromptPrompt Shows a dialog to pass an arbitrary string.You can optionally specify prompt text and the default value separated by colons, for example: Prompt:Username:AlicePrompt:Username:AlicePrompt:Username:Alice
PyInterpreterDirectoryPyInterpreterDirectoryPyInterpreterDirectory The directory containing the Python interpreter selected for the project.
RemoteProjectFileDirRemoteProjectFileDirRemoteProjectFileDir The absolute path to the project directory on a remote server.
SelectedTextSelectedTextSelectedText The text currently selected in the editor.
SelectionEndColumnSelectionEndColumnSelectionEndColumn The column number where the selection ends.
SelectionEndLineSelectionEndLineSelectionEndLine The line number where the selection ends.
SelectionStartColumnSelectionStartColumnSelectionStartColumn The column number where the selection starts.
SelectionStartLineSelectionStartLineSelectionStartLine The line number where the selection starts.
SourcepathSourcepathSourcepath The complete sourcepath of the project.
SourcepathEntrySourcepathEntrySourcepathEntry The entry in the sourcepath related to the current file.
TempDirTempDirTempDir The directory for temporary files.On Windows, it either returns the value of the %TEMP% environment variable or falls back to AppData\Local\Temp under the user's home directory (as returned by System.getProperty("user.home")) .On other operating systems, TempDirTempDirTempDir returns /tmp.
UnixSeparators(path)UnixSeparators(path)UnixSeparators(path) Takes a path as the parameter and converts all separators to forward slashes.For example, UnixSeparators(foobar)UnixSeparators(\foo\bar)UnixSeparators(foobar) will return /foo/bar.

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$.

Create a new path variable

  1. Press Ctrl+Alt+S to open settings and then select .
  2. Click the Add button, enter the name and value of the variable, and click OK to apply the changes.

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.

Last modified: 08 May 2025