Skip to content
Log In Sign Up info@muvcloud.com

Copy and Paste a Line

  1. Press Esc to be in normal mode.
  2. Put the cursor on the line and press yy.
  3. Move to where the copy should go and press p.

p pastes a copied line below the cursor line; P pastes it above. A count works as usual: 3yy copies three lines, and 3p pastes the copy three times.

Copy Words and Parts of Lines

KeysWhat it copies
ywTo the start of the next word
yiwThe word under the cursor
y$To the end of the line
y0To the start of the line
yGTo the end of the file

When the copy is part of a line, p pastes it after the cursor and P before it. In Vim, Y copies the whole line like yy; in Neovim, Y copies to the end of the line.

Select with Visual Mode

  • v: selects character by character.
  • V: selects whole lines.
  • Ctrl+v: selects a rectangular block, useful for columns.

After pressing one of them, move the cursor with the arrow keys, j, k, or a search. Then press y to copy or d to cut. Esc leaves visual mode without doing anything.

Cut and Paste

Vim has no separate cut command: every delete saves the text, so a delete is a cut. dd cuts a line, dw a word, and d in visual mode the selection. Then paste with p. To move a line down by one, press ddp. More delete commands are in how to delete a line in Vim.

Registers

Vim stores copied and deleted text in registers, named by a character. Put a double quote and the register name before the command:

"ayy
"ap
:registers
  • Unnamed register: used by every y, d, and p without a name.
  • "0: holds the last copy. A delete does not overwrite it, so "0p pastes what you copied even after you deleted something.
  • "a to "z: named registers that keep text until you replace it.
  • "_: the black hole; "_dd deletes without saving the text.

:registers (or :reg) shows what each one holds. In insert mode, Ctrl+r followed by a register name, such as 0, pastes it at the cursor.

Paste from Your Own Computer over SSH

When Vim runs on a server, text you paste with your terminal's paste command arrives as if you typed it. With automatic indenting on, each pasted line can be indented further than the one before. Current Vim versions use bracketed paste when the terminal supports it, which avoids this. If the indent still breaks, turn on paste mode while you paste:

:set paste

Then press i, paste, press Esc, and turn it off again with :set nopaste. Paste mode disables indenting and some mappings while it is on. Neovim handles pasted text on its own and does not need it.

The System Clipboard

The registers "+ and "* are the system clipboard, and they work only when Vim was built with clipboard support. Check with:

vim --version | grep clipboard

+clipboard means support is built in; -clipboard means it is not. On a server over SSH, the clipboard would be the server's, not yours, so it does not help there. To copy from the server to your computer, select the text with your terminal's mouse selection; turn off line numbers with :set nonumber first so they are not copied. If you are stuck in a mode, see how to save and quit in Vim, and to step back after a bad paste, undo with u.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations