I want to have a quick way of setting the Vim 'paste'
option, inserting some text, and reverting to the previous value of 'paste'
.
A typical use case insert the OS clipboard content literally, regardless of any insert mode rewriting that may be active, such as automatic indentation, and without changing the state of Vim. Another use case would be to allow an OS macro feature to inject keystrokes into Vim and have them interpreted as literal text.
This obviously generalizes to other options — the general idea is to set some options but only for the duration of one trip through insert mode.
Basically I want to bind a key sequence (say _i
) to a macro that does this
:set paste
i…<Esc>
:set nopaste
where by i…<Esc>
I mean switch to insert mode (as with the i
command) and resume the macro upon return to command mode, except that I want to end up with the 'paste'
still active if it was active beforehand. How can I do this?
Note: The content of the OS clipboard is mapped to the "*
register. When that works, the 'paste'
option isn't very useful. The motivating scenario for this question is for those times when the conditions for "*
register support are not met — Vim isn't compiled with the +xterm_clipboard
feature, or it's running in a terminal such as Screen or over SSH which isolates it from the ambient X server.
+
or*
register?