How do I swap two lines in vim?

To swap the current line with the next one, type ddp while in command mode.

  • dd - delete line (actually called cut in other editors) and save it in register
  • p - paste line from register

dd deletes the current line, then you can paste the removed line using p. There's another way though using m. With m you can move lines around i.e.

:m 1 will move the current line after line 1

:m 0 will move the current line to top

:m $ will move the current line to bottom

In your example, place the cursor in the first line and type :m $

More info: http://vim.wikia.com/wiki/Moving_lines_up_or_down