Linux Vi Cut Copy And Paste

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

vi cut, copy and paste (Line)

In command mode, you can cut, copy and paste a line with the following commands.

cut

dd

The command dd deletes current line completely.

Example:

Linux Cut Copy Paste1

Look at the above snapshot, our cursor is at line third. We want to delete this whole line.

Linux Cut Copy Paste2

Look at the above snapshot, after pressing dd command, third line is deleted.

copy

yy

The command yy (yank yank) is used to copy a line. Move the cursor to the line you want to copy and then press yy.

paste

p

The p command paste a copied or cut content after the current line.

Example:

Linux Cut Copy Paste3

Look at the above snapshot, this is our original script.

Linux Cut Copy Paste4

Look at the above snapshot, first we have copied the second line using yy, then press p. Copied line will paste after the current line.

P

The P command paste a copied or cut content before the current line.

Example:

Linux Cut Copy Paste5

Look at the above snapshot, this is our original script.

Linux Cut Copy Paste6

Look at the above snapshot, after copying the content using yy, we moved the cursor to first line and then pressed P. Line is copied before the current line.