home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.editors
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
- From: navarra@casbah.acns.nwu.edu (John Navarra)
- Subject: Re: Capitalizing first [a-z] letter in sentence in vi
- Message-ID: <1992Jul23.102852.1466@news.acns.nwu.edu>
- Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
- Organization: Northwestern University, Evanston Illinois.
- References: <1992Jul22.141433.26865@sci.kun.nl> <1992Jul22.215752.19032@news.acns.nwu.edu> <1992Jul23.010424.4048@sci.kun.nl>
- Date: Thu, 23 Jul 1992 10:28:52 GMT
- Lines: 68
-
- In article <1992Jul23.010424.4048@sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
- >:1,$-1g/[.!?])*[ ]*$/+s/[A-Za-z]/\u&
- >
- Ok, Hans, this works pretty well. (you can see it coming by now
- can't you ;-) ) I added the TAB key in with the [SPACE] part to check for
- sentences which ended with any whitespace combinations.
- The only instances where this misses, that I can see, are as
- follows:
-
- 1) It misses the first line because there is no punctutation before the
- first sentence. I.e., if the file started:
-
- in the beginning....
-
- it would miss the 'i' because the search pattern found no [.!?] on
- the previous line. However, this is easily correctable by hand.
-
- 2) It misses instances where there are blank lines in between two
- sentences. I.e., say your file was double spaced and it looked like
- this:
-
- This is sentence one.
-
- this is sentence two.
-
- 'this' would not be capitalized in the second sentence.
- After some contemplation, the only thing I could think of two take
- care of this situation is to do the following:
-
- :%s/^[SPACETAB]*$/./g
-
- Which will make the file look like:
-
- This is sentence one.
- .
- this is sentence two.
-
- and run your substitution on it. Now the 'this' will be capitalized
- correctly. Now I can just do:
-
- :%s/^.$//g
-
- to get rid of all those '.' lines I just made.
- The only problem with this approach is that a sentence obviously need
- not end on each line but may contain a blank line in between anyway.
- Therefore, by deliberately inserting a '.', a line could be changed that
- wasn't supposed to be. However, this is the best I could come up
- with. I am still open to suggestion on this one. Ah the headaches
- of regular expressions!
-
-
- ----------
-
- And, while I'm at it, more progress on phase1:
- we had this line:
-
- :%s/[.!?])*[SPACETAB]*[a-z]/\U&/g
-
- but the following is better:
- :%s/[.!?])*[SPACETAB][SPACETAB]*[a-z]/\U&/g
-
- The extra SPACETAB is in there to make sure words like
- file.name weird?construction wild!wild!wild
-
- are not capitalized.
-
- Getting tired of this yet? ;-(
- -tms
-