How do I write a config file manually? I need to find out how to manually create a configuration file, one which will be included with a custom theme as optional/required upon installation.

I know I need to create a file in themes/mytheme/config/optional for a block, but how do I know the exact filename and what to put in it?
Creating configuration files manually is tedious and like @Berdir mentioned in the comments it is better to export them.

First install your theme, so you can place the blocks for your new theme.


Create the blocks in the UI.
Make sure you have installed the module: Configuration Manager (already installed if you use Standard profile)
Export the configuration using the UI (/admin/config/development/configuration/full/export) or using Drush: drush cex
Depending on how you exported the configuration:


If you used UI, you have a .zip that you must extract.
If you used Drush, the files are exported to sites/default/config_longname/sync

The blocks file names are block.block.BLOCK_MACHINE_NAME.yml
Copy those block files that you created and put them config/optional in your theme folder.
Now open these files and remove the first line, looking something like: uuid: f95127a4-7947-48e3-a0f1-1dae6c61940d


That's it, if you move the theme to a new site and install the theme, the blocks will be installed and placed where you originally put them.