Vim regex to substitute/escape pipe characters

前端 未结 3 1322
栀梦
栀梦 2021-02-19 03:48

Let\'s suppose I have a line:

a|b|c

I\'d like to run a regex to convert it to:

a\\|b\\|c

In most regex engine

3条回答
  •  盖世英雄少女心
    2021-02-19 04:03

    vim has its own regex syntax. There is a comparison with PCRE in vim help doc (see :help perl-patterns).

    except for that, vim has no magic/magic/very magic mode. :h magic to check the table.

    by default, vim has magic mode. if you want to make the :s command in your question work, just active the very magic:

    :s/\v\|/\\|/g
    

提交回复
热议问题