Vim/Vi Copy Line

Vim or Vi provides different keys and commands in order to copy the line. In this tutorial, we will learn how to copy lines in different ways.

Copy Current Line

The yy keys are used to copy the current line. The current line means where the cursor is located currently. Follow these steps to copy the current line.

  • Press the ESC key in order to change normal mode.
  • Press yy keys in order to copy the current line where the cursor is located.

Copy First Line Of The File

We can copy the first line of the file. Even when the file is opened for the first time the cursor will be located at the start of the first line. But during usage, we will move the cursor into different lines. We may want to copy the first line from the locations and lines in a file.

  • Press the ESC key in order to change normal mode.
  • First press the gg keys to move the first line and then press yy keys in order to copy the current line where the cursor is located.

Copy Last Line Of The File

We can copy the last line of the file. Even when the file is opened for the first time the cursor will be located at the start of the first line. But during usage, we will move the cursor into different lines. We may want to copy the last line from the locations and lines in a file.

  • Press the ESC key in order to change normal mode.
  • First press the G key to move the last line and then press yy keys in order to copy the current line where the cursor is located.
READ  chmod Recursively - Change Files and Folders Permissions Recursively In Linux

Paste Copied Line

Lines are generally copied in order to paste naother location So after the copy operation we can paste the line to the cursor current location.

  • Press the ESC key in order to change normal mode.
  • First press the p key in order to paste the copied line into the current location where the cursor is located.

Leave a Comment