I want to change a large group of identifiers from lower-case to upper-case. I have a file with a number (hundreds or so) of unique identifiers that start with a q_
. I constructed a regex that defines this match: (q_\w*)
and now I want to apply the ~
command to make them all upper-case (they are currently lower-case). I feel like VIM is more than capable of doing this but my skill with it is not there yet, can you help?
If you want to up-case the entire identifier, for each identifier in the file, use this substitute command:
%s/q_\w\+/\U&/g
The trick here is &
in the replacement pattern, which references the entire match. This will substitute e.g. q_identifier1
with Q_IDENTIFIER1
.
If you only want to up-case the q
, then you can use:
%s/q_\(\w\+\)/Q_\1/g
Now q_identifier1
will be changed to: Q_identifier1
If you want to up-case everything except the q_
, then use:
%s/q_\(\w\+\)/q_\U\1/g
Now q_identifier1
will be changed to: q_IDENTIFIER1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With