I received a couple of enquiries about the vi problem that I posted a couple of days ago.
I use Elvis, which is a vi clone. I wrote to Steve Kirkendall, who wrote Elvis, asking him for his opinion. Hereunder is the problem amd his comments. -------------------------------- The Problem: > consider the following heading:--- > > in the quick armadillo and in the lazy goat > > The problem is to capitalize the first letter of each word > that is made up of more than three letters. *However* the first > word, regardless of the number of letters also has to begin with > a capital. > > Thus the header becomes:--- > > In the Quick Armadillo and in the Lazy Goat Steve's reply: In vim, you can do it in one step with... :s/\(^\|\w\w\w\)\w\+/\u&/g In elvis, this command doesn't work because elvis doesn't recognize the ^ metacharacter anywhere except as the first character of the regular expression. Elvis would need two steps. That's probably a bug, but it doesn't come up very often, so I haven't worried about it much. The traditional vi, and nvi, don't support the \w metacharacter, so you'd need to use [a-zA-Z0-9_] instead. And I'm not sure about the \+ metacharacter either, so you should probably replace it another [a-zA-Z0-9_] and a * operator. And even then, support for \| and a late ^ is very iffy. I don't like the idea of using . to recognize characters in a word, because it could be fooled by a very short word followed by another word. /\<....\>/ could match "in a". The vim version of the command breaks down like this: :s/\(^\|\w\w\w\)\w\+/\u&/g 11111111111112222 334 1) Either the beginning of a line, or 3 characters that can appear in a word. 2) One or more additional characters that can appear in a word. Note that \+ is a "greedy" operator, so it'll always match the maximum number of word characters. Because of this, we don't need to use any \< or \> metacharacters. 3) Capitalize the next character. Note that lowercase \u is different from uppercase \U. \U affects all following characters, until the next \E. \u only affects one character, and doesn't need a \e to end it. 4) Use a copy of the whole original string. The \u only affects the first character of that string. This would probably still be fooled by apostrophes. Words such as "don't" might not be capitalized because they'd look like two short words. -------------------------------------------------------- If anyone has comment on this, could you post it, please? Regards, Bill Bennett -- SLUG - Sydney Linux User's Group - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug