Vim regular expression for fixing associative arrays
Posted: Tue Feb 19, 2013 2:47 am
I've been assigned a project that have associative arrays without single quotes all over the place.
Example:
$foo[bar]
Which should be:
$foo['bar']
This generates a PHP notice and it's very bad practice.
With this command in Vim I can replace all "foo" instances with "bar" in the current directory and subdirectories
:args **/*.php | argdo %s/foo/bar/ge | write
I would like to apply the same principle with a regular expression in order to fix the associative arrays.
So instead of 'foo' there should be a regular expression that finds associative array keys and instead of "bar" another regular expression that inserts single quotes.
Any suggestions?
May be this request for help is too difficult or not even possible, in that case I would take any recommendation on how to approach this problem.
Example:
$foo[bar]
Which should be:
$foo['bar']
This generates a PHP notice and it's very bad practice.
With this command in Vim I can replace all "foo" instances with "bar" in the current directory and subdirectories
:args **/*.php | argdo %s/foo/bar/ge | write
I would like to apply the same principle with a regular expression in order to fix the associative arrays.
So instead of 'foo' there should be a regular expression that finds associative array keys and instead of "bar" another regular expression that inserts single quotes.
Any suggestions?
May be this request for help is too difficult or not even possible, in that case I would take any recommendation on how to approach this problem.