vimtricks.wiki Concise Vim tricks, one at a time.

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 V and motions
  • :'<,'>m'>+1 moves the selection down one line
  • :'<,'>m'<-2 moves 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=gv moves up
  • gv=gv reselects and re-indents after moving
  • This is similar to Alt+Down in other editors
  • Works with any number of selected lines

Next

How do you yank a single word into a named register?