问题描述
我想在每次击键时升华以保存文件,以进行实时重新加载.
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.
如果指南针任务足够快,就好比直接在chrome inspector中工作.
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")
如果您有皮棉,则可以对其进行验证,并且仅保存在干净的皮棉上.请注意,按照我发布的内容,对每个文件的任何修改都将保存在每次击键中.您可能需要添加一些其他检查,例如文件类型,磁盘上是否存在文件类型等.
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.
这篇关于有没有一种方法可以自动保存每一个击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!