[comp.editors] vi delete to #

wb8foz@mthvax.cs.miami.edu (David Lesher,,255RTFM,255rtfm) (11/21/90)

I'm looking for a macro that would delete to a given line
number. For example: You are editing a file, and are on line 5.
You want to delete everything up to line 17.  Now of course, you
can subtract in your head, and use a 12dd. But my view has always
computers are supposed to do those things for me! 

Any suggestion on a "delete to {or delete through} line #" macro?
-- 
A host is a host from coast to coast.....wb8foz@mthvax.cs.miami.edu 
& no one will talk to a host that's close............(305) 255-RTFM
Unless the host (that isn't close)......................pob 570-335
is busy, hung or dead....................................33257-0335

rouben@math13.math.umbc.edu (Rouben Rostamian) (11/21/90)

In article <1990Nov21.025246.8298@mthvax.cs.miami.edu> wb8foz@mthvax.cs.miami.edu (David Lesher) writes:
 >I'm looking for a macro that would delete to a given line
 >number. For example: You are editing a file, and are on line 5.
 >You want to delete everything up to line 17.

 Try: 
        d17G

--

spcecdt@deeptht.santa-cruz.ca.us (John DuBois) (11/28/90)

In article <1990Nov21.025246.8298@mthvax.cs.miami.edu> wb8foz@mthvax.cs.miami.edu (David Lesher) writes:
+I'm looking for a macro that would delete to a given line
+number. For example: You are editing a file, and are on line 5.
+You want to delete everything up to line 17.  Now of course, you
+can subtract in your head, and use a 12dd. But my view has always
+computers are supposed to do those things for me! 
+
+Any suggestion on a "delete to {or delete through} line #" macro?
+is busy, hung or dead....................................33257-0335

     I think the only way you're going to get delete-through-line#
is with :.,# d<return>   You could make the :., part a macro...

	John DuBois
	spcecdt@deeptht.santa-cruz.ca.us

asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) (11/29/90)

In article <1990Nov21.025246.8298@mthvax.cs.miami.edu> wb8foz@mthvax.cs.miami.edu (David Lesher) writes:
> I'm looking for a macro that would delete to a given line
> number. For example: You are editing a file, and are on line 5.
> You want to delete everything up to line 17.  Now of course, you
> can subtract in your head, and use a 12dd. But my view has always
> computers are supposed to do those things for me! 
> 
> Any suggestion on a "delete to {or delete through} line #" macro?

I do this all the time.  I put the cursor on the first(last) line I
want deleted, then enter

    :.=

which tells me the line number there.  Then I put the cursor on the
last(first) line, and enter

    :N,.d   (:.,Nd)

where `N' was the previous line number (determined by the `:.=' command).
The `.' indicates current line number.

Don't forget, "vi" is not really a "screen" editor.  It is actually a
"screen" interface on top of "ex", which is a "line" editor.  When you
enter the `:' you are entering an "ex" command directly.

This allows you a number of convenient options, such as

    :.,.+4w! temp

which writes to a file named "temp" (overwriting if needed) the 5 lines
beginning at the current cursor position.  This breaks down as follows:

   :    - go to "ex" mode
   .    - current cursor position
   ,    - thru ...
   .+4  - current cursor position plus 4
   w    - write
   !    - I really mean it! overwrite if necessary (default no overwrite)
   temp - name of the file to create (defaults to original filename)

:-)  note that this is a smiley face, not an "ex" command.
--
asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain)
========================= Opinions are Mine, Typos belong to /usr/ucb/vi
"We're sorry, but the reality you have dialed is no longer in service.
Please check the value of pi, or see your SysOp for assistance."
.hplabs!felix!asylvain ================================================

felps@convex.com (Robert Felps) (11/30/90)

In <75@deeptht.UUCP> spcecdt@deeptht.santa-cruz.ca.us (John DuBois) writes:

>In article <1990Nov21.025246.8298@mthvax.cs.miami.edu> wb8foz@mthvax.cs.miami.edu (David Lesher) writes:
>+I'm looking for a macro that would delete to a given line
>+number. For example: You are editing a file, and are on line 5.
>+You want to delete everything up to line 17.  Now of course, you
>+can subtract in your head, and use a 12dd. But my view has always
>+computers are supposed to do those things for me! 
>+
>+Any suggestion on a "delete to {or delete through} line #" macro?
>+is busy, hung or dead....................................33257-0335

>     I think the only way you're going to get delete-through-line#
>is with :.,# d<return>   You could make the :., part a macro...

>	John DuBois
>	spcecdt@deeptht.santa-cruz.ca.us

How about,

d#G

or am I missing something here?


Thanks,
Robert Felps                                felps@convex.com
Convex Computer Corp                        OS System Specialist
3000 Waterview Parkway                      Tech. Assistant Ctr
Richardson, Tx.  75083                      1(800) 952-0379

davel@booboo.SanDiego.NCR.COM (David Lord) (12/01/90)

>In article <1990Nov21.025246.8298@mthvax.cs.miami.edu> wb8foz@mthvax.cs.miami.edu (David Lesher) writes:
>> I'm looking for a macro that would delete to a given line
>> number. For example: You are editing a file, and are on line 5.
>> You want to delete everything up to line 17.  Now of course, you
>> can subtract in your head, and use a 12dd. But my view has always
>> computers are supposed to do those things for me! 
>> 
>> Any suggestion on a "delete to {or delete through} line #" macro?

Don't need a macro to do this, the feature is built into vi already;

d<num>G  will delete from the current line to line <num> which can be
	 before or after the line you are on.

dG       deletes from current line to end of file.
d1G      deletes from current line to line one.
d250G    deletes from current line to line 250.

Alternatively you can use:
:<num1>,<num2>d

and replace the appropriate <num> with '.'.

-- Dave Lord