How do I move a line to a specific line number?
Answer
:m {line-number}
Explanation
The :m (move) command moves the current line to after the specified line number. It is the cleanest way to reposition a line without yanking and pasting.
How it works
:m 0moves the current line to the top of the file:m $moves it to the end:m 10moves it to after line 10:m +1moves it down one line:m -2moves it up one line
Example
With the cursor on a misplaced import line, :m 0 moves it to the top of the file.
Tips
:m+1and:m-2are useful for nudging lines up/down:'<,'>m $moves the visual selection to end of file:mcan use marks as targets::m 'a:t(copy) is similar but copies instead of moving- Map these for quick line movement:
nnoremap <A-j> :m+1<CR>