Is there a way to autosave on each keystroke in sublime?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 15:22:17

问题


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.

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


回答1:


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.




回答2:


I had this very same need some time ago when I was trying to do some very fast feedback prototyping that required the file to be saved before I could analyze its output. However, this is not something I'd need in all my projects.

Luckily I found that there is an elegant plugin that does just what is needed - saves the given file after each and every modification - and does that with a simple addition! You can easily enable and disable the feature when it suits you with a simple key combination. Although it is but a small improvement over the other spot on answer, I hope it'll help someone out there.

The plugin in question is auto-save, and of course, it can be installed through Sublime Package Control.



来源:https://stackoverflow.com/questions/15277166/is-there-a-way-to-autosave-on-each-keystroke-in-sublime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!