JetBrains Rider 2022.1 Help

Scratch files

Sometimes you may need to create temporary notes or draft up some code outside the project context. Instead of switching to a different application, you can use scratch files and scratch buffers.

  • Scratch files are fully functional files that support syntax highlighting, code completion, and all other features for the corresponding file type. For example, while working on one solution, you may come up with an idea for a method that you could later use in another solution. You can create a scratch file with a draft of the method, which is not stored in your solution directory but can be opened when you're working on any other solution. You can use scratch files to draft code constructs, HTTP requests, JSON documents, and so on.

  • 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 solution directory and can be opened from any other solution. You can create up to five scratch buffers with default names, which are rotated and reused by clearing the content.

Create a scratch file

  1. From the main menu, select File | New | Scratch File or press Ctrl+Alt+Shift+Insert.

  2. 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 Solution Explorer.

Alternatively, you can create a new scratch file with the contents of the current selection in the editor. Select some text or code, press Alt+Enter and then select Create new scratch file from selection. JetBrains Rider 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, JetBrains Rider will create the file with the same type and extension as the original file.

If you close a tab with an empty scratch file, JetBrains Rider deletes it.

You can run a C# scratch file or any of its parts using C# Interactive.

Run a C# scratch file

  1. Select the desired part of the code in the scratch file. You can successively extend selection with Ctrl+W or select the whole file contents with Ctrl+A.

  2. Press Alt+Enter.

  3. Choose Send Selection to C# Interactive in the action list.

  4. JetBrains Rider will start a new interactive session in a new tab of the Run window and send the selected code to this session. If a C# interactive session is already running, the selected code will be appended to this session.

Create a scratch buffer

  • There is no dedicated menu item for the action to create a new scratch buffer, but you can use the Find Action popup Ctrl+Shift+A and run the New Scratch Buffer action.

You can also add a shortcut for the New Scratch Buffer action as described in Customize keyboard shortcuts.

JetBrains Rider 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 JetBrains Rider reaches that limit, it will recreate buffer1.txt and suggest clearing the content for it. If you want to make sure JetBrains Rider does not clear the scratch buffer after you have five, you can rename it.

View all scratch files and buffers

  • Open the Solution Explorer and expand Scratches and Consoles | Scratches.

  • Use the Find Action popup Ctrl+Shift+A to invoke the Show Scratch Files action and view all available scratch files in a popup:

    The Scratch Files popup

Location of scratch files and buffers

By default, JetBrains Rider 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

%APPDATA%\JetBrains\<product><version>

Example

C:\Users\JohnS\AppData\Roaming\JetBrains\Rider2022.1

Syntax

~/Library/Application Support/JetBrains/<product><version>

Example

~/Library/Application Support/JetBrains/Rider2022.1

Syntax

~/.config/JetBrains/<product><version>

Example

~/.config/JetBrains/Rider2022.1

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.

Include a scratch file into your solution

If a scratch file grows into something that you want to use in your solution, move it into the desired directory of your solution structure.

  • Drag a scratch file from the Scratches and Consoles | Scratches directory in the Solution Explorer to the target directory in your solution.

  • Select a scratch file in the Scratches and Consoles | Scratches directory in the Solution Explorer and press Ctrl+X, then select the target directory in your solution and press Ctrl+V.

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, JetBrains Rider resolves the objects in your SQL code. As a result, you can navigate from the SQL code to the database tree.

  • Press Ctrl+Enter or click the Run button 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.

Last modified: 22 July 2022