Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text: File remains in tab even after deleted

Tags:

sublimetext3

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.

like image 700
Vijey Avatar asked May 05 '14 05:05

Vijey


5 Answers

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

like image 75
Benoit Blanchon Avatar answered Oct 18 '22 15:10

Benoit Blanchon


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.

like image 30
Michael Konečný Avatar answered Sep 21 '22 13:09

Michael Konečný


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.

like image 4
jwpfox Avatar answered Oct 18 '22 17:10

jwpfox


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")
like image 3
BENARD Patrick Avatar answered Oct 18 '22 16:10

BENARD Patrick


There's a plugin for this:

Plugin's Github Page

Seems like it should be a toggleable option.

like image 3
Isaac Gregson Avatar answered Oct 18 '22 15:10

Isaac Gregson