How do I swap two adjacent lines?
Answer
ddp
Explanation
The ddp sequence swaps the current line with the line below it. It is the line-level equivalent of the xp character swap.
How it works
dddeletes the current line (saved to register)ppastes the line below the new current line- The result is the two lines have swapped positions
Example
line B
line A
With the cursor on line B, pressing ddp gives:
line A
line B
Tips
ddkPswaps the current line with the line above:m+1moves the current line down one position (same effect):m-2moves the current line up one position- In visual mode, you can use
:m'>+1to move selected lines down