orestiss
orestiss

Reputation: 2283

How can I find and replace all occurrencies of a character in vim?

I have a strange character in a text, how can I find all of its occurrences and replace it with another character?

I know that if you need to do the same thing with a word you can use * and then :%s//replacement/g to replace all occurrences,

is there something similar for characters?

Upvotes: 1

Views: 203

Answers (3)

robbyphillips
robbyphillips

Reputation: 971

  1. Yank the character into a register (a in this case): "ayl

  2. Start your substitute command :%s/

  3. Use <C-r> a to paste the register into the command line.

  4. Finish your command and execute: :%s/<char>/<new-char>/g

Upvotes: 1

Alon
Alon

Reputation: 791

Use the command:

%s/a/A/g

which replaces a with A. For some more examples of the %s command take a look here.

Upvotes: 0

Peter Foti
Peter Foti

Reputation: 5654

Do you know how to type out the character? If so you can do :%s/<char-to-replace>/<char-to-replace-with/g

Upvotes: 0

Related Questions