41

In IntelliJ IDEA 14, we can create scratch files from Tools > New Scratch File...

Are they stored in some temporary files? If the answer is yes, where are they?

Attempts:

1) I pressed right click > Copy Reference and I pasted it:

1d0b26a2/scratch.2:1

2) I opened .idea\workspace.xml and I have the following part for scratch files:

  <file leaf-file-name="scratch.2" pinned="false" current-in-tab="true">
    <entry file="scratchpad://1d0b26a2/scratch.2">
      <provider selected="true" editor-type-id="text-editor">
        <state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="636">
          <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="20" />
          <folding />
        </state>
      </provider>
    </entry>
  </file>

For a normal file the entry path starts with file:// instead of scratchpad://.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 3
    I am also wondering why viewing scratch files is not possible in IDE. Once scratch file is closed (accidentally or automatically) there seems to be no way to reopen it. – ᄂ ᄀ Dec 09 '14 at 21:13
  • 4
    Opening accidentally closed scratch files can be easily done with Cmd-E, which shows the "Recent Files" popup. Closed scratch files show up there. – Rolf Jan 20 '15 at 11:53
  • for phpstorm on mac it is: `~/Library/Preferences/PhpStorm2018.2/scratches` – Blueblazer172 Aug 15 '18 at 11:31
  • @rolf you need to put this as the answer cause this is the perfect solution for this. Despite this being 7 years ago! – Christopher Thomas May 13 '22 at 13:31
  • Thanks for the tip Christopher, I added it as an answer. Cheers! – Rolf Jun 10 '22 at 08:45

7 Answers7

35

Starting with 14.1, Scratch Files are stored under .IntellijIdea14/config/scratches.

They are displayed either in Scratches and Consoles or on the Scratches tab (depends on the version you are using).

Current UI:

Scratches and Consoles

Earlier UI:

Scratches tab

IntelliJ IDEA Help - Scratch files

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
14

I upgraded my IntelliJ IDEA to 14.1 and I found the scratch files.

If you create a scratch file, its path can be found in many different ways:

  1. On the title bar

  2. Right click on the tab > Copy Reference

    enter image description here

    You can paste it anywhere and it will look like:

    C:/Users/username/.IntelliJIdea14/config/scratches/scratch

  3. Right click on the tab > Rename File...

  4. Right click on the tab > Local History > Show History

  5. In .idea\workspace.xml it looks like:

    <file leaf-file-name="scratch" pinned="false" current-in-tab="false">
      <entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch">
        <provider selected="true" editor-type-id="text-editor">
          <state vertical-scroll-proportion="0.0">
            <caret line="4" column="17" selection-start-line="4" selection-start-column="17" selection-end-line="4" selection-end-column="17" />
            <folding />
          </state>
        </provider>
      </entry>
    </file>
    
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
3

You can switch to project view and you'll be able to see them under "Scratches and consoles"


WebStorm project view

Yidir
  • 583
  • 7
  • 12
3

enter image description here

~/Library/Application\ Support/JetBrains/IntelliJIdea2020.1

for macOS this is the location of both

  • database consoles (all the neat little db helper scripts)
  • scratch files (stored as plain files, a scratch you created in your idea app under the name scratch.py you will find in this directory as scratch.py)

To migrate your scratches, you just need to copy over these directories to your new environment under the above mentioned path.

However, please mind that this works for IntelliJ version 2020.1 on macOS. I'm not 100% sure where earlier versions used to store scratches and on other operating systems.

Husterknupp
  • 977
  • 9
  • 16
1

Here's another solution if you can't find your scratch files in the Scratches tab as @fnt suggested (which normally is the most convenient way probably).

In my case, I've recently updated my editor from PhpStorm 2018.1 to PhpStorm 2018.2. The scratch files are saved along with all preferences in a path specific to each version of your editor. In case of MacOS it's ~/Library/Preferences/PhpStorm2018.2.

This means that when you update your IDE, it starts using the new path and it doesn't see your old scratches anymore. If you still need to open them, simply navigate to path specific for your OS and all you're scratches are there.

All paths, are listed in official docs.

Najki
  • 514
  • 6
  • 22
1

Opening accidentally closed scratch files can be easily done with Cmd-E, which shows the "Recent Files" popup. Closed scratch files show up there.

Rolf
  • 7,098
  • 5
  • 38
  • 55
0

@rolf wrote this comment and I want to promote it as the answer here cause it's not already written. But the best way is to

Opening accidentally closed scratch files can be easily done with Cmd-E, which shows the "Recent Files" popup. Closed scratch files show up there. – Rolf

Thanks rolf!

Christopher Thomas
  • 4,424
  • 4
  • 34
  • 49
  • The question is not about _closed_ scratch files but scratch files in general. – ᄂ ᄀ May 20 '22 at 15:52
  • I know what you mean, the answer doesn't give the location on the disk of the cached remnants. But it's still a good answer if you need to recover a scratch file and you're trying to find the file on disk because you want to recover it. – Christopher Thomas May 22 '22 at 09:20
  • That's why the original comment wasn't posted as an answer. – ᄂ ᄀ May 25 '22 at 14:37