copy partial lines in VI

You can do yMovement, so for 10 characters: y10l yanks 10 characters from (and including) the current cursor position


I prefer just pressing the v key, then using the cursor keys to move your selection. Then press the y key when you satisfied to yank the selection.


I would guess the most common partial yanks are:

yaw: yank the word the cursor is currently in
2yaw: yank the word the cursor in currently in and the next (2 words total)
ya(: yank the matched parentheses containing the cursor
yf.: yank from the cursor to the next .
y$: yank from the cursor to the end of the line

Any movement keys can be used.


Cut and paste:

Position the cursor where you want to begin cutting.

  1. Press v to select characters (or uppercase V to select whole lines).
  2. Move the cursor to the end of what you want to cut.
  3. Press d to cut (or y to copy).
  4. Move to where you would like to paste.
  5. Press P to paste before the cursor, or p to paste after.
  6. Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:

d = delete = cut

y = yank = copy

Resource: vim.wikia.com: Copy, cut and paste

Tags:

Vi

Vim