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 are fully functional, runnable, and debuggable 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 stored in the IDE configuration directory under scratches.
Create scratch files
Do one of the following:
Press Ctrl+Alt+Shift+Insert.
Press Ctrl+Shift+A, start typing
scratch file
and 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 and Consoles directory of the Project tool window.
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 Ctrl+Shift+A and run the New Scratch Buffer action.
View the available scratches
To see the list of created scratch files and buffers, open the Project tool window and select :
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 Project tab and select Sort by Type: WebStorm sorts scratches alphabetically based on their extensions:
View documentation for scratches
Select any scratch file or buffer and press Ctrl+Q to view quick documentation with the location, type, size, creation and modification date of the file.
Rename scratches
In the Project tool window, click Scratches under Scratches and Consoles, select the file to rename, and press Shift+F6.
In the dialog that opens, type the new name. Note that specifying another extension does not affect the file type, use the Change Language action for that.
See Renaming files and folders for details.
Copy scratches
In the Project tool window, in the directory, select the scratch file to copy.
Press F5. In the dialog that opens, type the new filename. Here you can also specify another extension to change the file type. If necessary, select the folder where you want to save the copy.
See Copying files and folders for details.
Move scratches
In the Project tool window, in the directory, select the scratch file to move.
Press F6 and select the target folder in the dialog that opens.
See Moving files and folders for details.
Change the language of scratches
In the Project tool window, click Scratches under Scratches and Consoles, and choose from the context menu of the scratch file to change the language for.
Select the desired language. Note the following:
Four last used items are on top of the list, above the separator.
To narrow down the list, start typing the language name.
The
action keeps extension in sync, if it exists.
You can assign a shortcut to the Change Language action as described in Configuring keyboard shortcuts.
Run and debug scratches
Install the required packages and add the corresponding import statements to the scratch file. For example, to use JQuery:
Open package.json and add the following packages to the
dependencies
property:"dependencies": { "jquery": "^3.5.0", "jsdom": "^16.2.2", "core-js": "^3.6.5", "nuxt": "^2.14.5" }From the context menu of package.json, select Run 'npm install'.
Open your scratch file and add the following import statements:
const {JSDOM} = require("jsdom"); const {window} = new JSDOM(""); const $ = require('jquery')(window);
From the context menu of the scratch file, select Run <scratch_file_name>.
To debug a scratch file, set the breakpoints as required and select Debug <scratch_file_name> from its context menu..
Run an SQL scratch file
To run an SQL scratch file, you need to have a connection to a data source. In WebStorm, 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 WebStorm 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.
Right-click any area in the open scratch file and click Execute. In the Sessions window, select a query console.