1

In Sublime Text 3 if I go to:

MENU: File>Open Recent

There are files in that list which are no longer available.

How can I clean that list of dead files?

I don't want to clear the full list, just the dead ones.


Note: I've followed How to increase number of recent files in Sublime Text 3? to get 30 recent files showing in this menu.

Ste
  • 1,729
  • 1
  • 17
  • 27
  • Currently you can only clear all `Recent projects` or `Recent files`. There is no option to remove one by one. – Dinko Pehar May 23 '19 at 08:07
  • Thanks for the info, I'm pretty sure the only way is to write a custom plug-in to keep track of recent files and then clear the old links. – Ste May 23 '19 at 19:50

2 Answers2

2

Following this post over on the Sublime Forum it can be done by editing the Session.sublime_session file.

For example: I'd edited etc/hosts so I could block myself from watching youtube, but with it being in the recent files list in Sublime it's easy to unblock myself thus I wanted to remove /etc/hosts from my recent file list in Sublime (ST3).

My copy of Sessions.sublime_session is in ~/.config/sublime-text-3/Local/ from which I deleted all lines containing etc/hosts.

The only caveat is that you can't edit that file using Sublime, Sublime should not be running, I used a different text editor.

Final caveat this is the solution for linux, and ST3, for windows and mac I'm guessing there's something similar.

Lozminda
  • 45
  • 8
  • Sorry I found a more automatic alternative than this. I shall post the answer now. – Ste Jul 04 '22 at 19:52
0

I found out how to do this using this python script here:

https://github.com/STealthy-and-haSTy/SublimeScraps/tree/master/session_cleaner

I don't want to post the python code as I don't have permission to do so but that has been up on GitHub for a couple of years so there should be no worries of it disappearing anytime soon.

I've written a batch file that will start the python file, see the code below. Just name it RunSessionCleaner.cmd and place this in the same folder as the sublime_session_clean.py file.

@echo off & title %~nx0 & color 5F & chcp 65001 >NUL
rem Based on this thread here: https://stackoverflow.com/a/13351373
goto :MY_ROUTINE
:CMD_SIZE
chcp 850 >NUL & set "uiWidth=%1" & set "uiHeight=%2"
mode %uiWidth%,%uiHeight%
if %4==TRUE (set /a "uiHeightBuffer=uiHeight+%3")
if %4==TRUE (powershell.exe -ExecutionPolicy Bypass -Command ^
  "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeightBuffer%;$W.buffersize=$B}")
if %4==FALSE (powershell.exe -ExecutionPolicy Bypass -Command ^
  "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%uiWidth%;$B.height=%uiHeight%;$W.buffersize=$B}")
chcp 65001 >NUL & goto :EOF
:MY_ROUTINE
call :CMD_SIZE 60 7 222 TRUE
title Cleaning folders, files and projects...
echo Cleaning folders, files and projects...
:: Full path to data folder        W:\Apps (Portable)\Sublime Text\Data
:: Full path to python.exe         W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\python\python.exe
:: Full path to sublime_session_clean.py  W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner\sublime_session_clean.py
:: Or like I have done use a relative directory to the Data folder
:: The SsssionClearner.py file is located in: W:\Apps (Portable)\Sublime Text\Data\Packages\User\SessionCleaner
::
:: Change this line below to suit your needs.
".\python\python.exe" "sublime_session_clean.py" --data-dir "..\..\..\..\Data" --workspaces --files --folders
echo/
goto :EXIT_ROUTINE
:EXIT_ROUTINE
rem call :CMD_SIZE 100 10 222 FALSE
title Exiting routine...
echo Exiting routine...
set /p "=" <NUL &
ping localhost -n 3 >NUL & exit
exit

Change line 24 of the code above to suit your paths. You can just use relative paths here like I have done so you can do that too.

This batch file can be clicked on or set up in Task Scheduler to start up when the PC does to clean out all the non-existent files or workspaces.

Please note, Sublime Text needs to be closed in order for this to work.

Ste
  • 1,729
  • 1
  • 17
  • 27