H1 Visa transfer once done with stamping

My H1 B visa is approved and stamped. If I decide to switch my company (as there is no plan sooner) I have to ask new employer to file petition before putting papers? If I put papers and my current employer cancels my visa, does the new employer can still file (with cap exemption).

Yes, that would be safe. Get the visa transfer started before informing your current employer about you leaving. Once you get the H1 transfer petition receipt, you should be fine.

So there are two things in play here - your visa stamp in the passport and your approved 797 petition. The old employer can get both canceled. If the petition is canceled, still a new employer can file for another cap-exempt petition (aka H-1 transfer). If the visa stamp is canceled, then you will have to re-appear for visa stamping after getting the new petition approved.