search

Home  >  Q&A  >  body text

How to use VIM replacement to use the hit part in the pattern string

The description of the problem is rather obscure, so I will give an example directly
There is a file like this

A1
A2
A3

hopes to be replaced with

F1B1
F2B2
F3B3
How should

be written?

给我你的怀抱给我你的怀抱2773 days ago710

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-16 16:44:43

    vim’s regular expressions are quite special, see http://vimregex.com/, but it supports back references, but you need to use escaped brackets (),然后在替换部分依序引用(如, 1).

    :%s:A\(\d\+\):FB:g

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 16:44:43

    :%s/A(d+)/F1B/g
    You can use regular expressions after escaping

    reply
    0
  • Cancelreply