If your Vim has access to the X selection / system clipboard, you can just paste via <C-r>*
/ <C-r>+
in insert mode, or directly in normal mode via "*p
/ "+p
.
Only if that isn't working you need to :set paste
, as Vim otherwise cannot tell whether you've typed this (very quickly), or pasted it. Because any keyboard action could be from the input, it's hard to automate this, but Vim fortunately offers the 'pastetoggle'
option to make the switching faster:
'pastetoggle' 'pt' string (default "")
global
{not in Vi}
When non-empty, specifies the key sequence that toggles the 'paste'
option. This is like specifying a mapping:
:map {keys} :set invpaste<CR>
Where {keys} is the value of 'pastetoggle'.
The difference is that it will work even when 'paste' is set.
'pastetoggle' works in Insert mode and Normal mode, but not in
Command-line mode.
For example, with :set pastetoggle=<F11>
, you just need to i<F11> (paste) <F11><Esc>
.