How to only lowercase quoted string in VIM

前端 未结 1 1758
既然无缘
既然无缘 2021-01-18 19:48

Say I have a file with the following content:

Apple \'BANANA\' ORANGE \'PEACH\'

What is the regex to convert all quoted uppercase to lowerc

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 20:39

    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

    0 讨论(0)
提交回复
热议问题