Sublime Text 提示保存文件 [英] Sublime Text Prompt to Save File

查看:110
本文介绍了Sublime Text 提示保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 ST 中有一个便笺簿,然后我通过 Ctrl-F4 关闭它.它总是提示我保存它,我觉得这很痛苦.

I often will have a scratch pad in ST that I then close via Ctrl-F4. It always prompts me to save it, which I find to be a pain.

ST 中是否有设置,我可以将此对话框的默认设置更改为关闭而不保存",或者如果它是一个新文件(即没有名称),甚至根本不提示我.

Is there a setting in ST where I can either change to default of this dialog to "Close without saving", or do not even prompt me at all if it is a new file (i.e. has no name).

推荐答案

您可以将选项卡设置为暂存缓冲区(关闭时不提示保存).打开所需的选项卡后,使用 Ctrl` 打开控制台并键入:

You can set a tab to be a scratch buffer (doesn't prompt to save when closed). With the desired tab opened, open the console with Ctrl` and type:

view.set_scratch(True)

然后按Enter,然后用Esc 关闭控制台.您现在可以随时关闭选项卡,而不会收到提示.当然,您也可以根据需要手动保存内容.

then hit Enter, and close the console with Esc. You can now close the tab whenever you want without being prompted. Of course, you can manually save the contents if you wish.

如果您希望将所有新缓冲区默认设置为暂存,您需要一个插件.在 Sublime 中创建一个新的 Python 文件,内容如下:

If you would like to have all new buffers set to scratch by default, you'll need a plugin. Create a new Python file in Sublime with the following contents:

import sublime
import sublime_plugin


class SetNewScratchBuffer(sublime_plugin.EventListener):
    def on_new(self, view):
        view.set_scratch(True)

    def on_save(self, view):
        view.set_scratch(False)

将文件另存为 Packages/User/set_new_scratch_buffer.py 其中 Packages 是选择 Preferences -> 时打开的文件夹;浏览包...(~/.config/sublime-text-2/Packages 在带有 ST2 的 Linux 上).保存后,它应该会自动变为活动状态,但您可以重新启动 Sublime 以确保.现在,所有使用 CtrlNFile -> 创建的新缓冲区新文件 将自动设置scratch 属性.这将在保存文件时禁用,因此您不会意外破坏对打开文件的更改.

Save the file as Packages/User/set_new_scratch_buffer.py where Packages is the folder opened when selecting Preferences -> Browse Packages... (~/.config/sublime-text-2/Packages on Linux with ST2). Once saved, it should automatically become active, although you can restart Sublime to make sure. Now, all new buffers created with CtrlN or File -> New File will automatically have the scratch attribute set. This will be disabled when the file is saved, so you don't accidentally destroy changes to an opened file.

这篇关于Sublime Text 提示保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆