Alex Rivera | Logout

Move entire line up and down in Vim

Asked 2009-04-12T14:02:53.333
494

In Notepad++, I can use Ctrl + Shift + Up / Down to move the current line up and down. Is there a similar command to this in Vim? I have looked through endless guides, but have found nothing.

If there isn't, how could I bind the action to that key combination?

Edit: Mykola's answer works for all lines, apart from those at the beginning and end of the buffer. Moving the first line up or the bottom line down deletes the line, and when moving the bottom line up it jumps two spaces initially, like a pawn! Can anyone offer any refinements?

Edit
Report

2 Answers

12

In command mode position the cursor on the line you want to move down, and then

ddp

Explanation: dd deletes the current line to the general buffer p puts it back AFTER the cursor position, or in case of entire lines, one line below.

There is some confusion regarding commands p and P in many docs. In reality p pastes AFTER cursor, and P AT cursor.

answered 2011-09-17T10:46:39.380
1

vim plugin unimpaired.vim [e and ]e

answered 2012-05-17T21:54:45.697

Your Answer