13

When I delete a file that I don't need anymore, but then I have to close the tab manually. It is irritating.

Every time, I have to delete the file and then close the tab by confirming the discard changes.

Is there a way to delete the file in one shot.

Please Note: This happens in my MacBook laptop.

1
  • 2
    I think of it as a safety net...
    – Marty
    May 5, 2014 at 5:11

6 Answers 6

13

If you use the Side​Bar​Enhancements plugin, there is an option for that:

{
    "close_affected_buffers_when_deleting_even_if_dirty": true
}

Make sure to add this to the correct settings file:

Preferences >> Package Settings >> Side Bar

2
5

I am not 100% clear on the details of your question. Apologies if this answer does not match what you are trying to ask.

Assuming you do not already have the file open this behaviour is a side effect of the choice to preview the file on click.

If this is the use case you are asking about then there is an answer.

If you look in Preferences -> Settings - Default and search for preview you should find this:

// Preview file contents when clicking on a file in the side bar. Double
// clicking or editing the preview will open the file and assign it a tab.
"preview_on_click": true,

This means clicking on the file to delete it causes it to be opened for preview and after deleting the file you also need to close the preview tab.

If you wish to change this behaviour open this file Preferences -> Settings - User and add this line:

"preview_on_click": false,

Then you should not open a preview and therefore will not need to close it after deleting the file.

If you already have the file you are deleting open for editing this will not cause the behaviour you are looking for.

1
  • Hi Duncan, Thanks for the response. Your solution almost solved my problem. I am happy with the solution. However, I would like to have both "preview_on_click" and "deleted file going away from the tab".
    – Vijey
    May 6, 2014 at 7:15
3

There is an issue, so in order to don't make a link-only answer, I just paste here the main info :

Sublime Forum Question : Close tab after delete file?

Sublime Forum : https://www.sublimetext.com/forum/viewtopic.php?f=2&t=11686

Sublime Forum Answer :

You can do this with a plugin. I didn't really test this much, so you may want to test on non critical stuff first. It does just close the view, so worst case is that you lose some existing work. That being said, I'm pretty sure it works fine.

import sublime_plugin
import os
class MyEvents(sublime_plugin.EventListener):
    def on_activated(self, view):
        if view.file_name():
            if not os.path.exists(view.file_name()):
                view.set_scratch(True)
                view.window().run_command("close")
1
  • +1 for the idea. Would like to see better inbuilt solutions.
    – Vijey
    May 5, 2014 at 12:22
3

There's a plugin for this:

Plugin's Github Page

Seems like it should be a toggleable option.

2
  • Thanks Isaac for the idea.
    – Vijey
    Apr 30, 2015 at 7:30
  • no problem... I've just installed it (on Sublime Text 3) and it works great. Certainly much better than the default delete behavior. Apr 30, 2015 at 7:50
3

This was annoying me so much, I created a plugin for it

https://gist.github.com/michaelkonecny/bb5a0d1cf43698c0ebe8673f92324ea3

Just download the close_deleted_files.py file and save it to %AppData%\Roaming\Sublime Text 3\Packages\User (or similar path on Mac).

This is how the plugin works: whenever a view is focused, it goes through the filenames of all the tabs in that window and closes those, whose files do not exist.

1

Extending @jwpfox answer

Below works for me:

Go to -> Top Menu -> Sublime -> Preferences -> Settings

Here Primary Preferences.sublime-settings file is not editable when you click on settings, so two pages will open, now add the flag on the second page like below .. it will override the primary setting.

Alternatively, you can add the flag in below location file as well directly :

Packages/User/Preferences.sublime-settings

Add flag as

"preview_on_click": false,

The entire file looks like the below:

{
    "ignored_packages":
    [
        "Vintage",
    ],
    "preview_on_click": false,
}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.