Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vim: Uppercase First Characters

0 views
Skip to first unread message

Daniel

unread,
Oct 17, 2001, 11:16:14 PM10/17/01
to
Hi, vim experts,

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

Al Sharka

unread,
Oct 18, 2001, 10:12:41 AM10/18/01
to
On Thu, 18 Oct 2001, Daniel wrote:

} 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

Peppe

unread,
Oct 18, 2001, 12:02:07 PM10/18/01
to
Thus wrote Al Sharka <ash...@my-deja.com>

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

Al Sharka

unread,
Oct 18, 2001, 1:46:03 PM10/18/01
to
On Thu, 18 Oct 2001, Peppe wrote:
} Thus wrote Al Sharka

} > On Thu, 18 Oct 2001, Daniel wrote:
}
} > } 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

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

Peppe

unread,
Oct 18, 2001, 2:09:47 PM10/18/01
to
Thus wrote Al Sharka <ash...@my-deja.com>
> On Thu, 18 Oct 2001, Peppe wrote:

> } :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

Peppe

unread,
Oct 18, 2001, 2:20:38 PM10/18/01
to
Thus wrote Peppe <c92...@student.dtu.dk>

> > On Thu, 18 Oct 2001, Peppe wrote:

> > } :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.

0 new messages