Another possibility is that it could be allergies...My yorkie was doing this, and it turned out to be pretty serious allergies.
I removed all possible allergens from the house. Washed everything in non perfume, non dye detergent. Vacuumed everything twice a day for a couple of days. Washed walls, etc.
It went away.
It was happening at night or more around 4AM, 5AM, 6AM, etc. more than anything. It was like hacking, and he would hack up white liquid, sometimes foamy. It was really pitiful...

Sometimes he would hack so much that he would end up vomitting just like you said.
The vet actually gave us a cough expectorant instead of a cough suppressant because she said he needed to get that stuff out.
I never ended up having to use it though because like I said, I removed all possible allergens from the house and went on a crazy cleaning rampage, and his allergy symptoms went away.
The vet also put him on antibiotics just in case as well...