Home » Software Development » Editor » Vim » Keyboard shortcuts for Cut, Copy and Paste in Vim Editor

Keyboard shortcuts for Cut, Copy and Paste in Vim Editor

In Last post “VIM : How to create a file and write contents using vim editor” we created a filename.c , Lets work on this same file to cut, copy and paste some lines / text as below.

Cut and Paste

  1. Position the cursor where you want to begin cutting.
  2. Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste).
  3. Move the cursor to the end of what you want to cut.
  4. Press d to cut
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.

Copy and Paste

Copy and paste is performed with the same steps except for step 4 where you would press y instead of d:

  1. Position the cursor where you want to begin cutting.
  2. Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste).
  3. Move the cursor to the end of what you want to cut.
  4. Press y to copy
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.

“d” stands for delete in Vim, which in other editors is usually called cut
“y” stands for yank in Vim, which in other editors is usually called copy

Copying and Cutting in normal mode

In normal mode, one can copy (yank) with y{motion}, where {motion} is a Vim motion. For example, yw copies to the beginning of the next word. Other helpful yanking commands include:

  • yy or Y – yank the current line, including the newline character at the end of the line
  • y$ – yank to the end of the current line (but don’t yank the newline character); note that many people like to remap Y to y$ in line with C and D
  • yiw – yank the current word (excluding surrounding whitespace)
  • yaw – yank the current word (including leading or trailing whitespace)

Pasting in normal mode

In normal mode, one can use p to paste after the cursor, or P to paste before the cursor.

Reference – http://vim.wikia.com/wiki/Copy,_cut_and_paste


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment