Reputation: 33
I am trying to capitalize every line starting with int. or INT.
Following command
%s/\<int.*\>/\U&/gi
capitalize lines like international, integer too. (I know I can add c and search it then confirm it but I prefer adding that to my .vimrc and having the result whenever I save the file.)
So how can I only capitalize lines starting with int . (int period space another word(s)..) I tried
%s/\<int.\s*\>/\U&/g
but it didn't work.
Thanks.
Upvotes: 3
Views: 114
Reputation: 195209
I would do with :g
command:
:g/^int\./norm! gUU
Some Notes:
the above line works for option ic
set. I feel it convenient to have ic
and scs
set.
the line below works no matter if you have ic
set or not:
:g/\c^int\./norm! gUU
Upvotes: 3
Reputation: 2933
Just saying: it seems easier to do with :g
.
Something like:
:g/\v^(int|INT)\./norm! gUU
\v
activates the very-magic mode for regexp, not mandatory but I find it easier this way,:g
takes all the lines matching the pattern, and launches norm! gUU
for each of those lines (thanks to @Kent for the tip!). As you know, gUU
in normal mode transforms the whole line to uppercase. More info about :g
here : http://vim.wikia.com/wiki/Power_of_g
That's easily one killer feature of Vim that many users don't know of. I couldn't live without it!
Upvotes: 1
Reputation: 627263
You need to use
%s/^int\..*/\U&/i
Here,
^
- start of stringint\.
- a int.
substring.*
- all text to the end of the line.The \U&
replacement turns all the matched text to upper case.
The i
flag makes matching case insensitive. Note you do not need g
here as the command will affect all lines, and there is only 1 match per line.
Upvotes: 4