Search code examples
solarisvi

How can I replace a string with special characters in vi?


How can you replace all occurrences of the string zUe*ES33Na with 8!fifHsgx in vi?

I tried using :%s/zUe*ES33Na/8!fifHsgx/g but it said substitute pattern match failed.

I have a feeling it is because there are 'special' characters that I'm trying to search for or replace with.

Basically is there a way to indicate to vi to interpret the characters as search characters and not as special characters?

This is for editing a file with passwords in it.

I got the same error when trying to replace the first string above with something simple like AAAAAA:

:%s/zUe*ES33Na/AAAAAA/g

so I have a feeling the * is causing an error.

Do I have to escape the * or can I somehow indicate to vi not to interpret it as containing special characters, by ,say, something like surrounding it with quotes?


Solution

  • Use \ escape character

     :%s/zUe\*ES33Na/8!fifHsgx/g