有没有办法在 sublime 中自动保存每次击键? [英] Is there a way to autosave on each keystroke in sublime?

查看:18
本文介绍了有没有办法在 sublime 中自动保存每次击键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 sublime 在每次击键时保存我的文件,以便实时重新加载.

I would like sublime to save my file on each key stroke, for live reload purposes.

最简洁的操作是在每次击键时自动保存,前提是文件具有有效的语法.

The neatest action would be to autosave on each keystroke, only if the file has valid syntax.

如果 compass 任务足够快,那就像直接在 chrome 检查器中工作一样.

If compass task was fast enough it would be like working directly in chrome inspector.

推荐答案

您可以编写一个插件,使用 on_modified 监听器保存文件.像下面这样的东西可能会起作用(注意未经测试)

You could write a plugin that saves the file using the on_modified listener. Something like the following may work (note untested)

import sublime_plugin

class SaveOnModifiedListener(sublime_plugin.EventListener):
    def on_modified(self, view):
        view.run_command("save")

如果你有一个 linter,你可以验证它,并且只保存干净的 lints.请注意,根据我发布的内容,对 sublime 中任何文件的任何编辑都将在每次击键时保存.您可能需要添加一些额外的检查,例如文件类型、磁盘上是否存在等等.

If you have a linter, you could validate it, and only save on clean lints. Note that with what I have posted, any edit to any file in sublime will be saved on each keystroke. You may want to add some additional checks for things like file type, if it exist on disk, etc.

这篇关于有没有办法在 sublime 中自动保存每次击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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