Javatpoint Logo
Javatpoint Logo

vi cut, copy and paste a line in blocks

TIn command mode, if you want to delete, cut or copy n number of lines, just type the number before typing the command. For example, 4dd will delete four number of lines from the current line to the next three lines in downward direction.

In case of yy command, command will be noted by vi. For example, if we have given command 4yy then at the bottom left corner, vi will show a message as "4 lines yanked".

Cut

ndd

Here n denotes a number. It will delete n number of lines after the current line.

Example:

2dd

Linux Cut Copy blocks1

Look at the above snapshot, this is our script and we want to delete first two lines.

Linux Cut Copy blocks2

Look at the above snapshot, after typing 2dd, two lines after the current lines are deleted.

Copy

nyy

The command nyy is used to copy n number of lines after the current line.

Example:

2yy

Linux Cut Copy blocks3

Look at the above snapshot, we want to copy two lines after the first line.

Linux Cut Copy blocks4

Look at the above snapshot, after pressing 2yy, last two lines are copied and with P key we have pasted them before the first line.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA