多行粘贴(ctrl-r)到ex或用\ r替换^ M

当我拖拉几行并将其粘贴到命令行时,每行都^M改为\r。例如,如果我在可视模式下复制下两行(使用命令Vjy):


line1

line2

并使用以下命令将其粘贴到命令行(搜索)模式/<c-r>":


/line1^Mline2

但我期望: /line1\rline2


我想做的是突出显示粘贴的字符串,这对粘贴代码块很有帮助。我知道我可以选择


`[v`] 

但是我只想突出显示它,并且无论如何它都可以通过将多行代码粘贴到ex中以替代或其他有趣的东西而有用。


小怪兽爱吃肉
浏览 240回答 2
2回答

慕标5832272

在可视模式下复制下一段:line1line2line3并将其粘贴到命令行中(带有<c-r>")应为line1^Mline2^Mline3^M。如果希望此文本为line1\rline2\rline3\r您可以定义以下函数并映射:function! Substitute()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; silent! let g:p=substitute(@", "\\n", "\\\\r", "g")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; call feedkeys(":", 'n')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;endfunction&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nnoremap <silent> : :call Substitute()<cr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;该命令let g:p=substitute(@", "\\n", "\\\\r", "g")将^M在未命名的寄存器(:help quotequote)中查找所有内容,将其替换为\r,然后将输出字符串存储在中p。要p在命令行中粘贴的内容,请使用<c-r>=p。
打开App,查看更多内容
随时随地看视频慕课网APP