Re: Deleting lines from L1 to L2 in Vim script

2006-05-30 Thread Tim Chase

I would like to to delete line from L1 to L2, I try to script
that but obviously commands are different for a script. What
is the right thing to do ?



Well, if L1 and L2 represent fixed line numbers, such as line 24 
through line 38, you can just put


24,38d

in your script.  Quick, easy, clear...the way to go.

If L1 and L2 represent strings/regexps for finding a given line, 
you can use


let oldWS=wrapscan
set wrapscan
$/L1/,/L2/d
let wrapscan=oldWS

You can skip the 'wrapscan' stuff if you already have 'wrapscan' 
enabled (most folks do, only to turn it off selectively on an 
as-needed basis), or if you know that the L1 won't happen on the 
first line of the file.  In the second case (L1 isn't on the 1st 
line of the file), you can just do


1/L1/,/L2/d

It basically is searching from line 1 for the first instance of 
L1, and then deleting through the first instance of L2 that 
follows L1.


Just a few ideas.  I can expound on their magic further if you 
need, but you can start by reading in the help under


:help :range
:help :d

which should get you off to a good start.

-tim




Re: Deleting lines from L1 to L2 in Vim script

2006-05-30 Thread Christian J. Robinson
Today (Tue, 30 May 2006), Baha-Eddine MOKADEM wrote:

 I would like to to delete line from L1 to L2, I try to script that
 but obviously commands are different for a script.  What is the
 right thing to do ?

The easiest way to do it is with the :delete command (see :help
:delete).  For example:

 :4,8delete

This would delete lines four through eight.

However, I suspect your script has the start and end lines stored in
variables, which necessitates using :execute (see :help :execute).
For example, using L1 and L2 as variable names:

 :execute L1 . , . L2 . delete


- Christian

-- 
 If your work speaks for itself, don't interrupt. 
Christian J. Robinson [EMAIL PROTECTED] http://infynity.spodzone.com/
   PGP keys: 0x893B0EAF / 0xFB698360   http://infynity.spodzone.com/pgp   


Re: Deleting lines from L1 to L2 in Vim script

2006-05-30 Thread Mikolaj Machowski
Dnia wtorek, 30 maja 2006 11:43, Baha-Eddine MOKADEM napisał:
 Hi,


 I would like to to delete line from L1 to L2, I try to script that but
 obviously commands are different for a script.

Why? Just place something like::

5,10d

in script and it will work.

If you want to use variables::

let l1 = 5
let l2 = 10
exe l1.','.l2.'d'

Checking if range exists may be tricky but not impossible.

m.



Re: Deleting lines from L1 to L2 in Vim script

2006-05-30 Thread Tim Chase

And how about deleting from line L1 for instance to the end of
the file. And put it in a script file, since G don't appear
like a regexp and $ represent end of line if I'm not wrong ?



$ represents the end-of-line in *normal* mode.  As an Ex command, 
it means the last line in the file.  Thus, you'd use


:42,$d

to delete from line 42 to the end of the file.

I highly recommend reading the help found at

:help :range

where you'll learn all sorts of handy ways for referring to lines 
in an ex command.  Commands/addresses can be chained so you can 
end up with things like


:1/APPENDIX/?CHAPTER?+2

which would refer to two lines after (+2) the line that contains 
CHAPTER that occurs before the first line containing the word 
APPENDIX.  All sorts of complex references and ranges can be 
created from a few simple addressing schemes.


-tim




Re: Deleting lines from L1 to L2 in Vim script

2006-05-30 Thread A.J.Mechelynck

Tim Chase wrote:

And how about deleting from line L1 for instance to the end of
the file. And put it in a script file, since G don't appear
like a regexp and $ represent end of line if I'm not wrong ?



$ represents the end-of-line in *normal* mode.  As an Ex command, it 
means the last line in the file.  Thus, you'd use


:42,$d

to delete from line 42 to the end of the file.

I highly recommend reading the help found at

:help :range

where you'll learn all sorts of handy ways for referring to lines in 
an ex command.  Commands/addresses can be chained so you can end up 
with things like


:1/APPENDIX/?CHAPTER?+2

which would refer to two lines after (+2) the line that contains 
CHAPTER that occurs before the first line containing the word 
APPENDIX.  All sorts of complex references and ranges can be created 
from a few simple addressing schemes.


-tim




Similarly, in a range, a dot means the cursor line. Thus, to delete from 
the cursor line to the end of the file, use


   .,$d

(dot comma dollar d-for-delta).

Or, from two lines above the cursor to three lines below the cursor:

   .-2,.+3d

etc.


Best regards,
£Tony.