Disclaimer: I have not replaced my shift lever. What follows is therefore conjecture.
It appears the shift lever rotates around the foot peg anchor assembly, so the foot peg would definitely have to be removed before the shift lever would be free of the bike.
The foot peg is fastened to the bike by an outward-facing Allen-head machine screw that requires a 6 mm wrench. There's not much room to get the wrench handle to turn the screw, but I didn't fiddle with my Allen sockets which may or may not work in the confined space.
Worst case if you can't operate a wrench in there: Remove the whole assembly to which the foot peg bolts. All of those machine screws have their heads on the outside of the bike, facing in, so there should be more room. I'd take a closeup photo and label the screws as I took them out to make reassembly foolproof.
Be sure to let us know what worked for you, for I'm sure others will need this knowledge in the future.