Sublime Forum

Ways of persisting data


What are some ways in which I can persist some data entered by me and I can have access to it after quitting Sublime Text ?



Presuming that you mean you want your plugin to be able to save data somewhere and have it still be available in a future run of Sublime (i.e. it persists over a restart or project open/close, etc):

  • Save the data to a file and load the content in plugin_loaded() or as needed; you can save such a file anywhere you like, but it’s probably best practice to keep it to something like a folder inside of the sublime.cache_path() or sublime.packages_path() locations, since those are Sublime specific (and will work regardless of platform).

    You probably want to choose either the User folder or a folder named for your package so that you don’t potentially step on the toes of someone else doing the same thing.

  • Store it in settings; view.settings(), window.settings() or your own sublime-settings file. If using a project, you could also store values in the project specific settings or just the project data in general. The settings for a view and a window are persisted, so they’ll remain around as long as that view or window does (even across restarts), so this isn’t a good choice if the data should be persisted indefinitely though; also you can’t store arbitrary objects in settings (if that matters).

If you literally mean that you want to store the data somewhere and have access to it after quitting Sublime (i.e. Sublime is no longer running but you still want to look at it) then I’d go the file route and not the settings route for simplicity. Also you’d probably want to store the file somewhere more readily accessible from outside of Sublime in that case.

1 Like


Thanks. I thought of using settings but just asked the question to see if that’s a logical way.