Vim provides different shortcuts for copy, cut, and paste operations. These commands are one of the most used and problematic commands because of vim command or shortcut based work style.
Copy Current Line
We can copy the current line with the
yy command which is named yank. But the cursor should be located in the line we want to copy.
We will again use
yy command in order to copy multiple lines. But in this situation, we should specify the range or line counts. We will provide the line count we want to copy between y’s . In this example, we will copy 5 lines from the current cursor.
We can copy the next word where cursor locates with
yw command. Words are separated with spaces.
Cut Current Line
We can use
dd command in order to cut the current line. dd command is actually used to delete line but after delete operation, the deleted line will be put into the buffer where we can use and put the line with
Cut Multiple Lines
We can cut multiple lines with
dd command. In this example, we will cut 10 lines by putting 10 between
d commands. Cut start location is the cursor location.
We can cut word which is next one with
dw command. It is a modified version of the dd command where second d is changed with the w which is for word.
Cut and copy operations will put the content into the buffer. This buffer will be used to paste the text. We will use p key in order to paste the last item in the buffer like below.