Vim regex to substitute/escape pipe characters

前端 未结 3 1336
栀梦
栀梦 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:08

    Vim does the opposite of PCRE in this regard: | is a literal pipe character, with \| serving as the alternation operator. I couldn't find an appropriate escape sequence because the pipe character does not need to be escaped.

    The following command works for the line in my example:

    :. s%|%\\|%g
    

提交回复
热议问题