Refactor with Move Selection to New File to split a large file into manageable pieces, to share code among modules, or to reveal previously private code.
Use other refactoring commands, e.g. Move Implementation to Source File, to move code between existing source files and header files.
Access
To move into a new file, select one or more entire lines, then choose Move Selection to New File from the Quick Action and Refactoring menu (Shift+Alt+Q).
![](/~/media/wholetomato/kb/documentation/move-selection-to-new-file/moveselectionmenu.ashx?la=ru&hash=AF33C83F1B375E8B1BE6F0D8AA3F5BAF168FA748)
In the dialog that opens, enter a file name for the destination—a file that cannot exist. If the destination is a header file, you have the option of including the new file in the current file.
![](/~/media/wholetomato/kb/documentation/move-selection-to-new-file/moveselectiondialog.ashx?la=ru&hash=90B3CC8637D2482CB95C314E0B45527342B51082)
Your selection is moved to a new file, and formatted according to a VA Snippet. The new file is created in the same directory as your original file, and automatically added to your current project.
![](/~/media/wholetomato/kb/documentation/move-selection-to-new-file/moveselectionresult.ashx?la=ru&hash=4A47928B398BC26C45874F231F9DE38AA3F5A796)
If you chose the option, an include directive is inserted in your original file.
![](/~/media/wholetomato/kb/documentation/move-selection-to-new-file/moveselectioninclude.ashx?la=ru&hash=B1213687EC8F23C64B374E0EB9C991C3F5F605AC)
If you move to a new file the declaration of one class from a multi-class header file, presumably to create manageable pieces, follow your move with another that moves the corresponding class implementation to a new source file. If you first move a class implementation, follow it with another that moves the corresponding class declaration.
Format
You can customize the content of new files by editing several VA Snippets related to refactoring. There are separate VA Snippets for separate programming languages, and in the case of C/C++, for header files and source files.
Type of destination file |
VA Snippet for format |
C++ header |
Create Header File |
C++ source |
Create Source File |
C# source |
Create File |
For example, the default VA Snippet for Create Header File makes use of the Microsoft #pragma directive.
![](/~/media/wholetomato/kb/documentation/move-selection-to-new-file/moveselectionpragma.ashx?la=ru&hash=A441179A8803423E6E843BBCEB519F8EA27CD7B5)
Modify the VA Snippet if you prefer to guard with a universal #ifdef.