showkey
showkey

Reputation: 298

Why i get different result in vim between `"+p` and `paste`?

I want to paste something from web into vim .

1.select the content which i want to paste.
please attachment

enter image description here

2.the sentence2 which i paste with method clipboard

enter image description here enter image description here

3.compare the sentence2 which i paste with method :+p enter image description here why sentence1 lost the letter C ?this is the only different place.

Upvotes: 1

Views: 375

Answers (2)

timss
timss

Reputation: 10270

Normally you don't want Vim to interpret whatever you're pasting from your system clipboard, only typed text. However Vim can't know the difference between pasted and type text in all scenarios, especially in a terminal. Using the paste mode will disable any interpreting, i.e. formatting, autocomplete by plugins or even commands, of the text pasted.

From :h paste:

        Put Vim in Paste mode.  This is useful if you want to cut or copy
        some text from one window and paste it in Vim.  This will avoid
        unexpected effects.
        Setting this option is useful when using Vim in a terminal, where Vim
        cannot distinguish between typed text and pasted text.  In the GUI, Vim
        knows about pasting and will mostly do the right thing without 'paste'
        being set.  The same is true for a terminal where Vim handles the
        mouse clicks itself.

Toggle paste mode using pastetoggle:

set pastetoggle=<F3>

Upvotes: 0

Kevin
Kevin

Reputation: 56129

When you use "+p, vim pastes the contents of the + buffer. But when you paste from the clipboard, the terminal emulator passes vim each of the letters as input, as if from the keyboard. It so happens that the first letter of your pasted content is C, which causes vim to cut from the cursor to the end of the line and enter insert mode, so you only lose that one character. When pasting from the clipboard (either by the menu as you did or ctrl-v) you need to go to insert mode first. And depending on what you're pasting, you may want to :set paste, to prevent bindings and formatting from taking effect (use :set nopaste to turn it off).

Upvotes: 6

Related Questions