Site icon LinuxCommands.site

vim tutorial: vim copy, cut and paste

Vim copy, cut and paste can help us quickly modify the file content.

This article will show you how to use vim to copy-paste and cut-paste in normal mode.

Copy and paste:

Cut and paste:

Examples
Copy and paste a line
  1. Open the terminal and use vim to open the test file: test.log
➜  ~ vim test.log

2. In normal mode, press yy to copy the line where the cursor is.

3. Press p to paste the copied line after the current cursor.

4. Type :x or :wq to save and exit.

Copy and paste all lines of text

Steps 1 and 2 are the same as above.

3. Press yG to copy all lines of text.

4. Press G to move the cursor to the last line, press p to paste the copied line.

5. Type :x or :wq to save and exit.

Cut and paste a word

Steps 1 and 2 are the same as above.

  1. Move the cursor to the word to be cut, and press the dw key.

4. Move the cursor to the position to be pasted, and then press p key.

5. Type :x or :wq to save and exit.

Exit mobile version