Pasting from the clipboard and automatically toggling ":set paste"

I have the following in my .vimrc:

inoremap <S-Insert> <ESC>:setl paste<CR>gi<C-R>+<ESC>:setl nopaste<CR>gi

gi is to start insert mode in the same position as where insert mode was stopped last time in the current buffer.

Update:

Jefromi posted a better solution. I have tinkered it a bit

inoremap <S-Insert> <ESC>"+p`]a

It inserts clipboard text and places the cursor right after it.


I don't use a mac, but I believe I have the prefix right here: <D-v> should mean cmd-v. For insert mode:

:imap <D-v> ^O:set paste<Enter>^R+^O:set nopaste<Enter>

or really, just do this:

:imap <D-V> ^O"+p

The ^O and ^R are literal control-O and control-R, which you can type with ^V^O (control-v control-o) and ^V^R (control-v control-r). Control-O in insert mode allows you to execute one command then return to insert mode; here you can use it to put from the clipboard register.

This worked for me when I tested them mapped to a different key, so you should be all set.

There's no need to map anything when not in insert mode; you can just use "+p.

Tags:

Vim

Paste