Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

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")

There's a plugin for this:

Plugin's Github Page

Seems like it should be a toggleable option.

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top