How to Copy and Paste Text in Vim

DJC > Tutorial

| Vim |

Vim is a very powerful text editor, but its commands can seem complicated at first. Here you’ll learn how to copy and paste text easily.


Copying Text (Yank)

  • To copy an entire line, place the cursor on the line and press:

yy

  • To copy multiple lines, for example 5 lines:

5yy

  • To copy a visual selection:

  • Press v to enter visual mode.

  • Select the text with the arrow keys.
  • Press y to copy the selection.

Pasting Text (Put)

  • To paste the copied text, place the cursor where you want to paste and press:

p (after the cursor)

P (before the cursor)


Quick Example

  1. Place the cursor on the line you want to copy.
  2. Press yy.
  3. Move the cursor to where you want to paste.
  4. Press p.

Additional Tips

  • To copy and paste between files, use the registers ("+y and "+p) if Vim was compiled with clipboard support.
  • You can check :help yank and :help put inside Vim for more information.

Practice these commands and you’ll boost your productivity in Vim!

DJC > Tutorials


DJC > Tutorial