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 are fully functional files, which support syntax highlighting, code completion, and all other features for the corresponding file type. 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. 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 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.
Scratch files and buffers are displayed in the Scratches view of the Explorer window.
You can run a C# scratch file or any of its parts using C# Interactive.
To run a C# scratch file
Select the desired part of the code in the scratch file. You can successively extend selection with Ctrl+Alt+Right or select the whole file contents with Ctrl+A.
Choose Send Selection to C# Interactive in the action list.
JetBrains Rider will start a new interactive session in a new tab of the Run Tool 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 file
Do one of the following:
Press Ctrl+Shift+A, start typing
scratch fileand then pick the corresponding action.
Select the language of the scratch file. Scratch files of the same type are automatically numbered and added to the Scratches view of the Project tool window .
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.
Also, you can create a shortcut for the New Scratch Buffer action as described in Configuring 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 that limit is reached, it will recreate buffer1.txt and suggest to clear the content for it. If you want to make sure that a scratch buffer is not cleared after you have five, you can rename it.
View documentation for scratches
Select any scratch file or buffer and press Ctrl+Shift+F1 to view quick documentation with the location, type, size, creation and modification date of the file.
Run an SQL scratch file
To run an SQL scratch file, you need to have a connection to a data source. In JetBrains Rider, you need to attach a scratch file to the query console.
When you attached the console, the objects in your SQL are resolved. This means that JetBrains Rider now understands which particular objects are used in your 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 Sessions window, select a query console.
Click the <session> switcher, which is in the upper right 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 (<current_dialect>).
Right-click any area in the open scratch file and click Execute. In the Sessions window, select a query console.
Like any other file, you can perform the following operations with scratch files and buffers:
Use Local History, undo, and redo changes
Perform clipboard operations