I have 'a
and 'b
bounding some lines of text. I want to convert all the w
, h
, n
, and m
variables to upper case. A sample line:
f(w,h,n,m) | w <= 0 | h <= 0 | n < 0 | m < 0 = 0
It seems to me that this should work:
:'a,'b g/\<[whnm]\>/normal ~
This doesn't work. It matches the line, but does not match the individual variables. It leaves the cursor at the beginning of the line and capitalizes the f
there. How do I make it perform the ~
action at every match in the range?
I know this particular example can be done simply with a regex substitution. I don't want to do that. I want to run an arbitrary command at every location that matches a search pattern, which seems like something obvious to do, but so far appears impossible to do in vim.
:global
operates on entire lines only, and not the matching part. So you're running~
for every line (which should convert the first character,f
, toF
). No time to write a more expanded answer right now, but at least you know your problem ;-)