对于我来说,将文本复制到剪贴板并用其他内容替换所有出现的文本是非常典型的。我不知道如何使用Vim :substitute
这样做。您可以使用 Ctrl + R Ctrl + R register
插入寄存器的内容,但是你仍然需要逃避文本,我找不到任何合理的方法来使用多行文本。
假设您要将FROM @SERVER: PING :/\SERVER<CR>command: ping, source: None, target: @SERVER, arguments: ['@SERVER']
注册q
中的ACK @SERVER1
替换为以下文字中的FROM @SERVER: PING :/\SERVER
command: ping, source: None, target: @SERVER, arguments: ['@SERVER']
TO @SERVER: PONG SERVER
FROM @SERVER: PING :/\SERVER
command: ping, source: None, target: @SERVER, arguments: ['@SERVER']
TO @SERVER: PONG /\SERVER
FROM SERVER: user2 PRIVMSG !CNL :#user1: what's up?
command: pubmsg, source: #user2, target: !CNL, arguments: ["#user1: what's up?"]
FROM @SERVER: PING :/\SERVER
command: ping, source: None, target: @SERVER, arguments: ['@SERVER']
TO @SERVER: PONG /\SERVER
FROM @SERVER: PING :/\SERVER
command: ping, source: None, target: @SERVER, arguments: ['@SERVER']
TO @SERVER: PONG /\SERVER
:
示例文字:
{{1}}
答案 0 :(得分:1)
如果您的示例的前两行在默认寄存器中(例如通过y2$
),您可以构建如下的替换命令:
:%s/\V<C-r>=substitute(escape(@@, '/\'), '\n', '\\n', 'g')<CR>/REPLACEMENT/g
它的作用:
\V
/
的{{1}}分隔符也是:substitute
正则表达式原子\n
和表达式寄存器