How do I copy selected text to the clipboard in visual mode?
Answer
y (in visual mode)
Explanation
In visual mode, pressing y yanks (copies) the selected text into the default register. You can then paste it elsewhere with p.
How it works
- Select text with
v,V, or<C-v> - Press
yto yank the selection - The cursor returns to the start of the selection
- Paste with
p(after cursor) orP(before cursor)
Example
Select a paragraph with Vip, press y to copy it. Move to the target location and press p to paste.
Tips
"+yyanks to the system clipboard"ayyanks to named registera- After yanking, the selection is stored in both
"and0registers gvreselects the yanked area if you need to see it again- Visual yank is more intuitive than operator-based
yiwfor beginners