DI is CRUCIAL in the ditto. Since you're pairing amazing edgeguard with horrible recovery, this matchup is extremely tedious. once you're out your stock is p much gone.
Neutral:
Play grounded, dashdance grab. dtilt to limit his dash dance, I don't recommend going for aerials. Punish aerials with FTilt, it's amazing, It outranges a lot of marth's moves so don't be scared to go for it. Wavedash OoS is amazing against shielded fsmashes, you basically get a free grab if they get antsy and fsmash.
Grabs:
If you get grabbed at any percent you gotta nail the DI down and away otherwise you'll get regrabed/eat a forward smash. In case you DI wrong and will eat a fsmash just DI all the way in and up. not much else to do if you miss the di at the ledge.
At extremely low percents you also DI down and away but you have to buffer something to avoid the regrab, be it spotdodge or roll or whatever.
If you notice the opponent does good DI to your F- Throws mix up up throws, iirc upthrow to upair is guaranteed when they DI down and away. it's a mix up so if your opponent also does this just don't di down and away and you should get out of that.
Edgeguards:
Just mix it up, sometimes go out there for the back air edgeguard so they get scared of going low but you can usually bait them to go up the ledge with their upb and roll fsmash or something. You can stay at the ledge and dtilt or fsmash as they up b if they're not good at sweetspotting too.
If you're at the ledge you can do a normal get up if you're under 100% and expect them to fsmash, it has some good invulnerability, and if they delay it and you shield it you get a free wavedash grab. it's usually about guessing what the opponent will do. You can also hax dash and double jump to the side platform on battlefield to get out of there.
that's all I can think of right now. Some stuff may be off it's been a while since I played the ditto.