The dynamics of a cylinder arranged between two sidewalls in a uniform flow is experimentally investigated. To investigate the effect of sidewalls on flow-induced vibration, both circular and square cylinders are considered. The gap between cylinder and sidewalls is sufficiently small to induce the oscillating cylinder to periodically impact the walls under certain conditions. The dynamic responses of a circular cylinder change dramatically depending on whether the cylinder impacts the walls. An impacting circular cylinder can oscillate with a large amplitude beyond a critical reduced velocity, the magnitude of which is restricted by the gap distance, whereas a non-impacting circular cylinder only oscillates in a lock-in region of the reduced velocity. The periodic impact with the sidewalls, rather than lock-in with vortex shedding, allows the large-amplitude oscillations of the impacting cylinder to persist. The impacting circular cylinder exhibits strong hysteresis, which is not observed for the non-impacting cylinder. Furthermore, the oscillation frequency of the impacting cylinder is proportional to the reduced velocity. The periodic impact acts to improve the power extracted by a damping mechanism in a broader range of reduced velocity. Meanwhile, for a square cylinder between sidewalls, oscillation by galloping is suppressed, and no impacts occur over the entire range of the reduced velocity. The suppression is caused by shear-layer reattachment on the side surface of the square cylinder, which is generally observed at a large angle of incidence for an isolated square cylinder.