We start with x-5. We want to add on some h value such that x-5+h = x+1, which solves to h = 6. So we must add on 6 to (x-5) to get to (x+1). This shifts the graph 6 units to the right.
As for the vertical shifting, we start with +7 and we end up at -2. The vertical distance is 7-(-2) = 9 units, so we must shift 9 units down.