When you're just starting to make a change, you need to take tiny steps toward your goal. There's no switch to turn off complaining, so you have to start somewhere. Jon Gordon, author of "The No Complaining Rule," suggests filtering yourself with the "but-positive" technique:

If you find yourself griping, add a 'but' and say something positive. For example, I don't like driving to work, but I'm thankful at least I can drive and I even have a job.

Yes, your complaint still spills out, but the positive note you add helps clear the air a little. You register that you made a complaint, add a reason why it might not be worth complaining about, and—over time—complaints will become far less common.