The limited potassium-ion intercalation capacity of graphite hampers the development of potassium-ion batteries (PIB). Edge-nitrogen doping (pyrrolic and pyridinic) has been demonstrated as an effective approach to enhance K-ion storage in carbonaceous materials. One primary shortcoming of current methods is the lack of precise control over producing edge-nitrogen configuration. In this work, we present a molecular-scale copolymer pyrolysis strategy for precisely controlling edge-nitrogen doping in carbonaceous materials. Our optimized process results in defect-rich, edge-nitrogen doped carbons (ENDC) with a high nitrogen doping level up to 10.5 at. % and high edge-nitrogen ratio of 87.6%. The optimized ENDC exhibits a high reversible capacity of 423 mAh g-1, a high initial Cloulombic efficiency of 65%, superior rate capability, and long cycle life (93.8% retention after three months). This edge-nitrogen control strategy can be extended to design other edge-heteroatom rich carbons through pyrolysis of copolymers for efficient storage of various mobile ions.