The three ways to copy in Vim
Vim copies text using the yank command, which is the letter y. Unlike most text editors, Vim does not use Ctrl+C to copy — instead, you press y followed by a movement command that tells Vim what to copy. The text goes into Vim's clipboard (called a register), and you paste it with p.
The three most common copy patterns are: yank a whole line with yy, yank from your cursor to the end of the line with y$, or yank a word with yw. Each one combines the yank command with a direction — the same directions you use to move around in Vim.
Once you have copied text, you paste it by pressing p (paste after the cursor) or P (paste before the cursor). The text stays in Vim's clipboard until you yank something else, so you can paste the same text multiple times in the same file or in a different file.
Key Takeaways
- Vim's yank command is y, not Ctrl+C — press y followed by a movement to copy text to Vim's clipboard.
- The most common yanks are yy (whole line), y$ (to end of line), and yw (one word).
- Paste copied text with p (after cursor) or P (before cursor), and the text stays in the clipboard for multiple pastes.
- Vim stores copies in registers, and you can view what you have copied by typing :reg in command mode.
Yank a whole line with yy
The quickest copy in Vim is yy, which copies the entire line your cursor is on. You do not need to position the cursor at the start of the line — yy works from anywhere on that line. Press yy once, and the whole line (including the newline at the end) goes into the clipboard.
To copy multiple lines at once, press a number before yy. For example, 3yy copies the current line plus the two lines below it. This is faster than copying one line, pasting it, and repeating. After you press 3yy, move your cursor to where you want the lines to go and press p to paste all three at once.
Yank from cursor to end of line with y$
The command y$ copies everything from your cursor position to the end of the current line. This is useful when you are in the middle of a line and want to grab the rest of it without copying the beginning. Position your cursor at the point where you want to start copying, press y$, and the text from there to the line's end is copied.
A related command is y^, which copies from your cursor back to the start of the line (not including leading whitespace). If you want to copy from the start of the line to your cursor, use y0 instead. These directional yanks let you copy partial lines without selecting by hand.
Yank a word or character with yw and yl
To copy a single word, position your cursor at the start of the word and press yw. Vim copies the word and the space after it. If you want to copy just the word without the trailing space, use yiw (yank inside word), which copies only the letters and numbers that make up the word.
For smaller copies, yl copies a single character at your cursor. This is rarely needed, but it works the same way as other yanks — press yl and the character is copied. You can also copy a character by pressing y and then the right arrow key, since the arrow is a movement command that Vim understands.
Copy a block of text with visual mode
When you need to copy text that does not fit a straightforward pattern (like a sentence that spans two lines, or a paragraph with irregular breaks), use visual mode. Press v to enter visual mode, then move your cursor to select the text you want. Everything between your starting point and your cursor is highlighted. Once the text is selected, press y to yank it.
Visual mode has two other variants: V (capital V) selects whole lines at a time, which is useful for copying multiple full lines without counting them. Ctrl+V selects a rectangular block, which is helpful when copying columns of text or aligned code. After selecting in any visual mode, press y to copy.
Paste copied text with p and P
After you have copied text with any yank command, move your cursor to where you want to paste and press p. The text appears after your cursor position. If you want the text to appear before your cursor instead, press P (capital P).
For line-based copies (like yy), Vim is smart about where it pastes — p creates a new line below your cursor and pastes there, while P creates a new line above. For character or word copies, p and P insert the text inline at your cursor, which is why the distinction matters.
Check what you have copied with :reg
Vim keeps a history of recent copies in registers. To see what text is currently in your clipboard register, type :reg and press Enter. The register named " (the unnamed register) holds your most recent yank. Older copies are stored in numbered registers 0 through 9, with 0 being the second-most recent.
You can paste from an older register by typing "0p (paste from register 0) or "1p (paste from register 1). This is useful if you copied something, then copied something else, but now want to paste the first thing again. Named registers a through z let you store copies intentionally — press "ay to yank into register a, and "ap to paste from it later.
Frequently Asked Questions
How do I copy text from Vim into another program?
By default, Vim's yank command copies to Vim's internal clipboard, not your system clipboard. To copy text that other programs can paste, you need Vim compiled with clipboard support. Check by typing :echo has('clipboard') — if it returns 1, you have it. Then use "+y to yank into the system clipboard instead of y.
Can I undo a yank if I copied the wrong text?
Yanking does not change your file, so there is nothing to undo. If you copied the wrong text, just yank the correct text — it replaces what was in the clipboard. If you pasted the wrong text, press u to undo the paste.
What is the difference between yank and delete in Vim?
Yank (y) copies text without removing it from the file. Delete (d) removes text and also copies it to the clipboard, so you can paste it elsewhere. Both use the same movement commands — dd deletes a line, dw deletes a word — and both leave the text in a register.
How do I copy and paste between two Vim windows?
Yank in the first window with y, then move to the second window (using Ctrl+W and arrow keys) and paste with p. Vim's registers are shared across all open windows in the same session, so the text you copied stays available. If you close Vim and reopen it, the clipboard is cleared unless you use named registers to save it.