Using the move refactoring
With the move refactoring, you can take any top-level named identifier from your code and move it either to a separate file or to a different package.
For example purposes, clone the Delve project from Github: git clone https://github.com/derekparker/delve
. For more information about Git, refer to the official Git documentation.
Open the Delve project in GoLand.
Navigate to delve | pkg | config | split.go.
Right-click the
SplitQuotedFields
function declaration and select Refactor | Move. Alternatively, press F6.In the To file field, type
newsplit
.Click Refactor. The newsplit.go file is created with the function that we moved. The move refactoring does not only move declarations, but also adds the required imports, updates the references to the identifier, and performs a cleanup of the previous definition place of the identifier so that your code can still work.
![https://resources.jetbrains.com/help/img/idea/2024.3/go_move_refactoring_delve.png](https://resources.jetbrains.com/help/img/idea/2024.3/go_move_refactoring_delve.png)
Open the Delve project in GoLand.
Navigate to delve | pkg | goversion | go_version.go.
Right-click the
GoVersion
type and select Refactor | Move. Alternatively, press F6.Specify a file path and a file name. For example, add
/gover
to the file path in the To directory field, and typegover
in the To file field.Select
AfterOrEqual
andIsDevel
identifiers for theGoVersion
type. GoLand displays a notification when the identifier is private and is not exported during the move operation.Click Preview. In the Find tool window, you can review refactoring changes and exclude Delete or remove Ctrl0X code parts from the refactoring process.
![Preview changes Preview changes](https://resources.jetbrains.com/help/img/idea/2024.3/go_move_refactoring_preview.png)
Thanks for your feedback!