答案1
是的,您可以编写一个插件将视图设置为临时视图并关闭它。然后为该命令创建一个键绑定。选择工具 > 开发者 > 新插件...并粘贴:
import sublime_plugin
class CloseWithoutSavingCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
view.set_scratch(True)
view.close()
然后创建一个键绑定来覆盖 ctrl+w
{
"keys": ["ctrl+w"],
"command": "close_without_saving",
},
PS. 正如 @Dreamcat4 在评论中提到的那样,将此键绑定限制到临时缓冲区可能也是相关的。在这种情况下,您可以轻松创建一个上下文侦听器,它仅启用该文件类型的键绑定:
import operator as opi
import sublime
import sublime_plugin
class CloseWithoutSavingCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
view.set_scratch(True)
view.close()
class IsRealFileListener(sublime_plugin.EventListener):
def on_query_context(self, view, key, operator, operand, match_all):
# only act with the correct context key
if key != 'user.is_real_file':
return
if operator == sublime.OP_EQUAL:
op = opi.eq
elif operator == sublime.OP_NOT_EQUAL:
op = opi.ne
else:
# operator not supported
return
# assumption: a real file is a buffer, which has a filename as target
is_real_file = bool(view.file_name())
return op(is_real_file, operand)
创建一个键绑定来覆盖 ctrl+w,但仅限于上下文
{
"keys": ["ctrl+w"],
"command": "close_without_saving",
"context": [
{ "key": "user.is_real_file", "operator": "equal", "operand": false }
],
},
答案2
我也使用 Sublime 作为临时记事本。
对于试图忽略的 Macos 用户 此对话框我发誓这些年来情况越来越糟
Esc
点击“取消”Enter
点击“保存”N
应该“不要保存”,但事实并非如此- 箭头键也不起作用
经过很长时间的思考之后,我现在要做的事情是这样的。
- 全选
⌘A
- 删除
⌫
- 关闭标签
⌘W