I know he's doing it to get attention - particularly at the dinner table, or when we're out. But he'll stick one hand in his mouth until he starts gagging, and giggles when my wife tells him to stop. If we ignore him, he does it until he vomits, giggles, then does it again. Holding both hands frustrates him, of course, and only works until we let go.
I'm still not certain if it's anything that we did, or if he just got bored of it, but I managed to convince my wife to join me in just ignoring him when he does it, and the practice has basically ceased. He still occasionally makes a gagging noise while in his high chair in order to get our attention, but he hasn't done it while shopping in quite a while, and I think he's making the association that doing it generally results in his food going away (on the off chance that it actually is something in the food making him gag), which he of course doesn't like.
The way to handle things they do just to get attention is, yes, by ignoring it. Eventually, he will realize he's not getting a reaction out of you, so he'll figure out something else that gets a rise out of you, lol. Just clean up after he vomits and try as best as you can not to make a big deal about it