Reputation: 5767
Based on the idea of quick command in insert mode I want to insert my OS clipboard when I am in the insert mode. To make that happen as I want, I have to add a whitespace in the inoremap
call, but I do not know how?
This is done with
inoremap VV <Esc>"+gP
Using this:
leads to the result
work smart withvim
What I want is a whitespace between with and vim
work smart with vim
Any suggestions?
Upvotes: 0
Views: 565
Reputation: 3387
Option 1.
inoremap VV <C-R><C-o>+
Ctrl-R
tells vim to insert the contents of a register, and +
is the OS clipboard register. It inserts the clipboard contents as if you typed them. The additional <c-o>
makes the register contents get inserted literally, so that things like <esc>
or ^H
(backspace) aren't interpreted like you typed them, but are inserted as text.
Option 2.
inoremap VV <C-o>"+gp
C-o
tells vim to go to normal mode for just one command, so you don't need to add <Esc>
at start, or i
at the end.
Upvotes: 0
Reputation: 196546
Your issue is caused by the P
in "+gP
and by the fact that leaving insert mode moves the cursor one character to the left, on the <space>
.
P
pastes before the cursor so your mapping pastes before the <space>
. Changing the P
to p
should "fix" your problem, in a superficial way.
Here is a more solid alternative that inserts the content of the clipboard register right after the cursor without leaving insert mode:
inoremap VV <C-r>+
Well… what about simply using <C-r>+
?
Working around a side effect (here, pasting after the cursor) is not the same as avoiding that side effect (here, not leaving insert mode to begin with). Guess which one is the right approach? ;-)
Upvotes: 5
Reputation: 2053
Use
inoremap VV <Esc>"+gp
P
places the clipboard before cursor, p
after cursor.
Upvotes: 1