How To Create a Custom Code Snippets File

A very handy tool you have at your disposal when editing your scripts is the use of Code Snippets. When using the script editor, you can press F4 to open the code snippet pop-up, which permits you to select one of the commonly-used code methods from a list:


From this window you can select with your mouse the snippet to use, or you can press the associated hotkey listed on the right. This will add the snippet to your code for editing.

You can also define your own code snippets if you want to. Before doing this, you'll need to create a file called "snippets.txt" in one of the following directories:

Windows: %ProgramData%\GameMakerStudio2\User\

macOS: /Users/Shared/GameMakerStudio2/User/

This folder is not modified during an update to GameMaker Studio 2, so your edited file will remain intact (but any edits to the base snippets file in the install directory will be reverted).


Please note that this FAQ assumes you're using IDE 2.2.2 or above. If you're using an older version, you can ignore the paths mentioned above and instead add your own snippets into [your GMS2 installation folder]\TextEditor\snippets.txt, but be aware these changes will be lost when you update/reinstall GMS2, so we would recommend updating to 2.2.2.


Once the file is created in the User directory, you can edit it with any text editor following these rules:

  • Each snippet has to be on a separate line (there should be no blank lines)

  • Each snippet must start with the hotkey to be used followed by "-" and then the name of the snippet (which is what is shown in the menu) followed by a colon ":", eg:
    I - Instance Create:
    After the colon you add the snippet of code:
    I - Instance Create:instance_create_layer(x, y, |layer|, object);
  • Snippets can't have modifiers in their keybinding as the binding is always the first letter specified eg CTRL+1 will set the binding to be C
  • Custom Code Snippets with the same keybinding as a base code snippet will override the base code snippet when the keybinding is used.

The code that you add must also follow a specific format where:

  • All code is on a single line

  • You use "$" for a newline

  • You put the text that needs to be selected first between "|" symbols (the cursor will select this text for editing when the snippet is added)

See the examples that are already in the base snippets file to see how it is set up following the rules above. You can find the base file in the GameMaker Studio 2 install directory:

\GameMaker Studio 2\TextEditor\snippets.txt



Have more questions? Submit a request


Article is closed for comments.