In VIM we perform the copy operation using the y command. This copies the content to a buffer much like a clipboard and then we paste the text we copied using the p command to paste the content after the cursor position and the P command to paste the content before the cursor position. The d command not only deletes but also cuts the text which can be pasted later.
Press the Escape [Esc] key to enter into command mode.Type yy to copy the current line.
Say we are currently at line number 2 and want to copy from line number 2 to line number 5, i.e., a total 4 lines (2nd, 3rd, 4th and 5th). For this we have to do the following.
Press Escape [Esc] to enter into command modeMove the cursor to line number 2Type 4yy to copy the current line and the next 3 lines.
To copy from current cursor location to the end of the vim we that to type y$ command in command mode.
To copy from the current cursor position to the beginning of the line in vim we have to use the y0 command in command mode.
Press Escape [Esc] to enter into command modeType yG to copy from the current line to the end of the file.
Press Escape [Esc] to enter command modeMove the cursor the the desired lineType ynG to copy form the current line to the nth line of the file where n is an integer value denoting the line number.
For example, if we are at the 4th line of the file and want to copy till the 8th line we will type y4G.Similarly, if we are at the 6th line and want to copy up to the 3rd line we will type y3G.
Copyright © 2014 - 2017 DYclassroom. All rights reserved.
rendered in 0.0717 sec