CLion 2018.2 Help

Scratches

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

Scratch files
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
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 CLion suggests. CLion 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. Start typing New Scratch Buffer:
    cl new scratch buffer
    CLion creates a temporary editor tab with the name buffer1. In the future, the default names will be buffer<number>.
  2. Type the desired code.

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:
    cl scratch files location
  • To sort scratch files by types, click artwork studio icons logcat toolbar settings or right-click the Project tab and select Sort by Type:
    cl sort by type
    CLion sorts scratches alphabetically based on their extensions.

Close scratches

Delete scratches

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

Change the language of a scratch file

  1. In the Project tool window, click Scratches under Scratches and Consoles, and choose Change Language (<current language>) on the context menu of the scratch file to change the language for.
  2. 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 Change Language action keeps extension in sync, if it exists.

Rename, copy and move scratches

To rename a scratch

  1. In the Project tool window, click Scratches under Scratches and Consoles,select the file to rename, and press Shift+F6.
  2. In the dialog that opens, type the new name.

To copy a scratch

  1. In the Project tool window, in the Scratches and Consoles | Scratches directory, select the scratch file to copy.
  2. Press F5. CLion shows the appropriate dialog:
    cl 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:

    cl copy scratch buffer

To move a scratch

  1. In the Project tool window, in the Scratches and Consoles | Scratches directory, select the scratch file to move.
  2. Press F6 and select the target folder in the dialog that opens.

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 CLion home, in the config/scratches directory (on Windows/*NIX)
    • ~/Library/Preferences/<CLion>XX/scratches (on macOS)
  • You can undo or redo changes in scratches.
Last modified: 16 June 2018

See Also

External Links: