Scratch files
Sometimes you may need to create temporary notes or draft up some code outside of the project context. Instead of switching to a different application for this purpose, you can use scratch files and scratch buffers.
Scratch files support syntax highlighting for the corresponding file type, and you can use them to draft any code instances, from Objective-C/Swift constructs to JSON documents. For example, while working on one project, you may come up with an idea for a method that you could later use in another project. You can create a scratch file with a draft of the method, which is not stored in your project directory but can be accessed and opened from another project.
Scratch buffers are simple text files without any coding assistance features. Scratch buffers can be used for simple task lists and notes to yourself. They are also not stored in the project directory but can be accessed and opened from another project. You can create up to five scratch buffers with default names, which are rotated and reused by clearing the content.
Create scratch files
Select the language of the scratch file. Scratch files of the same type are automatically numbered and added to the Scratches and Consoles directory of the Project tool window (in the Files view) .
Alternatively, you can create a new scratch file with the contents of the current selection in the editor. Select some text or code, press ⌥ ⏎ and then select Create new scratch file from selection. AppCode will attempt to detect the language of the selected fragment and use the appropriate type and extension. If it can't detect the language of the selection, AppCode will create the file with the same type and extension as the original file.
AppCode numbers scratch files sequentially starting from 1. If you close a tab with an empty scratch file, AppCode deletes it.
Create scratch buffers
There is no dedicated menu item for the action to create a new scratch buffer, but you can use the Find Action popup ⌃ ⇧ A and run the New Scratch Buffer action.
You can also create a shortcut for the New Scratch Buffer action as described in Configure keyboard shortcuts.
AppCode creates a text file named buffer1.txt. The next scratch buffer you create is named buffer2.txt, and so on up to buffer5.txt. When AppCode reaches that limit, it will recreate buffer1.txt and suggest clearing the content for it. If you want to make sure AppCode does not clear the scratch buffer after you have five, you can rename it.
View available scratch files and buffers
Open the Project tool window and expand .
The Scratches and Consoles directory is available when you select the Files view.
By default, scratch files and buffers are sorted alphabetically by their names and next by their extensions (types), which automatically means that buffer files always come first. To sort scratch files by types, click or right-click the Files tab and select Sort by Type.
Alternatively, you can use the Show Scratch Files action to open a separate popup with all available scratch files:
By default, AppCode stores scratch files and buffers in the IDE configuration directory under scratches. They are available from any IDE and project that uses this configuration directory.
- Syntax
~/Library/Application Support/JetBrains/<product><version>
- Example
~/Library/Application Support/JetBrains/AppCode2021.2
To change the location of the Scratches and Consoles directory, use the idea.scratch.path
platform property. To change the location of just the Scratches directory, use the idea.scratch.path/scratches
platform property. For more information, see Advanced configuration.
Productivity tips
Change the language of a scratch file or buffer
In the Project tool window, open the Files view, open the .
Right-click a scratch file or buffer and then click Change Language.
Select the desired language. You can start typing the name of the language to narrow down the list.
View documentation for scratches
Select any scratch file or buffer in the Project tool window and press ⌃ Q to view quick documentation with the location, type, size, creation and modification date of the file.
Move scratches
In the Project tool window, select the Files view and open the directory and select the scratch file to move.
Press F6 and select the target folder in the dialog that opens.
Run an SQL scratch file
To run an SQL scratch file, you need to have a connection to a data source. For this, attach a scratch file to the query console.
When you attach the console, AppCode resolves the objects in your SQL code. As a result, you can navigate from the SQL code to the database tree.
Press ⌃ ⏎ or click in the gutter. In the Sessions window, select a query console.
Click the <session on> switcher in the upper right corner of the window and select a console. The switcher menu includes consoles that are associated with the same language as your scratch file.
If you want to attach a console from another DBMS, change the scratch file language. To change a language, right-click any area in the open scratch file and click Change Language.
Right-click any area in the open scratch file and click Execute. In the Sessions window, select a query console.