How to Copy and Paste Text in Vim
| 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
vto enter visual mode. - Select the text with the arrow keys.
- Press
yto 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
- Place the cursor on the line you want to copy.
- Press
yy. - Move the cursor to where you want to paste.
- Press
p.
Additional Tips
- To copy and paste between files, use the registers (
"+yand"+p) if Vim was compiled with clipboard support. - You can check
:help yankand:help putinside Vim for more information.
Practice these commands and you’ll boost your productivity in Vim!