Sublime Forum

How to disable "Do you want to save the changes you made to New file?"

#1

Hello,

I open a lot of temporary tabs while I’m working. At the end of the day when I go to clean up, I want to close most of these tabs. However I find it very tedious to have to answer this same question over and over again.

Ideally I could just press a hotkey such as alt+D so I don’t have to click my mouse, but it seems like only way to answer the prompt is with mouse click =-/

Is there any way to disable this warning? Thank you

0 Likes

#2

The trick is to mark a view as “scratch” before closing.

I wouldn’t recommend to close view’s with unsaved content automatically without prompting as this is likely to cause accidental data loss.

The safest solution is probably to create dedicated views for note taking, which are not intended to be saved later.

If really required a plugin can also provide a command to suppress promt and directly close files.

Default.sublime-commands

[
	{ "caption": "File: New Scratch", "command": "new_scratch" },
	{ "caption": "File: Close Without Saving", "command": "close_without_saving" },
]

Packages/User/file_management.py

import sublime_plugin


class NewScratchCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.new_file()
        if view:
            view.set_scratch(True)


class CloseWithoutSavingCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()
        if view:
            view.set_scratch(True)
            view.close()
            return
        sheet = self.window.active_sheet()
        if sheet:
            sheet.close()
0 Likes

#3

The general UI for GUI applications (not just Sublime) is that there is a default accelerator key for pressing buttons in dialogs. In Sublime (on Windows), that would be Alt+Y for Yes and Alt+N for No (see the underlined letter in the button key; that’s the mnemonic, just like in a menu).

The same applies to Linux, and probably MacOS too (though I don’t use MacOS so I don’t know if it works quite the same way or not).

0 Likes

#4

Hello thank you for your replies.
I am using MacOS and I don’t think there is an accelerator. Command - D which works in other applications doesn’t work for Sublime, neither does Tab / enter keys.

I will try to figure out how to set up a “scratch” view. Thank you

0 Likes

#5

⌘D to select “Don’t Save” in the unsaved changes dialog does work in ST in macOS. I use it all the time.

0 Likes

#6

See here for keyboard shortcuts in macOS dialogs: https://superuser.com/questions/24159/osx-keyboard-shortcuts-in-dialogs

0 Likes

#7

Thank you so much bschaaf! Mac changed the hotkey from cmd +d to cmd +delete.

Thank you deathaxe too for the plugin suggestion. I’m going to try it out

1 Like