home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.editors
- Path: sparky!uunet!caen!uwm.edu!ux1.cso.uiuc.edu!krisk
- From: krisk@ux1.cso.uiuc.edu (Kris Klindworth)
- Subject: Re: vi and columns
- Message-ID: <BxGpnu.KBF@ux1.cso.uiuc.edu>
- Organization: University of Illinois at Urbana
- References: <Bx7J88.B2w@cmptrc.lonestar.org>
- Distribution: na
- Date: Mon, 9 Nov 1992 18:50:03 GMT
- Lines: 42
-
- jspence@cmptrc.lonestar.org (John Spence) writes:
-
- >I do not know is vi is the editor to do this task in or not, but I would
- >like to know if it can be done in vi.
-
- >I would like to change a column position to a character string in a
- >range of columns. For example, I would like to change column 63 in
- >lines 40 through 55 to the string "foobar". In a sense, this would be
- >a insert command rather than a substitution command.
-
- There may be a cleaner procedure out their, but this is the way I
- work with fixed fields.
-
- First I construct the search pattern. This starts with .'s out to the column
- I want to play with. In your case you might use O[ESC] to create a blank
- line and then 63i.[ESC] to insert 63 .'s as column holders (I'm assuming
- that you really do want to replace column 63 with foobar).
-
- ...............................................................
-
- Then, I use \( \) combinations to mark off the parts I want to save in
- the replacement pattern. It is importants to work from the right to
- the left because doing it from left to right will shift the .'s away
- from their proper column positions.
-
- \(..............................................................\).
-
-
- Then, I fill in the rest of the command.
-
- :40,55s/^\(..............................................................\)./\1foobar/
-
- Finally, I delete the command line into a named buffer ("pdd)
- and execute the buffer (@p). If the command didn't do quite what I wanted,
- I undo it (u), put it back into the file ("pP), edit it, and run it again.
-
-
- ------------------------------------------------------------------------------
- Kris Klindworth Internet: krisk@ux1.cso.uiuc.edu
- Database Programmer Phone : (217)244-7120
- Illinois State Water Survey US Mail : 2204 Griffith Dr
- Champaign, IL 61820
-