Last Updated: February 25, 2016
· kchien

Use ex mode in vim to move lines quickly

Move text quickly in vim. When you start out in vim, you might:

  1. First, delete the text
  2. Then, move your cursor to the desired location
  3. Finally, put the text before or after the cursor (using P/p, respectively).

Next time, use ex commands to do this like a boss!

For example, let's assume you want to move line numbers 10-20 to line 8. You would do this by entering:


Let me explain the above:

  • The colon brings you into ex mode.
  • The first 10: line number 10
  • The semicolon: used so that the next number is calculated relative to the first.
  • +10 : means add to the first number
  • m: means move
  • 8: the line number where you want to move the text

Source: I learned this from Learning the vi and vim editors, 7th edition by By Arnold Robbins, Elbert Hannah, Linda Lamb

1 Response
Add your response

OMG :move! And here I've been doing y'a'bp

over 1 year ago ·