Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Search/replace: what do I need to escape?

Tags:

replace

vim

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

like image 319
Falassion Avatar asked Dec 16 '11 18:12

Falassion


People also ask

How do I search and replace an entire file in Vim?

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.

What's new in Vim?

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.

How do I Turn Off case sensitive search in Vim?

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.

How to do a granular find and replace in Vim?

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.


1 Answers

:%s/\$data\[\'user\'\]/$data['sessionUser']/g

I did not test this, but I guess it should work.

like image 164
cppcoder Avatar answered Oct 13 '22 21:10

cppcoder