
In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up.Īfter visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up. The mappings work in normal, insert and visual modes, allowing you to move the current line, or a selected block of lines. The following mappings in your vimrc provide a quick way to move lines of text up or down. See :help redo-register Mappings to move lines The result is that all the lines are pasted, in the correct order. The first dot command pastes register 2, and the next pastes register 3, and so on. Repeat with the dot command, eight times: Now type "1P to paste the contents of register 1 before the cursor. Repeat this on "line 3", and so on, until everything has been deleted in order. Move the cursor to "line 1" and type dd to delete the line. The following example lines can be moved to a different order by deleting each line in turn (starting with the line that will be first when the move is complete): Move 5 lines starting at current line to after line 21 Move lines 5, 6 and 7 to before first line You can also use arbitrary ranges with the move command. To move a block of lines, use the same command but visually select the lines before entering the move command. Move current line to the end of the current paragraphįor clarity, a space is shown after the :m commands above, but that space is not required. Move current line to before line with mark a

Move current line to after line with mark a (see using marks) You can move a line, or a block of lines, with the :m command. Press "ap to paste after the line with the cursor, or "aP to paste before.Select a range of lines vith V type "Ad to delete the entire range and append it to the same register.

