Vim Tips Wiki
(Undo revision 38240 by 85.10.248.24 (talk))
Tag: sourceedit
Tags: Visual edit apiedit
Line 50: Line 50:
 
==Increasing the buffer size==
 
==Increasing the buffer size==
 
Sometimes you can only copy up to 50 lines. To solve this, increase the buffer limit between multiple files.
 
Sometimes you can only copy up to 50 lines. To solve this, increase the buffer limit between multiple files.
  +
  +
Aside from the line limit, a size limit (in KB) may also be present.
  +
  +
In the example below, <100 limits the number of lines saved for each register to 100 lines. The s10 in the same example limits the maximum size of each item to 10 kilobytes.
 
<pre>
 
<pre>
 
:help 'viminfo'
 
:help 'viminfo'

Revision as of 23:52, 27 May 2015

Tip 312 Printable Monobook Previous Next

created August 13, 2002 · complexity intermediate · version 6.0


Here is how to cut-and-paste or copy-and-paste text using a visual selection in Vim.

Cut and paste:

  1. Position the cursor where you want to begin cutting.
  2. Press v to select characters (or uppercase V to select whole lines).
  3. Move the cursor to the end of what you want to cut.
  4. Press d to cut (or y to copy).
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.

Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:

  • d = delete = cut
  • y = yank = copy

Multiple copying

Deleted or copied text is placed in the unnamed register. If wanted, a register can be specified so the text is also copied to the named register. A register is a location in Vim's memory identified with a single letter. A double quote character is used to specify that the next letter typed is the name of a register.

For example, you could select the text hello then type "ay to copy "hello" to the a register. Then you could select the text world and type "by to copy "world" to the b register. After moving the cursor to another location, the text could be pasted: type "ap to paste "hello" or "bp to paste "world". These commands paste the text after the cursor. Alternatively, type "aP or "bP to paste before the cursor.

Windows clipboard

When using Vim under Windows, the clipboard can be accessed with the following:

  • In step 4, press Shift+Delete to cut or Ctrl+Insert to copy.
  • In step 6, press Shift+Insert to paste.

Different instances

How to 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)

Increasing the buffer size

Sometimes you can only copy up to 50 lines. To solve this, increase the buffer limit between multiple files.

Aside from the line limit, a size limit (in KB) may also be present.

In the example below, <100 limits the number of lines saved for each register to 100 lines. The s10 in the same example limits the maximum size of each item to 10 kilobytes.

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

See also: Quick yank and paste}}

Comments