IntelliJ IDEA 2018.1 Help

Scratches

IntelliJ IDEA provides a temporary editor. You can create a text or a piece of code for search or exploration purposes. IntelliJ IDEA suggests two types of temporary files:

Scratch files
The scratch files are fully functional, runnable, debuggable, etc. They require a language to be specified and have an extension. The scratch files are created via Ctrl+Shift+Alt+Insert.
Scratch buffers
The scratch buffers are only intended for pure editing, and as such they do not require specifying a language and do not have an extension. The scratch buffers belong to .txt type by default.

This action has no dedicated shortcut, but you can configure one as described in the section Configuring Keyboard Shortcuts.

Buffer files are reused after creating 5 files. After reuse, the content and language are reset.

Create scratch files

  1. Do one of the following:
    • On the main menu, choose File | New | Scratch File.
    • Press Ctrl+Shift+Alt+Insert.
    • Right-click anywhere in the Project Tool Window and choose New | New Scratch File from the context menu.
    • Press Ctrl+Shift+A, start typing scratch file.., and choose the corresponding action.
  2. Select the language of the future scratch from the list that IntelliJ IDEA suggests. IntelliJ IDEA creates a temporary editor tab with the name scratch.<extension>. In the future, the default names will be scratch_<number>.<extension>. The scratch file is added to the Scratches and Consoles directory located in the Project tool window.
  3. Type the desired code.

Create scratch buffers

  1. Press Ctrl+Shift+A or search everywhere.
  2. Start typing New Scratch Buffer:
    new scratch buffer

    IntelliJ IDEA creates a temporary editor tab with the name buffer1. In the future, the default names will be buffer<number>.

  3. Type the desired code.

Note that though this action has no keyboard shortcut, you can still configure one as described in Configuring Keyboard Shortcuts. You can also switch from scratch files to scratch buffers by reassigning the shortcut to avoid garbage buildup.

Observe the available scratches

  • To see the list of created scratch files and buffers, open the Project tool window and select Scratches and Consoles | Scratches:

    scratch files location
  • To sort scratch files by types, right-click the Project tab and select Sort by Type:

    sort by type
    IntelliJ IDEA sorts scratch files alphabetically based on their extensions.

Close scratches

Click icons actions close on the editor tab. Refer to the section Manage editor tabs for details.

Delete scratches

In the Project tool window, in the Scratches and Consoles | Scratches directory, right-click the scratch file or a buffer you want to delete and from the context menu choose Delete.

Change the language of a scratch

If you want to change the scratch's language when a scratch is already created, you can do so with the aid of the editor's context menu.

  1. In the Project Tool Window, in the Scratches and Consoles | Scratches, right-click the scratch file for which you want to change the language.
  2. From the context menu, select Change Language (<current language>).
  3. Select the desired language.

    Note the following:

    • Four latest items appear on top of the list before a separator.
    • You can narrow down the list by typing the language name.
    • You can assign a shortcut to this action as described in Configuring keyboard shortcuts.
    • Change Language action keeps extension in sync, if it exists.

Rename, copy and move scratches

IntelliJ IDEA makes it possible to perform rename refactoring of the scratches.

  1. In the Project Tool Window, in the Scratches and Consoles | Scratches directory, select the scratch file to be renamed.
  2. Press Shift+F6.

Copy and Move file actions are available the same way. Refer to the sections Move and Copy for details.

Note that when you copy a scratch, IntelliJ IDEA includes the respective extension that corresponds to the file type:

  1. In the Project Tool Window, in the Scratches and Consoles | Scratches directory select the scratch file to be copied.
  2. Press F5. IntelliJ IDEA shows the appropriate dialog:
    copy scratch

    This dialog box shows the scratch name with the corresponding extension. Note that when you copy a scratch buffer, the extension is .txt:

    copy scratch buffer

Important notes about scratches

Note the following:

  • The scratch code in scripting languages is executable: you can run and debug it.
  • Local History for scratches is supported.
  • It is possible to perform clipboard operations with scratches.
  • The scratches are stored, depending on your operating system,
    • Under IntelliJ IDEA home, in the config/scratches directory (on Windows/*NIX)
    • ~/Library/Preferences/<IntelliJ IDEA>XX/scratches (on macOS)
  • You can undo or redo changes in scratches.
Last modified: 24 July 2018

See Also