I'd say that it's impossible to train a cat not to vomit in certain places. One of the reasons for it is the cats aren't really reliably trainable, at least not it the sense that dogs are. But that's not the only factor - I don't think it's possible to train dogs not to vomit on carpets either.
Vomiting generally is not something that is consciously planned, it's rather spontaneous and unpredictable not only for you, but somewhat also for your vomiting cat - while it could feel the looming nausea, the vomiting itself is an involuntary reflex, happens rapidly and is not something that is consciously planned.
I should also explain why do cats seem to prefer vomiting on carpets in the first place, but I guess that wouldn't be directly helpful for you, but please consider that it might help you to invent your own solution. for this problem. Actually, believe it or not, as far as I know cats in some sense believe that vomiting on a carpet is cleaner than doing so on a hard and non-porous surface - and it has to do with their instinct. Cats naturally tend to immediately cover their waste products (urine, feces, vomit) with dirt to keep it "clean" and dispose of anything that could signal their presence to potential predators.
Soft, somewhat squishy and porous surface, like the one of a carpet, provides tactile sensation that is more closely resembling the dirt that the tactile sensation of hard and non-porous floor, thus it encourages the cat to vomit there.
They also seek porous surfaces because they subconsciously know that the waste products will soak into them over time and thus become less evident. Their hardwired concept of being clean doesn't include disposing of the waste in our humanly manner.
However, it doesn't mean that you're doomed to have your carpets ruined by the cat's vomiting. I'd actually focus on resolving the cause of the vomiting itself - ingesting hair and the forming of hairballs, that is. While it is not expected to be completely resolvable issue, you could try the following to significantly reduce the frequency of cat's vomiting.
- Regular, daily brushing your cat with a wire brush. This way you'll remove the hair strands that are already loose and thus reduce amount of ingested ones.
- Using specialized, high in fiber cat food formulas, aimed to reduce hair shedding and/or improve your cat's digestive tract's ability to efficentlyefficiently pass them without accumulating.
- For non-hairball related vomiting, try to indentify what could cause gastrointestinal irritation and eliminate it from cat's diet.