Why does shift insert only work fully in insert mode?

Just tried pasting some content (in Git Bash on CentOS server) into a file using vim.
I just opened the file and tried using shift+insert and I noticed that the first half (roughly) gets cut off, but if I set vim to insert mode and hit shift+insert everything gets pasted perfectly.
Was just wondering why this is?

Thanks


Both Shift + Insert and "pasting" into a terminal behave in a similar way - they emulate key presses.

This is an important distinction that is often impossible for terminals to make - are you typing or pasting? Note: some terminals support "bracketed paste" modes, after @Josh's comment I even came across a vim plugin bracketed paste in xterm which you may be interested in.

Your pasted data will be lost up to the first character that enters an insert mode. You may also find that your cursor has moved and that other parts of the file have changed (e.g: changed case / been deleted / etc)...

In summary, if you're pasting text that you want inserted into the file, enter insert mode first.


Try copying the following text and paste it into a terminal running Vim (not in insert mode):

hello how are you

The result is the same as typing the same letters on your keyboard:

result of pasting into Vim

In this case, it leaves you in insert mode...

Now try exiting insert mode - Esc - and pasting the following

/are
n

This performs a search for "are":

result of pasting into Vim

Now paste this:

:0
dG

Oh no... everything is gone!

all gone


You will also find that if you have indenting enabled, then pasting a block of code into vim (in insert mode) will indent too much - it'll auto indent, and then your pasted code will include indentation.

def my_print(message):
    print(message)
    print('done...')

pasting code

To fix this, use the :set paste and :set nopaste commands

pasting code (paste mode)