Why don't aircraft use gimbaled engines instead of flaps?
Historically, flaps and control surfaces were moved manually: The pilot would move a stick, a control column or pedals, and pulleys or pushrods would transfer this force to the control surfaces. To do this with engines was physically impossible.

With the introduction of hydraulics, large enough forces for tilting engines were available for the first time. Some aircraft used them, but this application did not find widespread use because the possible lift increase was smaller than what could be achieved with flaps. The same goes for controlling the aircraft: Directed thrust control forces are much smaller than what was possible already with control surfaces. Also, the responsiveness of tilting a heavy engine is much worse that that of a light control surface. Consequently, moveable engines were mostly used for short take-off and landing (STOL) applications. The Do-29 was one of several experimental aircraft which could pivot the propellers to take off at lower speed. Note that in case of the Do-29 the engines stayed in place; only the propellers and their driveshafts would move. Other designs would tilt their wing and with it the wing-mounted engines. In all those cases this was only done to enable short take-off runs, not to control the aircraft.


Do-29 in the Dornier museum (picture source)

Other applications were for special cases like flying boats:



The Dornier Do-26 could tilt the rear engines up for operation on water to reduce the impact of spray on the propellers (picture source). Note that this was not for control, but for lifting the props out of the spray area.

Control surfaces are better suited for creating control moments:


Control surfaces sit at the ends of the aircraft, so they have a much better leverage. Engines were placed close to the center to minimize the control problems caused by a loss of a single engine.
Control surfaces modify the lift force, whereas engines modify thrust, which is in the order of magnitude of drag and, consequently, an order of magnitude smaller than lift.


However, this is only true as long as aerodynamics works in a linear fashion. Which is not the case with separated flow and stalled flight surfaces. To overcome this limitation, the exhaust stream of jet engines is deflected by pivoting the nozzle (or paddles, as done on the X-31). This is much easier to do than to move the whole engine. Also, since the engine stays aligned with the airframe, the intake will continue to work and the frontal area of the airplane does not increase; both important considerations which stand against pivoting the whole engine.


Vectoring nozzles on the Sukhoi 35 (picture source)

Generally, aircraft are controlled by changing moments which in turn rotate the aircraft such that the desired flightpath change is effected by the changed aerodynamic forces. There have been attempts at direct force control, however: One Dassault-Dornier Alpha Jet was fitted with moveable wing pylons which could be rotated around a vertical axis. When moved, this would create a side force which enabled the pilot to directly shift the aircraft's flight path sideways. With moment control, you first need to roll the aircraft in order to tilt the lift vector sideways and then roll back shortly before the desired sideways change is complete. This is much harder to get right with moment control than with direct force control, especially for small corrections.