Vim Tips Wiki
Register
No edit summary
 
m (Copy, Cut, and Paste moved to Copy, cut and paste: Page moved by JohnBot to improve title)

Revision as of 09:22, 18 October 2007

Previous TipNext Tip

Tip: #312 - Copy, cut and paste

Created: August 13, 2002 23:20 Complexity: intermediate Author: Anis W. Nugroho (anis_wn--AT--cbn.net.id) Version: 5.7 Karma: 688/270 Imported from: Tip#312

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

Comments

Sorry, step 4 for Copying supposed to be 'Copy...' :(

anis_wn--AT--cbn.net.id , August 13, 2002 23:24


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.

marcin--AT--amiga.pl , August 13, 2002 23:31


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.

rainbrot--AT--snark.com , August 18, 2002 3:12


Hello Guys. How to copy and paste between two instances of Vim on different Linux consoles?

dedekind--AT--mail.ru , November 16, 2003 1:23


after copying text, open a new buffer for a new file, ie

e ~/dummy

paste the text to the new buffer. write the new buffer. (:w) switch to the previous buffer (:bp) to release *.swp

now switch to the other console. put the cursor at the desired place. read the dummy file (:r ~/dummy).

that's it. the question is "why do you want to play in the other console? use multi buffer editing instead."

anis_wn--AT--cbn.net.id , November 28, 2003 13:41


How to use windows commands in vim? e.g. copy/paste/selectall, etc -> Ctrl-C, Ctrl-V, Ctrl-A, etc

Thanks Atur

atur--AT--vigorsoft.com , May 12, 2004 22:37


If you want to simulate the Windows way of Cut/Copy/Paste you could add the following line to your initialization file.

source $VIMRUNTIME/mswin.vim

Read :help :behave for other information.


Anonymous , February 22, 2005 19:06


VimTip866

-- Matous Jan Fialka [ http://vcp.ligatura.org/ ]

Matous Jan Fialka , March 5, 2005 7:35


Why can I not copy and paste a block of 200 lines? The yank works fine, but the paste only does about 50.

andrewz--AT--springsrescuemission.org , February 7, 2007 14:41