Use ex mode in vim to move lines quickly
Move text quickly in vim. When you start out in vim, you might:
- First, delete the text
- Then, move your cursor to the desired location
- 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:
:10;+10m8
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
Written by Kenrick Chien
Related protips
1 Response
OMG :move! And here I've been doing y'a'bp
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#