home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / editors / 2700 < prev    next >
Encoding:
Text File  |  1992-11-09  |  2.2 KB  |  54 lines

  1. Newsgroups: comp.editors
  2. Path: sparky!uunet!caen!uwm.edu!ux1.cso.uiuc.edu!krisk
  3. From: krisk@ux1.cso.uiuc.edu (Kris Klindworth)
  4. Subject: Re: vi and columns
  5. Message-ID: <BxGpnu.KBF@ux1.cso.uiuc.edu>
  6. Organization: University of Illinois at Urbana
  7. References: <Bx7J88.B2w@cmptrc.lonestar.org>
  8. Distribution: na
  9. Date: Mon, 9 Nov 1992 18:50:03 GMT
  10. Lines: 42
  11.  
  12. jspence@cmptrc.lonestar.org (John Spence) writes:
  13.  
  14. >I do not know is vi is the editor to do this task in or not, but I would
  15. >like to know if it can be done in vi.
  16.  
  17. >I would like to change a column position to a character string in a
  18. >range of columns. For example, I would like to change column 63 in 
  19. >lines 40 through 55 to the string "foobar". In a sense, this would be
  20. >a insert command rather than a substitution command.
  21.  
  22. There may be a cleaner procedure out their, but this is the way I 
  23. work with fixed fields.
  24.  
  25. First I construct the search pattern.  This starts with .'s out to the column
  26. I want to play with.  In your case you might use O[ESC] to create a blank
  27. line and then 63i.[ESC] to insert 63 .'s as column holders (I'm assuming
  28. that you really do want to replace column 63 with foobar).  
  29.  
  30. ...............................................................
  31.  
  32. Then, I use \( \) combinations to mark off the parts I want to save in
  33. the replacement pattern.  It is importants to work from the right to 
  34. the left because doing it from left to right will shift the .'s away
  35. from their proper column positions. 
  36.  
  37. \(..............................................................\).
  38.  
  39.  
  40. Then, I fill in the rest of the command.
  41.  
  42. :40,55s/^\(..............................................................\)./\1foobar/
  43.  
  44. Finally, I delete the command line into a named buffer ("pdd) 
  45. and execute the buffer (@p).  If the command didn't do quite what I wanted,
  46. I undo it (u), put it back into the file ("pP), edit it, and run it again.
  47.  
  48.  
  49. ------------------------------------------------------------------------------
  50. Kris Klindworth                    Internet: krisk@ux1.cso.uiuc.edu
  51. Database Programmer                Phone   : (217)244-7120
  52. Illinois State Water Survey        US Mail : 2204 Griffith Dr
  53.                                              Champaign, IL 61820
  54.