ubuntu, updated

Vim: copy and paste

Yank and put inside vim, select lines and blocks, and paste from your computer into vim over SSH without broken indentation.

Vim words

Vim calls copying yank (y) and pasting put (p). Deleting with d also copies, so “delete” is really “cut”.

Inside vim (normal mode)

WhatKeys
Copy the lineyy
Copy 5 lines5yy
Copy a wordyw
Copy to the end of the liney$
Copy the whole fileggyG
Cut the linedd
Paste after / before the cursorp / P
Paste a line below / abovep / P (after yy or dd)

With a selection (visual mode)

  1. Move to the start.
  2. Press v (characters), V (whole lines) or Ctrl+V (a rectangular block).
  3. Move to extend the selection.
  4. Press y to copy, d to cut, > to indent.
  5. Go to the target and press p.

Block selection example: comment out lines 10 to 20.

:10           go to line 10
Ctrl+V        start a block
10j           extend 10 lines down
I             insert at the start of each line
#             type the character
Esc           apply to all lines

Copy lines by number

WhatCommand
Copy lines 10 to 20 below line 30:10,20t30
Move lines 10 to 20 below line 30:10,20m30
Delete lines 10 to 20:10,20d

Paste from your computer over SSH

Pasting into a terminal is just fast typing. In insert mode vim’s auto-indent then adds indentation to every line, and your YAML ends up as a staircase.

FixHow
Paste mode:set paste, i, paste, Esc, :set nopaste
Most modern terminalsAlready handled (“bracketed paste”, vim 8+). Try a normal paste first.

Copy from vim to your computer

Over SSH, vim can’t reach your computer’s clipboard. Two simple options:

On a desktop with vim-gtk3 installed, "+y copies to and "+p pastes from the system clipboard.

Registers (the short version)

Vim has many clipboards called registers. :reg shows them. Useful one: "0p pastes the last yank, even after you deleted something in between (a delete overwrites the default register, not register 0).

§ home
~/knubertus/home/
1,1 Top