什么" r"在vim搜索和替换命令结束时做什么?

时间:2014-12-27 03:19:56

标签: regex vim

r在此vim搜索和替换命令结束时执行了什么操作::%s/foo/bar/r

1 个答案:

答案 0 :(得分:2)

要在最后找出 r 的含义,只需在:help :substitute中输入vim

[r]     Only useful in combination with `:&` or `:s` without arguments.  `:&r`
        works the same way as `:~`:  When the search pattern is empty, use the
        previously used search pattern instead of the search pattern from the
        last substitute or `:global`.  If the last command that did a search
        was a substitute or `:global`, there is no effect.  If the last
        command was a search command such as "/", use the pattern from that
        command.
        For `:s` with an argument this already happens: >
                :s/blue/red/
                /green
                :s//red/   or  :~   or  :&r

因此,在您的情况下,命令:%s/foo/bar/r:%s/foo/bar/具有完全相同的效果,这会将foo的第一次更改为bar }在包含搜索模式的每一行(这里都是foo