How do I move selected lines down in the file?
Answer
:'<,'>m'>+1
Explanation
The :m command with the visual range moves selected lines. '>+1 places them after the line below the selection.
How it works
- Select lines with
Vand motions :'<,'>m'>+1moves the selection down one line:'<,'>m'<-2moves the selection up one line
Example
line A
line B
line C
Select line A and line B, run :'<,'>m'>+1:
line C
line A
line B
Tips
- Map this for convenience:
vnoremap J :m'>+1<CR>gv=gv vnoremap K :m'<-2<CR>gv=gvmoves upgv=gvreselects and re-indents after moving- This is similar to Alt+Down in other editors
- Works with any number of selected lines