Wikia

Vim Tips Wiki

Changes: Copy, cut and paste

Edit

Back to page

m (Reverted edits by 116.202.129.157 (talk | block) to last version by 209.119.64.116)
Line 1: Line 1:
 
{{review}}
 
{{review}}
{{Importuned
+
{{TipImported
 
|id=312
 
|id=312
 
|previous=311
 
|previous=311
Line 6: Line 6:
 
|created=August 13, 2002
 
|created=August 13, 2002
 
|complexity=intermediate
 
|complexity=intermediate
|author=Annis W. Groundhog
+
|author=Anis W. Nugroho
 
|version=5.7
 
|version=5.7
 
|rating=688/270
 
|rating=688/270
Line 41: Line 41:
 
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 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 g vim for Windows and want to copy or cut into the Windows clipboard, press Ctr l+Insert in step 4 (to copy) or Shift+Delete to cut. To paste from the Windows clipboard, press Shift+Insert.
+
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.
   
 
----
 
----
Line 49: Line 49:
 
:e ~/dummy
 
:e ~/dummy
   
paste the text to the new buffer<Br>
+
paste the text to the new buffer<br>
write the new buffer (:w)<Br>
+
write the new buffer (:w)<br>
switch to the previous buffer (:BP) to release *swop<Br>
+
switch to the previous buffer (:bp) to release *.swp<br>
now switch to the other console<Br>
+
now switch to the other console<br>
put the cursor at the desired place<Br>
+
put the cursor at the desired place<br>
 
read the dummy file (:r ~/dummy)
 
read the dummy file (:r ~/dummy)
   
Line 59: Line 59:
 
If you want to simulate the Windows way of Cut/Copy/Paste you could add the following line to your initialization file.
 
If you want to simulate the Windows way of Cut/Copy/Paste you could add the following line to your initialization file.
   
source $UNTIMELY/mswin.vim
+
source $VIMRUNTIME/mswin.vim
   
 
Read :help :behave for other information.
 
Read :help :behave for other information.
Line 70: Line 70:
   
 
----
 
----
same problem with me (50 line limit). I've fixed this before but don't don't remember what the fix was.
+
same problem with me (50 line limit). I've fixed this before but dont dont remember what the fix was.
   
 
----
 
----
 
Increase the buffer limit between multiple files.
 
Increase the buffer limit between multiple files.
   
:help 'vim info'
+
:help 'viminfo'
 
...
 
...
 
< Maximum number of lines saved for each register.
 
< Maximum number of lines saved for each register.
 
...
 
...
:set vim info?
+
:set viminfo?
:set vim info='100,<100,s10,h
+
:set viminfo='100,<100,s10,h

Revision as of 19:29, March 14, 2012

Tip 312 Printable Monobook Previous Next

created August 13, 2002 · complexity intermediate · author Anis W. Nugroho · version 5.7


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

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

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.


How copy and paste between two instances of Vim on different Linux consoles?

After copying text, open a new buffer for a new file:

: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)


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.


See Quick yank and paste.


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


same problem with me (50 line limit). I've fixed this before but dont dont remember what the fix was.


Increase the buffer limit between multiple files.

 :help 'viminfo'
 ...
 <       Maximum number of lines saved for each register.
 ...
 :set viminfo?
 :set viminfo='100,<100,s10,h

Around Wikia's network

Random Wiki