Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only lowercase quoted string in VIM

Say I have a file with the following content:

Apple 'BANANA' ORANGE 'PEACH'

What is the regex to convert all quoted uppercase to lowercase?

The expected output file should look like:

Apple 'banana' ORANGE 'peach'
like image 269
Mingyu Avatar asked Aug 21 '13 00:08

Mingyu


1 Answers

Try

:%s/'\w\+'/\=tolower(submatch(0))/g

'\w\+' match any word that is inside quotes. and replace it with the lowercase version of the match. \= tells substitute to evaluate the expression tolower(submatch(0)) where tolower() switches the string found in submatch(0) (the whole match) to lower case.


You can also use the \L atom to turn the string after it to lower case and \0 is the same as submatch(0)

:%s/'\w\+'/\L\0/g

Take a look at :h s/\L

like image 170
FDinoff Avatar answered Sep 20 '22 03:09

FDinoff