How does vim paste code copied elsewhere?

I copied a piece of code on the web page and wanted to paste it into vim.
when pasting for the first time, the first few characters of the copied content are always lost, and then the second paste is normal. What is the reason?
below is < title > Hello, World! < / title > is the test result of the pasted content. If you paste it twice, you can see that the first time (the first two lines) is very strange, and the second time (the third line) is normal.

  1
  2 , world!</title>
  3 <title>Hello, world!</title>

the 1 2 3 on the left is the line number

Mar.04,2021

simple reason: you try to edit the file without entering edit mode, resulting in unexpected results.

specific reason:

  1. you have opened vim, while vim is in normal mode .
  2. you pasted < title > Hello, World! < / title > , which is equivalent to applying to vim to execute the instruction, and vim will execute it in sequence. In normal mode, and indicate indentation, but because you don't select the text, nothing happens. The title between the two brackets is invalid. Hell will not have a concrete effect either. But when o is executed, o means that the next line of the cursor enters insert mode , and the rest is treated as inserted text. So the first line in your file is a blank line, and the second line is the content after o , that is, , World! < / title >
  3. because the above action has put vim into insert mode , and you did not click ESC to exit this mode, so when you continue with the second paste, the insert operation will be performed directly, and the line will be fully inserted.

question:
if there is no other action between two pastes, there should not be another line when pasting the second time. I guess you should type a carriage return and paste.

suggestion:
learn the basics of vi operation.


press insert to enter edit mode, and then press shift+insert to paste the content.


when you open vim, it defaults to command mode.

  • set paste mode
    if you want to paste as is, press : in command mode, the colon appears in the lower left corner, enter set paste to set it.
  • enter edit mode

    • I starts to enter edit mode at the cursor
    • a starts at the next character in the cursor position (invalid if there is no content) and enters edit mode
    • o move the cursor to the beginning of the next line and enter edit mode

enter edit mode and paste directly using shift+insert .
if you need to return to command mode again, press Esc.


maybe some characters have been translated into vim instructions

I am all : rattlecat sticky


Open clipboard in the settings. You can share the pasteboard with the outside world.
use "+ y" to copy the contents of vim and paste them directly outside.
external assignments, use "+ p" to paste in the file edited by vim.


use the document key under keyboard enter + p

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e95964-156e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e95964-156e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?