home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / editors / 1803 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.6 KB  |  80 lines

  1. Newsgroups: comp.editors
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
  3. From: navarra@casbah.acns.nwu.edu (John Navarra)
  4. Subject: Re: Capitalizing first [a-z] letter in sentence in vi
  5. Message-ID: <1992Jul23.102852.1466@news.acns.nwu.edu>
  6. Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
  7. Organization: Northwestern University, Evanston Illinois.
  8. References: <1992Jul22.141433.26865@sci.kun.nl> <1992Jul22.215752.19032@news.acns.nwu.edu> <1992Jul23.010424.4048@sci.kun.nl>
  9. Date: Thu, 23 Jul 1992 10:28:52 GMT
  10. Lines: 68
  11.  
  12. In article <1992Jul23.010424.4048@sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
  13. >:1,$-1g/[.!?])*[ ]*$/+s/[A-Za-z]/\u&
  14. >
  15.     Ok, Hans, this works pretty well. (you can see it coming by now
  16. can't you ;-) ) I added the TAB key in with the [SPACE] part to check for
  17. sentences which ended with any whitespace combinations.
  18.      The only instances where this misses, that I can see, are as
  19. follows:
  20.  
  21. 1) It misses the first line because there is no punctutation before the
  22.    first sentence. I.e., if the file started:
  23.  
  24. in the beginning....
  25.  
  26.    it would miss the 'i' because the search pattern found no [.!?] on
  27.    the previous line. However, this is easily correctable by hand.
  28.  
  29. 2) It misses instances where there are blank lines in between two 
  30.    sentences. I.e., say your file was double spaced and it looked like
  31.    this:
  32.  
  33. This is sentence one.
  34.  
  35. this is sentence two.  
  36.  
  37.    'this' would not be capitalized in the second sentence. 
  38.    After some contemplation, the only thing I could think of two take 
  39.    care of this situation is to do the following:
  40.  
  41.    :%s/^[SPACETAB]*$/./g
  42.  
  43. Which will make the file look like:
  44.  
  45. This is sentence one.
  46. .
  47. this is sentence two. 
  48.  
  49.     and run your substitution on it. Now the 'this' will be capitalized
  50.     correctly. Now I can just do:
  51.  
  52.    :%s/^.$//g
  53.  
  54.     to get rid of all those '.' lines I just made. 
  55.     The only problem with this approach is that a sentence obviously need 
  56.     not end on each line but may contain a blank line in between anyway.
  57.     Therefore, by deliberately inserting a '.', a line could be changed that
  58.     wasn't supposed to be. However, this is the best I could come up
  59.     with.  I am still open to suggestion on this one. Ah the headaches
  60.     of regular expressions!
  61.  
  62.  
  63. ----------
  64.  
  65. And, while I'm at it, more progress on phase1:
  66. we had this line:
  67.  
  68. :%s/[.!?])*[SPACETAB]*[a-z]/\U&/g
  69.  
  70. but the following is better:
  71. :%s/[.!?])*[SPACETAB][SPACETAB]*[a-z]/\U&/g
  72.  
  73. The extra SPACETAB is in there to make sure words like
  74. file.name  weird?construction wild!wild!wild 
  75.  
  76. are not capitalized. 
  77.  
  78. Getting tired of this yet? ;-(
  79. -tms
  80.