This article documents the relationship between Sheldon J. Plankton and Gary the Snail. They first interact in the season 7 episode "Shellback Shenanigans," where Plankton disguises himself as Gary to steal the Krabby Patty secret formula.
For two whole seasons, they didn't have another interaction until The SpongeBob Movie: Sponge Out of Water. Towards the end of the film, SpongeBob gives Gary a Krabby Patty with mayonnaise. However, SpongeBob notices something fishy as he says that Gary hates mayo. The Gary is then revealed to be a robot that Plankton was controlling. The real Gary comes into the Krusty Krab and growls at Plankton, causing him to run away.
Plankton and Gary's next interaction is in "Pineapple Invasion," where they face each other in fighting and beating each other after SpongeBob hid the Krabby Patty formula in his house. Plankton soon goes into Gary's shell but starts to hallucinate when the smell from the shell is responsible for his hallucination, causing Plankton to fail and pick up a grocery list instead.