Edit Substitutions in Options.

With each new Beta and RC I lose my customized substitutions (File | Options | Corrections | Edit Substitutions). Where are these stored so I can copy them, but not options like the theme. I know themes get updated frequently, and those I want to test, so saving and importing the entire options file doesn’t necessarily work.

I’ve found the customized dictionary file. Is there a similar list for just the substitutions?

They should be stored in your Options file that you can reload once you have updated to the new version.

My understanding is that substitutions are stored in the Windows Registry. :unamused: :open_mouth: But I don’t know why they would be removed when a new beta is installed.

Options are stored in the registry (see image) and substitutions are stored in a binary format, so you can’t just open RegEdit and copy the text. But you can export the key/data, edit the resulting text file to include only the substitutions, then import that back into the registry after installing the new version.

Most programs will remove their registry keys when they are uninstalled, so if you are uninstalling the old beta before installing the new beta, that explains why your substitutions disappear. So follow Jestar’s advice and export the options to a file before you uninstall, then install the new version, then import the options from the saved file.

Subsitutions are indeed saved with your preferences - just tested it out. I saved my current options (preferences) so I could go back, added a substitution (a simple three-letter acronym to expand out to the full spelling) and tested to make sure it works, saved the new preferences and then switched back to the old preferences without the substitution - the sub no longer worked. I was able to switch back and forth between them.
So, as you would with all of your normal Options preferences, save the preferences to a file after you have made the changes and definitely before you do an upgrade in the beta, then reload that set of preferences after you have done the upgrade. Saves a lot of work that you would have to do re-personalizing.

So if I’m reading you right, this is the solution to the desired ability to edit substitutions: save all options/preferences to a file, edit the substitutions in that file, maybe save it with a new name, then load that set of options. Correct?

Not exactly. Set up your options (preferences), click Manage, and then save to a file - just to set up a baseline preferences file in case you mess something up. Substitutions are a part of your options (preferences) file when it is saved, so I wouldn’t add them to the baseline just yet. Once you have saved the baseline, and with the Options window still open, go to the Corrections tab and click on “Enable additional substitutions”.

That will allow you to click the Edit Substitutions button that will bring up this dialog box:
Annotation 2020-07-16 171555.png
Click the Plus button to add your custom substitutions and, when you are done entering/editing, click the OK button to exit that dialog box and OK again to close the Options window. Then you want to test out those custom substitutions, make any changes you need to them, then go back into the Options (F12) → Manage → Save options to file. I would use a new name (add “subs” to the file name for instance) and save it. Click OK to exit Options. Now, once you update Scrivener, you would go back to Options (F12) → Manage → Load options from file. All the options and substitutions will come back and you don’t have to worry about re-adding them.

Thanks for your work on this, Jestar, and the detailed instructions. I was looking for a way to edit substitutions outside of the Scrivener dialog (i.e., add in a bunch all at once that I have in a different word processor). But it doesn’t sound like this is that after all.

Sorry, I don’t know of a way to do it outside of Scrivener. Not to say that a method doesn’t exist, just I don’t know of it. FWIW, I just learned (learnt for my British cousins) how to do this myself. You may be able to use your substitutions document to do copy->paste into the dialog (still one at a time) to speed things up. Of course, now that I have figured out how to do this, I’ll probably start using it more. :slight_smile:

I’m working on something that may be able to do the trick. I’m trying to take a page for L&L and not talk about it until it’s actually workable.

devinganger, international man of mystery! We will be waiting with beta-d breath (heh).

Right now, I’m trying to figure out what format that byte array actually is in, unless I’m just having a dull moment. I can’t manipulate it until I can properly unpack and pack it back into that format it’s using in the registry key.

The substitutions are preserved, if you use the automatic update embedded into Scrivener (Help > Check for Updates…).
If you uninstall and install Scrivener new, the substitutions are deleted from the registry upon uninstalling Scrivener.
If you uninstall and install Scrivener new, obviously you need to have a backup of your preferences before uninstalling Scrivener, so that you can restore the substitutions within the new installation.

If you experience anything else, please let us know.

Thanks for confirming that Tiho. That is exactly what we were discussing. My only quibble with the built-in updater is that on Windows 10 it does not remove the older version from the Installed/Uninstaller section of the registry. Easy enough to fix for the user if they want to mess with the registry themselves, but that shouldn’t be the case. Note that it also affects the 1.9.x version of Scrivener on Windows 10 using the built-in updater. It was not the case in Windows 7. I have no idea if it affected Windows 8 or 8.1 as I never “upgraded” to those.

I know you’re probably pretty busy, but would you mind enlightening us on what format the substitutionList registry value is stored as? I can turn it into the same string that starts “@ByteArray(…)” as in the options save file, but it looks like there’s a ton of embedded nulls.

I wanted to see if I could write a quick utility to allow bulk import/editing of the substitution list.

Thanks in advance…

@devinganger: This code snippet should help you read the substitutions from the registry.

QByteArray data; - holds the registry value with all the substitutions. Hope this helps.

    QDataStream stream(data);
    qint32 version;
    stream >> version;
    if (version == 1) {
        qint32 count;
        stream >> count;
        for (int i = 0; i < count; ++i) {
            bool isActive;
            QString matchText;
            QString insertText;
            stream >> isActive;
            stream >> matchText;
            stream >> insertText;