Dave's Brain

Browse - Computer Tips - Is there a way to cut and paste with vim?

Date: 1997dec16
Updated: 2010jan21
Keywords: vim, vi, cut, copy, paste
OS: Linux

Q.  Is there a way to cut and paste with vim?

A.  Ever try to cut (or copy) some lines and paste to another place?
If you need to count the lines first, then try these to eliminate counting task.

Cut and Paste:

1. Place the cursor at the beginning of the block you want to CUT. 2. Mark it with md 3. Go to the end of the block. 4. Cut it with d'd 5. Go to the new location that you want to PASTE those text. 6. Press P.
Copy and Paste:
1. Place the cursor at the beginning of the block you want to COPY. 2. Mark it with my 3. Go to the end of the block. 4. Cut it with y'y 5. Go to the new location that you want to PASTE those text. 6. Press P.
The name of the mark used is related to the operation (d:delete or y:yank). I found that those mark names requires minimal movement of my finger. ;)

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.