Paste multi-line string into GVIM at cursor position

copy-paste, keyboard-shortcuts, vim

Solution

First of all it seems CTRL-V is mapped to something because normally pasting in VIM is not done using CTRL-V (CTRL-V is visual block).

Second the behaviour you are seeing is standard vi[m] behaviour, if you yank one or more entire lines, pasting will always result in one or more lines above or below the current line.

I do not know of any builtin way to achieve what you are trying to do. But you could always remap CTRL-V to something that does do what you want, i.e.

:map <C-V> i<CR><Esc>"*P

After that pasting multiple lines will be between the characters your cursor was at, but this remapping probably is not what you want in other cases.

EDIT

OK, I found another way.

When in insert mode, type

CTRL-R *

this will paste the contents of the clipboard buffer at the location the cursor is at. (You can also use this to paste the contents of other buffers)

Problem

When I copy a two-line text from (e.g.) a PDF opened in Acrobat Reader into gvim using CTRL-V, the text is inserted above the line in gvim where I was positioned, instead of at the position where my cursor is. (scenario: I want to copy a document title that is spread over two lines and paste it in between a html tag in gvim). If I do the same with a single-line of text, the text is correctly pasted at the cursor's position. What should I do to make it also work with two-lines of text (e.g. something like 'paste without formatting')? Important: the string to be pasted consists of two lines separated by a carriage return (or something similar)! Solution There are actually two valid solutions: - using CTRL-R * to paste at the cursors position (and keeping the clipboard content multi-lined) - do a remapping of the paste command to replace all carriage returns in the clipboard string

Original source