GoLand 2022.2 Help

Built-in IDE macros

GoLand 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. Their values depend 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

$AffectedModuleNames$

The names of modules that are related to the current file, separated by commas.

$ClipboardContent$

The current contents of the system clipboard.

$ContentRoot$

The path to the content root to which the current file belongs.

$FileDir$

The absolute path to the directory that contains the current file.

$FileDirName$

The name of the directory that contains the current file.

$FileDirPathFromParent(dir)$

The path to the directory that contains the current file relative to a parent directory specified as the parameter dir.

$FileDirRelativeToProjectRoot$

The path to the directory that contains the current file relative to the module's content root.

$FileDirRelativeToSourcepath$

The path to the directory that contains the current file relative to the sourcepath root.

$FileEncoding$

The encoding of the current file.

$FileExt$

The extension of the current file.

$FileName$

The name of the current file (including all extensions).

$FileNameWithoutAllExtensions$

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 $FileNameWithoutAllExtensions$ macro will return hello.

$FileNameWithoutExtension$

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 $FileNameWithoutExtension$ macro will return hello.txt.

$FileParentDir$

The name of the parent directory to the directory where the current file is located.

$FilePath$

The absolute path to the current file.

$FilePathRelativeToProjectRoot$

The path to the current file relative to the content root.

$FilePathRelativeToSourcepath$

The path to the current file relative to the sourcepath root.

$FilePrompt$

Shows the file system dialog to select the file.

$FileRelativeDir$

The path to the directory where the current file is located relative to the module's content root.

$FileRelativePath$

The path to the current file relative to the module's content root.

$GoBinDirs$

Paths to bin directories that store Go tools.

$GoExecPath$

The path of the Go executable.

$GoFileImportPath$

The import path for of the current file.

$GOPATH$

The path set in the GOPATH environment variable.

$GOROOT$

The path to the project Go SDK.

$IsMake$

Returns true if compilation was performed with make.

$ModuleFileDir$

The absolute path to the directory where the current module file is located.

$ModuleFilePath$

The absolute path to the current module file.

$ModuleName$

The name of the current module file without the extension.

$ProjectFileDir$

The absolute path to the current project directory.

$ProjectName$

The name of the current project directory.

$Projectpath$

The current project's source path.

$Prompt$

Shows a dialog to pass an arbitrary string.

$RemoteProjectFileDir$

The absolute path to the project directory on a remote server.

$Sourcepath$

The complete sourcepath of the project.

$SourcepathEntry$

The entry in the sourcepath related to the current file.

$UnixSeparators(path)$

Takes a path as the parameter and converts all separators to forward slashes.

For example, $UnixSeparators(\foo\bar)$ 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 exactly the same way as you add macros – with ampersands before and after the variable: $MY_VAR$.

Create a new path variable

  1. Press Ctrl+Alt+S to open the IDE settings and select Appearance & Behavior | Path Variables.

  2. Click the Add button and specify the name and value of the variable.

  3. 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:

<macro implementation="full.macro.class.Name"/>

For more information about the available extension points, see IntelliJ Platform Plugin SDK documentation.

Last modified: 28 July 2022