The recent discovery of phase IV of solid hydrogen and deuterium consisting of two alternate layers of graphenelike three-molecule rings and unbound H2 molecules have generated great interests. However, vibrational nature of phase IV remains poorly understood. Here, we report a peculiar proton transfer and a simultaneous rotation of three molecule rings in graphenelike layers predicted by ab initio variable cell molecular dynamics simulations for phase IV of solid hydrogen and deuterium at pressure ranges of from 250 to 350 GPa and temperature range of from 300 to 500 K. This proton transfer is intimately related to the particular elongation of molecules in graphenelike layers, and it becomes more pronounced with increasing pressure at the course of larger elongation of molecules. As the consequence of proton transfer, hydrogen molecules in graphenelike layers are short lived and hydrogen vibration is strongly anharmonic. Our findings provide direct explanations on the observed abrupt increase of Raman width at the formation of phase IV and its large increase with pressure.