VIM search and replace special characters
vim is a wonderful text editor. Wait. What? emacs? who uses that anyhow… 😉
I recently needed to do a quick search and replace on ALL punctuation within a file and decided to use vim in combination with regex to complete the task and post a quick how-to here.
First, open the text file with vim as you normally would (kinda required right?)
Now use the vim command line by invoking the colon
Now use the regex search (see command below) and note that you need to use the
\ escape character or you’re going to end up with everything replaced vs just your punctuation (yes, that is the voice of experience).
In the above example all periods are replaced with underscores while leaving all other aspects of the file untouched. Simple right?