0

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. Dec 20, 2022 at 18:42

2 Answers 2

4

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

4
  • 3
    :%s/'\u/\L& got the job done. \u matches uppercase letters
    – s1n7ax
    Dec 21, 2022 at 8:53
  • @s1n7ax why is it L and not the lowercase l?
    – Wolfson
    Jun 14 at 17:56
  • @s1n7ax what does the & do?
    – Wolfson
    Jun 14 at 17:56
  • It is equivalent to \0. It stand for the matching string. Jun 14 at 18:50
-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 that you have read and understand our privacy policy and code of conduct.

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