Vortex-induced vibration of a circular cylinder with a length-to-diameter ratio of 19.2 in a spanwise shear flow is investigated numerically. The Reynolds numbers based on the velocity at the centre of the cylinder and the mass ratio are 500 and 2, respectively. The responses of the cylinder in shear flows with shear factors of 0.05 and 0.1 are compared with that in the uniform flow. Although the oscillation of the lift force for a stationary cylinder in a sheared flow is very weak, it is found that if the cylinder is allowed to vibrate, the lock-in regime and the maximum response amplitude are comparable with their counterparts for a cylinder in a uniform flow. The maximum response amplitude for a shear factor of 0.05 is found slightly greater than that for a uniform flow. In the lock-in regime, the vortex shedding and the oscillation of the sectional lift coefficient are found to synchronize (have a same frequency) along the cylinder span, leading to strong vibration of the cylinder. The sectional lift coefficient changes from being in phase to being out of phase with the response displacement at a location on the cylinder span, and the location where the lift coefficient changes its phase depends on the reduced velocity. The phase change of the lift coefficient corresponds to the change in the vortex shedding mode. The role of the sectional lift coefficient in the vibration varies along the cylinder span. For a small reduced velocity in the lock-in regime, the sectional lift forces near the high-velocity end of the cylinder excite the vibration, while those at the rest of the cylinder span damp the vibration. With increasing reduced velocity, the location where the sectional lift forces excite the vibration moves towards the low-velocity end of the cylinder.