Heat the oil in a large heavy-based pan. Add the onions and cook very gently for 30 minutes, stirring now and then, until very soft and caramelising. Add a third of the sugar and cook for another 15 minutes. Add the rest of the ingredients.
Simmer on your lowest heat until the liquid has reduced and the onions are dark and sticky. This will depend on your pan, approx. 30-45 mins. You should be able to run a wooden spoon through and leave the pan clean underneath.
Pot while hot into warm sterilised jars and seal with vinegar-proof lids. Store in a cool dry place and use within 3 months. Keep in the fridge once opened and use within a couple of weeks.
To sterilise your jars, put clean, dry jars on a baking tray and into a cold oven. Heat to 150°C/Gas 1-2 then heat for a minimum of 15 minutes. Fill the hot onion mixture into hot jars straight from the oven; fill right to the top and use a skewer to poke out any air holes. Then screw on the lids and turn upside down for 10 minutes to sterilise the lids.