How do I replace or find non-printable characters in vim regex?

前端 未结 6 1690
青春惊慌失措
青春惊慌失措 2021-01-30 07:09

I have a file with some non-printable characters that come up as ^C or ^B, I want to find and replace those characters, how do I go about doing that?

6条回答
  •  旧时难觅i
    2021-01-30 07:31

    Removing control symbols only:

    :%s/[[:cntrl:]]//g
    

    Removing non-printable characters (note that in versions prior to ~8.1.1 this removes non-ASCII characters also):

    :%s/[^[:print:]]//g
    

    The difference between them could be seen if you have some non-printable-non-control characters, e.g. zero-width space:

提交回复
热议问题