Locomotion of earthworm-like metameric robots results from shape changes of deformable segments. Morphologically, the segments could stretch, contract or bend by changing their states. Periodic shape changes are recognized as gaits of the robots. Robots could employ different gaits for different locomotion tasks. However, earthworm-like robots generally possess a number of independent segments and their hyper-redundant morphology (Chirikjian G S and Burdick J W 1995 IEEE Trans. Robot. Autom. 11 781-93) poses a challenge to gait planning for their locomotion. Hence, the goal of this paper is to establish a framework of in-plane gait planning for earthworm-like robots. To this end, a generic model of earthworm-like robots modelled in our prior work (Zhan X et al 2019 Int. J. Robot. Res. 38 1751-1774) is firstly reviewed and in-plane gaits of the robot are parameterized by adopting the principle of retrograde peristaltic wave (Quillin K J 1999 J. . Following this, gaits of earthworm-like robots could be uniquely determined by gait parameters, and gait planning of the robots is then reduced to optimizing the gait parameters. The framework mainly consists of a locomotion simulation module and a genetic algorithm module. In the locomotion simulation, the performance of each gait would be evaluated, and then gait parameters get evolved based on the fitness in the genetic algorithm module. To evaluate the fitness of each gait, two objective functions, i.e., the distance to goals and the number of locomotion steps the earthworm-like robot taken before reaching the goals, are to be minimized in the optimization. Besides, two stopping criteria are proposed to improve the efficiency of evaluation. The framework proposed in the paper could plan in-plane gaits of earthworm-like robots, in contrast, only rectilinear locomotion is considered in similar works. This greatly advances the state of art of earthworm-like robots.