Does anyone know how to make SublimeText2 save on every keypress? I use LiveReload for web dev and would love to have it refresh without having to hit cmd+s.
Auto Save on Every Keypress
Wouldnât that be really annoying?
What happens when your in the middle of writing an HTML tag, or havenât closed a CSS bracketâŚyou would get some bad results.
Cmd-S is really easy to press.
I donât think it would be annoying. Maybe it could be configured to wait x milliseconds for another key before triggering the save. So that it saves on idle like WebStorm does, but without the minimum time limit of 1 second like it has.
Something like this might work for you. Save it into a file (e.g. AutoSave.py) and drop it into /Sublime Text 2/Packages/User folder.
import sublime, sublime_plugin
class AutoSaveCommand(sublime_plugin.EventListener):
def on_modified(self, view):
view.run_command('save')
NOTE: it will save on every modification. To add the âwait x msâ functionality you will have to add a new thread; waiting in the event handler is NOT a good idea.
This is very memory intensive work though? I really donât see this being any good for anybody?
Just a quick example
[code]import sublime, sublime_plugin
class AutoSaveCommand(sublime_plugin.EventListener):
clicks = 0
clicksTrigger = 10
def on_modified(self, view):
self.clicks += 1
if self.clicks <= self.clicksTrigger:
self.clicks = 0
view.run_command(âsaveâ)[/code]
Anybody got this to work?
Or have other solutions for an alternative to CTRL + S -> Livereload scenario?
Best regards,
Kristian Thrane
You can use the following setup:
"save_on_focus_lost": true,
Switching to the browser will save and reload.
If you use a side by side view this will not help I know.
Thanks - but yeah - I am looking for a solution that either fires the save-event every 10 keystrokes or every 3rd second-ish
[quote=âKonTraxâ]
Just a quick example
[code]import sublime, sublime_plugin
class AutoSaveCommand(sublime_plugin.EventListener):
clicks = 0
clicksTrigger = 10
def on_modified(self, view):
self.clicks += 1
if self.clicks <= self.clicksTrigger:
self.clicks = 0
view.run_command(âsaveâ)[/code][/quote]
When I changed the â<=â to â>=â things worked properly for me.
if self.clicks >= self.clicksTrigger:
[code]import sublime, sublime_plugin
class AutoSaveCommand(sublime_plugin.EventListener):
clicks = 0
clicksTrigger = 10
def on_modified(self, view):
self.clicks += 1
if self.clicks >= self.clicksTrigger:
self.clicks = 0
view.run_command(âsaveâ)[/code]
Hi guys!
What do you think about saving by pressing Enter or moving up/down by arrows? I saw that solution in Aptana or similar software as far as I remember.
Can you write that code for me, please? I donât know Python.
Thanks a lot!
As someone pointed out earlier, if the purpose is for realtime updates through LiveReload, constant reloading of the browser while coding is going to result in a FUBRâd output in the browser 80%+ of the time. Even an event listener on return will cause the browser to display all sorts of ridiculousness if a ruleset hasnât been closed yet, or an element tag is open while coding. For viewing minor changes realtime, I suggest using the developer tools that are included with Chrome, Safari, or Firefox.
Also keep in mind that even on localhost, any scripts (particularly javascript) not correctly set to load after the DOM could realistically cause the page to never load at all while coding, even if set on a time delay (such as every 3 seconds). Probably one of my primary concerns personally would be the fact that I am constantly referring back and forth to a portion of the code in the browserâs developer tools while making changes in Sublime Text during a debug process or when fine tuning the frontend. If the browser is constantly refreshing, the whole reasoning behind using developer tools in conjunction with your IDE is moot.
I use auto-save for auto-saving and live-server for live reloading. but autosave wonât work when Iâm inside of an HTML attribute like class. I have to press space and then hit back to remove that space, and then the auto-complete triggers when I press space. is there any way to solve this problem?