# Vim search and replace broken by at sign

It sometimes happens that I need to replace passwords in a number of Ansible vaults - a process that I don’t want to do manually.

In my case I wanted to apply the following change:

old: RUvyaZuG63SYnufWhUArrBSta
new: n5K3G_d@Q&YzMUnL


Replacing the string with one that contains an at sign @ resulted in a broken replacement:

# broken
Command: %s/RUvyaZuG63SYnufWhUArrBSta/n5K3G_d@Q&YzMUnL/g
Result: n5K3G_d@QRUvyaZuG63SYnufWhUArrBStaYzMUnL


Apparently the combination of vim and Ansible vault applies some unwanted vim magic that you can control as follows:

Info:
The :substitute command has the :smagic and :snomagic alternate forms (the same as \m and \M), so you can search and replace with %sno/regex/new_text/g

Since I only need a literal string replacement, I can turn off the magic by adding no to the substitute command:

# works:
- Command: %s/RUvyaZuG63SYnufWhUArrBSta/n5K3G_d@Q&YzMUnL/g
+ Command: %sno/RUvyaZuG63SYnufWhUArrBSta/n5K3G_d@Q&YzMUnL/g
Result: n5K3G_d@Q&YzMUnL