From SmashWiki, the Super Smash Bros. wiki
A Ledge Recovery Attack is performed when you push either A Button or B Button while hanging on a ledge. Your character attacks and recovers from the ledge at the same time. There are 2-3 different Ledge Recovey attacks for each character and are chosen at random.