Sublime Forum

No warning when deleting or renaming open files (also reloading from disk)

#1

Currently, when I delete a file from Windows Explorer, Sublime Text doesn’t warn me that the file no longer exists. Instead, it merely acts like the file is unsaved, highlighting the close button (and turning the tab orange if you have that enabled).

As a result, I frequently move, rename, or delete a file in Windows Explorer, but continue working on the file in Sublime. When I save, I recreate the original file, with no sign at all that something is wrong. The file I want to edit is unchanged, but I instead have two different files under both names.

Another problem with this current behavior is that when I move or rename a file, the orange title bar provides no indication of whether or not I saved before renaming the file, so I no longer know if I have unsaved changes or not.

Notepad++ handles this situation better by telling the user that the file is no longer there, then asking in a dialog whether or not to close it. One potential flaw is that a careless user may accidentally click the “close” button when not intending to (this happened to me once).

Sublime should provide indication when the file is not on the disk, AND whether the file has been saved or not. This can be done using title bar colors or dialog boxes (like Notepad++). Preferably a notice box, but allow the user to close the tab themselves if they wish.


A related issue is when a file is updated on the filesystem. Sublime silently reloads the file on the disk without clearly informing the user. I’m not sure about the best solution, whether a dialog box would be too intrusive or prone to user error (clicking the wrong button).

EDIT: Under Menu -> [Preferences] -> [Settings - User], change "always_prompt_for_file_reload": false

0 Likes

#2

re: the related issue, why not set the always_prompt_for_file_reload preference to true in your user preferences?

from the default Preferences.sublime-settings file:

// Always prompt before reloading a file, even if the file hasn't been
// modified. The default behavior is to automatically reload a file if it
// hasn't been edited. If a file has unsaved changes, a prompt will always
// be shown.
"always_prompt_for_file_reload": false,
0 Likes

#3

ok that fixed editing.

now about deleting/moving…

0 Likes

#4

I like the way it works.
It allows branch switching in GIT to instantly update the files in sublime (it they are clean).
I think that is the reason for the implementation.

1 Like

#5

I agree with you Adamarla

However, I do have an issue is when I switch branches, and opened files which exist in the original brach do not exist in the newly checked out branch. Then the Sublime UI displays the file, but with a “not saved” status. This can be a little disorienting.

IMO, the UI should have specific indication (in the tabs icon, and anywhere else…) That the file is only unsaved, or actually does not exist on disk.

Does anyone know if THIS is possible?

0 Likes

#6

ping on this. As I wrote in http://sublimetext.userecho.com/topics/597-update-tabs-after-renaming-file/#comment-4453

I’m using sublime text 3 (3126);

subl foo.c
mv foo.c bar.c

now the tab containing foo.c is marked as unsaved instead of having it’s file name updated

This is probably my most desired feature in sublime text. It’s implemented in many other editors as others have noted (can probably be implemented via cross-platform fswatch, or qkwait or a number of other libraries)

0 Likes

#7

fswatch should be usable to implement that feature in sublime text:

  • usable as a library in C or C++
  • allow only watching renames / deletions
  • allow monitoring individual files and following them as they are renamed
0 Likes

#8

This is my biggest pet peeve with Sublime.

Sublime detects that the file has been deleted or renamed, the problem is that it visually shows it as unsaved.

It’s really frustrating, because often I rename a file, and I waste time to figure out why the changes aren’t taking effect, because I’m editing the wrong file. And afterwards, it creates an extra file that I have to clean up. Even after using Sublime daily for over 5 years, it still trips me up at least once a week.

In Sublime when a file is deleted, the title is “filename •”
In VSCode when a file is deleted, the title is “filename (deleted from disk)”

It should be fairly easy to implement (a few lines of code), because Sublime already detects that the file is missing, it just needs to add a condition to handle the title display.

For your reference, here’s the code of how VSCode handles it, which also detects read-only files:

0 Likes

#9

I was looking for a solution to the same problem.
I came across this (not my code):
https://github.com/russelldavis/sublime-detect-deleted-files

  • it closes tabs for which the file has been deleted (or renamed/moved away), or shows a warning (and not close) if there have been changes. It’s a bit rough around the edges, the dialog shows up multiple times, can probably be improved, but overall it seems like it’s on the right track.

To use it, create a folder with any name under under Data\Packages and place the .py file in that folder.

0 Likes