Last Updated: February 25, 2016
·
1.028K
· ck3g

Moving lines in Vim

Sometimes you might want to move line (or selected lines) into another place within current file.

There is several ways to achieve it:

Move current line up/down by lines count :m<direction><lines>

Example

:m+10 - Move current line down 10 lines
:m-5 - Move current line up 5 lines

To avoid doing math each time to calculate how much lines up/down do you need.
You could use relative numbers :set relativenumber (and :set number to switch back)

Another approach is to move current line into specific number: :m<line-number>

Example:

:m15 - Move current line into position of 15