I'm not sure how this would be done dynamically. You would maybe be able to check if there are any items from other vendors in the cart and clear it if you're going to a different vendor, but then going back to the previous vendor would cause the cart to have been cleared, which is not ideal.
If you decide to go that route, you would have to figure out how to write the code to do it yourself, since it would require quite a bit of custom coding and so it is not supported. To clear the cart, you can look at the code on the cart page that clears the cart.