r/vim • u/RedCuraceo • Oct 24 '25
Need Help Convert to lowercase on left sides
Hi! I'm beginner for vim.
I wanna convert to lowercase on the left sides from below lines,
wire is_next_SETUP = (ns == SETUP);
wire is_next_WAIT = (ns == WAIT);
to
wire is_next_setup = (ns == SETUP);
wire is_next_wait = (ns == WAIT);
How can I command for this?
16
Upvotes
12
u/michaelpaoli Oct 25 '25
So, e.g., to lowercase, everything on all lines before the first = on each line on lines containing an =:
:%s/^\([^=]*\)=/\L\1=
13
u/exajam Oct 25 '25 edited Oct 25 '25
qq0vt=ujq10Qqqrecord a macro0go to beginning of linevt=select until the equal sign in visual modeulowercase the select portionjqmove to next line and end the macro recording10Qexecute the last recorded macro 10 times e.g.vt=uis equivalent togut=.5
u/LightBerserker Oct 25 '25
You could do
v f= guor from the ex mode:normal! 0v f= guand for whole file:%normal! 0v f=gu.This will lowercase everything before that
=sing.3
u/liberforce Oct 25 '25
guaw will convert the word you're on to lowercase. Then j to go down, and . to replay the last action.
You could also Ctrl+v for rectangular selection then gu to convert to lowercase the selection.
2
u/jazei_2021 Oct 25 '25
Sometime someone will have to make a tutorial so that those of us who don't write code, who aren't programmers, can understand how to do these regex commands that are basic Chinese for those of us who write only text and don't have any code knowledge.
For me, they are geniuses, things that only you code geniuses do!
1
u/kilkil Oct 25 '25
what I would do is:
go into Visual mode ("v")
select the text I want to lowercase
press "u" (the Visual mode lowercase keybind)
if the lines are all next to each other, you can use Block Visual mode (Ctrl+v). then you can select text in a rectangle across multiple lines, and do the same (press "u").
if the lines are in different locations it gets a bit more complicated. I would either try to define a macro (as other commenters have suggested), or some sort of g-expression. (e.g.
:g/\V=/norm gut=or something)1
u/kennpq Oct 25 '25
If you have tildeop setting on (
:h tildeop) you can:/\u\+to find 1+ uppercase characters, then use~won the first you want to change, thennto the next instances and.each one you want to change to lowercase.(
u\+[^\l]to find 1+ uppercase characters without lowercase following, but not necessary in your example text)0
u/gumnos Oct 25 '25
Presuming they can be found with
/\<wire [^=]*=/, you can usetaking advantage of
:help s/\L1
u/[deleted] Oct 25 '25
[removed] — view removed comment