Skip to content

Storing Settings

On this page, you can find information about creating configuration options that will or will not get shared to other vaults and devices.

The table below gives a summary of what you should do if you want to e.g. have a setting that does not get shared to other vaults.

SINGLE VAULTMULTIPLE VAULTS
LOCAL-ONLYStore in localStorage with appId prefixStore in localStorage
SHAREDStore in plugin settingsStore in plugin settings, update device localStorage on settingsChange

Unique to a single device, unique per vault

Section titled “Unique to a single device, unique per vault”

Use this approach when you want to store a setting that will not be available to other vaults or devices.

// Store your setting
app.saveLocalStorage("yourplugin:setting", VALUE)
// Read your setting
app.loadLocalStorage("yourplugin:setting")

Keep in mind that this makes use of private API, add your own typings for these methods or use Obsidian Typings to use this in a type-safe way.

Behind the scenes, the setting combines the provided key with the appId (app.appId+ key), and then stores it in localStorage.

Unique to a single device, shared between vaults

Section titled “Unique to a single device, shared between vaults”

Use this approach when you want to have a setting that will also be available to other vaults on this device.

// Store your setting
localStorage.setItem("yourplugin:setting", VALUE)
// Read your setting
localStorage.getItem("yourplugin:setting")

Use this approach when you have a setting that should be used on all devices where the vault is used.

Follow the Official Settings guide.

export default class ExamplePlugin extends Plugin {
// ...
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}

Shared between devices, shared between vaults

Section titled “Shared between devices, shared between vaults”

Use this approach when your setting should be the same on every instance of Obsidian that the user uses.

Store the setting in regular localStorage (see above), and whenever a setting changes, update the localStorage value:

export default class ExamplePlugin extends Plugin {
// ...
async loadSettings() {
this.settings = Object.assign(
{ value: localStorage.getItem("yourplugin:setting") },
DEFAULT_SETTINGS,
await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
localStorage.setItem("yourplugin:setting", this.settings.VALUE)
}
}