Tags: #vim #search #replace #args #case #lower #upper
Imagine we have a file containing…
from foo import Bar
We want Bar to be bar.
We could do that across all files like so:
:args
:args **/*.py
:argdo %s/\v(from foo import )B(ar)/\1b\2/e | update
eflag tells Vim to ignore any errors
Alternatively instead of hardcoding the lowercase b we could have done this dynamically using either \l which lowercases the first character inside of a backreference or \L which lowercases the entire backreference (Reference).
Examples…
:argdo %s/\v(from foo import Bar)/\L\1/e | update
:argdo %s/\vfrom foo import (B)ar/\l\1/e | update
:argdo %s/\vfrom foo import (*+)/\l\1/e | update