I'm trying to search and replace $data['user']
for $data['sessionUser']
.
However, no matter what search string I use, I always get a "pattern not found" as the result of it.
So, what would be the correct search string? Do I need to escape any of these characters?
:%s/$data['user']/$data['sessionUser']/g
If you want to search an entire file, you can use % to indicate that as the range: :%s/ search / replace /g You may also wish to be asked for confirmation before Vim makes a substitution. To do this, add the confirm (c) option to the end of the search and replace command: :%s/ search / replace /gc.
The good new is: Vim search features are pure awesomeness. With a minimum of configuration, you can search whatever you want, wherever you want, at light speed. We’ll see in this article how to: Search in the current file. Search in multiple files. Find and replace everything you dream of.
If you want to ignore the case, here you go: /search\C - Case-sensitive search. /search\c - Case-insensitive search. You can as well write the following command in your vimrc: set ignorecase - All your searches will be case-insensitive. set smartcase - Your search will be case-sensitive if it contains an uppercase letter.
With this technique, you can do a granular find and replace in the whole file. To find and replace in multiple files, you can use the excellent Vim arglist. Think of it as an internal list of files you can modify.
:%s/\$data\[\'user\'\]/$data['sessionUser']/g
I did not test this, but I guess it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With