Vim logo vim online Vim Book Ad

 Tip #312: Copy, Cut, and Paste

 tip karma   Rating 94/46, Viewed by 2373 

created:   August 13, 2002 23:20      complexity:   intermediate
author:   Anis W. Nugroho ([email protected])      as of Vim:   5.7

PS: copy, cut, and paste are the words from (usually) gui editor.

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. ;)

 rate this tip  Life Changing Helpful Unfulfilling 

<<Open the folder containing the currently open file | printing using kprinter (unix + kde) >>

Additional Notes

[email protected], August 13, 2002 23:24
Sorry, step 4 for Copying supposed to be 'Copy...' :(
[email protected], August 13, 2002 23:31
2. Press v to select block
4. Cut it with "dd
4. Copy it with "yd
6. Press P (if you want to paste before) or p (if you want to paste after).

6. If you want to paste it later press "dp (or "yp for copy) to insert it after.
[email protected], August 18, 2002 3:12
Cut and paste:
1. Position the cursor where you want to begin cutting.
2. Press v (or upper case V if you want to cut whole lines).
3. Move the cursor to the end of what you want to cut.
4. Press d.
5. Move to where you would like to paste.
6. Press p to paste after the cursor, or P to paste before.

Copy and paste can be performed with the same steps, only pressing y instead of d in step 4.

If you want to copy and paste between editor buffers (but not between instances of vim), or if you want to maintain multiple "clipboards" (copy buffers), you can name your buffer by pressing "x (that's a double quote followed by x, where x is the single letter name you choose for your buffer) before the d in step 4, and again before the p in step 6.

If you happen to be using gvim for Windows and want to copy or cut into the Windows clipboard, press Ctrl+Insert in step 4 (to copy) or Shift+Delete to cut.  To paste from the Windows clipboard, press Shift+Insert.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo