1

I have bunch of strings that starts with uppercase letters. I want to change uppercase letters with lowercase letters. Strings are not aligned so visual block mode is not an option. Is it possible to use substitute to do this?

Before:

'Readable & writeable outside of effects'
'Multiple signal reads in same effect should only register once'

After:

'readable & writeable outside of effects'
'multiple signal reads in same effect should only register once'
1
  • In your example the letter to substitute is always the first of the line (contradicting the statement about their position). Maybe could you give us a better example to tune the proposed substitution expression. Commented Dec 20, 2022 at 18:42

2 Answers 2

6

You can use the \l or the ´\L´ operator in the substitution:

e.g.:

:%s/^\w\+/\l&/

will substitute the first letter of the first words of each line to its lowercase version.

:%s/'\(\_[^']*\)'/'\l\1'/g

will substitute the first letter of a quoted string to its lowercase version

5
  • 3
    :%s/'\u/\L& got the job done. \u matches uppercase letters
    – s1n7ax
    Commented Dec 21, 2022 at 8:53
  • @s1n7ax why is it L and not the lowercase l?
    – Wolfson
    Commented Jun 14, 2023 at 17:56
  • @s1n7ax what does the & do?
    – Wolfson
    Commented Jun 14, 2023 at 17:56
  • It is equivalent to \0. It stand for the matching string. Commented Jun 14, 2023 at 18:50
  • to replace KamelCase part, without quotes: %s/\([A-Z]\)/\l\1/cg
    – bcag2
    Commented Jan 17 at 15:07
-1

You can do this with the gu command and a motion: ggguG. To make everything uppercase, use: gggUG. Explanation (with mnemonic devices):

  1. gg go to the first row.
  2. gu go lowercase from here...
  3. G to the end of the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.