How can I make all the first characters of the words to uppercase in a line?
That is : from "i like vim so much" to "I Like Vim So Much".
I know that to make all chars to uppercase, one can use
'gUU'.
Thanks!
daniel
} How can I make all the first characters of the words to uppercase in a line?
} That is : from "i like vim so much" to "I Like Vim So Much".
with the cursor on the line you want to change:
:s/\([A-Za-z]\)\([A-Za-z]*\)/\u\1\L\2/g
I am not sure if this is better, but how about letting '\u' do its
magic and don't bother with the case of the letters following it:
:s/[A-Za-z]*/\u&/g
or even the slightly different
:s/\<.\{-}\>/\u&/g
Peppe [try it on "I do not like HTML on usenet"]
--
"Before you criticize someone, walk
Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
c92...@student.dtu.dk (o o) he gets angry, he'll be a mile away
----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
That gives me an error message with vanilla vi (on at least HP-UX) of
"substitution loop". Granted, the OP did specify VIM.
} Peppe [try it on "I do not like HTML on usenet"]
And, I agree that lower-casing the rest of the letters was unnecessary
for this solution. Then again it would have been desirable if someone were
"shouting" this:
I LIKE VIM SO MUCH
} or even the slightly different
} :s/\<.\{-}\>/\u&/g
That must be specific to VIM also:
"Bad range construct \{m,n\} in regular expression" error
> } :s/[A-Za-z]*/\u&/g
> That gives me an error message with vanilla vi (on at least HP-UX) of
> "substitution loop". Granted, the OP did specify VIM.
Tested fine on a "Version SVR4.0, Solaris 2.5.0".
I have access to a "HP Version 78.2.1.8 $ 32-bit NLS $" which can be a
bit weird. If you have a line of "foo bar baz"
:s/[A-Za-z]*/\u&/g
results in "Foo baR baZ", while
:s/[A-Za-z][A-Za-z]*/\u&/g
gives me the expected "Foo Bar Baz".
Could not reproduce the loop, though. Anything special on the line?
> And, I agree that lower-casing the rest of the letters was unnecessary
> for this solution. Then again it would have been desirable if someone were
> "shouting" this:
> I LIKE VIM SO MUCH
Why then? ;-)
[Ok, ok - sometimes it is a good idea]
> } or even the slightly different
> } :s/\<.\{-}\>/\u&/g
> That must be specific to VIM also:
> "Bad range construct \{m,n\} in regular expression" error
Vim has it, and so does other clones for all I hear.
Peppe
> > } :s/[A-Za-z]*/\u&/g
> Tested fine on a "Version SVR4.0, Solaris 2.5.0".
> I have access to a "HP Version 78.2.1.8 $ 32-bit NLS $" which can be a
> bit weird. If you have a line of "foo bar baz"
> :s/[A-Za-z]*/\u&/g
> results in "Foo baR baZ", while
> :s/[A-Za-z][A-Za-z]*/\u&/g
> gives me the expected "Foo Bar Baz".
> Could not reproduce the loop, though. Anything special on the line?
Just for the curious, I get the loop error on the following
AIX ? 2 4: Version 3.10
IRIX 6.5: Version SVR4.0
This one is OK though:
SunOS 4.1.4: Version SVR3.1
Guess it is a problem width a zero-length match.