如何在不覆盖寄存器的情况下粘贴 [英] How to paste over without overwriting register
问题描述
有谁知道有一种方法可以粘贴到视觉上选择的区域而不将选择放置在默认寄存器中?
Does anyone know of a way to paste over a visually selected area without having the selection placed in the default register?
我知道我可以通过始终从显式寄存器粘贴来解决问题.但是键入 "xp 而不是 p
I know I can solve the problem by always pasting from an explicit register. But it's a pain in the neck to type "xp instead of just p
推荐答案
"{register}p
不会像你描述的那样工作.它将用寄存器的内容替换选择.你将不得不做类似的事情:
"{register}p
won't work as you describe. It will replace the selection with the content of the register. You will have instead to do something like:
" I haven't found how to hide this function (yet)
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
" NB: this supports "rp that replaces the selection by the contents of @r
vnoremap <silent> <expr> p <sid>Repl()
只要您不使用具有非 nore vmap 到 p 并且期望寄存器被覆盖的插件,这应该没问题.
Which should be fine as long as you don't use a plugin that has a non-nore vmap to p, and that expects a register to be overwritten.
此代码可用作脚本 那里.Ingo Karkat 还定义了一个 插件来解决同样的问题.
This code is available as a script there. Ingo Karkat also defined a plugin solving the same issue.
这篇关于如何在不覆盖寄存器的情况下粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!