Vim / vi Editor Commands for Copy / Paste and Delete

Vim is a beautiful editor in linux / unix operating system. The vim editor has got lot of in-built commands for doing numerous operations. In this article, we will see the copy, paste and delete operations of Vim Editor.

Note: Run all the commands in Escape mode. Press ESC button and then type the following commands.

Copy a Line:

yy: The yy command copies the current line in the file.

Pasting a line:

The P and p are used to paste lines before and after the current line.

p: Pastes the line after the current line.

P: Pastes the copied line before the current line.

Delete Operations:

You can do lot of delete operations in vi editor like removing a single character, entire line, word etc.

d^: Delete all the characters from the current position of the cursor to the beginning of the line.

d$: Remove all the characters from the current cursor position to the end of the line.

dd: Deletes the current line.

dw: Deletes characters from the current cursor position to the end of the word.

x: Removes a single character where the cursor is placed.

X: Removes a character to the left of the cursor

Undo the Changes:

You can revert the changes done to the file by using the undo operations.

u: Undo the last edit.

U: Revert only the changes made to the current line.

In the Vi / Vim editor, you can do lot of operations apart from these. The copy and paste commands mentioned here are just basic. You can do lot more in Vim editor.

If you have any questions or you want to share any vim editor tips, you can comment here.