VIM : 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:

Position the cursor where you want to begin cutting.
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).
Move the cursor to the end of what you want to cut.
Press d to cut (or y to copy).
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.

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

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)

SHUFFLED :   Click to Chat : How to open WhatsApp chat from website button

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

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded
Tags: ,

Leave a Reply