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

How To Sort Alphabetically - MS Exc... x
How To Sort Alphabetically - MS Excel

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux