Sean Lerner wrote:
Hi Tony and All,
Actually, it turns out the reason it's not working properly is because I
have :set paste turned on by default (which I need, as I'm always
pasting from windows aps into Vim).
And when :set paste is turned on, it literally types out whatever
function key was pressed --- so if I press F11, it types out <F11>
I was looking at the Vim doc, and it seems the only exception to this
Insert (paste) rule is the following:
:set pastetoggle=<F11>
That will turn paste mode off when in Insert (paste) mode.
Is there any work around so that I can always have paste mode on and use
mappings? I'm wondering, is it possible to trigger a function when
pastetoggle is executed?
Or is it possible to customize my paste mode -- i.e. have it work the
way it does, but not have it affect Function keys. I looked at :help
paste but the documentation is sparse, and doesn't elude to this.
Thanks for your help,
Sean
The purpose of the 'paste' option is not to allow pasting but to disable
mappings when pasting; so the answer starts with: ":set nopaste" (without the
quotes). However, if Vim can distinguish between typed text and pasted text
(and gvim usually can), it will still not apply mappings when pasting.
Pasting to and fro using the clipboard is done by means of the "+ register
(which, on non-X11 systems such as Windows, is synonymous with the "*
register). So,
:$put +
will insert the clipboard below the last line of the file, and
"+5yy
will yank 5 lines (starting at the current line) into the clipboard.
The 'pastetoggle' key cannot be remapped, since when 'paste' is ON, mappings
are disabled. But if you leave 'paste' at its OFF default, you can map any
function to any key:
:imap <F11> <C-O>:call MyPaste()<CR>
Best regards,
Tony.