🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #2861

Re: Substituting on even or odd line numbers in VI?

#2861
From: Hans Mulder
Date: Wed, 26 Jun 1991 12:51
28 lines
1281 bytes
In <1991Jun26.025626.29367@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes:

>Can you say, on every even line number, substitute something for something.

Not directly, but you can use the trick below.

>Or on every odd line number, execute a command.

Yes, at least for ex-commands.  If you say

:g/^/command|+t+|-d

the command gets executed on all odd numbered lines, provided it doesn't move
the cursor off the line.  If you want to move the cursor, you could say

:g/^/+t+|-d|-command

but then your command wouldn't be executed on the last line if you had
an odd number of lines in the buffer.

So to substitute something on all even numbered lines, you should say

:2,$g/^/s/foo/bar/g|+t+|-d

--
Have a nice day,

Hans Mulder	hansm@cs.kun.nl
Technical Details
Message-ID: <3706@wn1.sci.kun.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm
References: <1991Jun26.025626.29367@massey.ac.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm
From: hansm@cs.kun.nl (Hans Mulder)
Newsgroups: comp.editors
Subject: Re: Substituting on even or odd line numbers in VI?
Message-ID: <3706@wn1.sci.kun.nl>
Date: 26 Jun 91 12:51:58 GMT
Article-I.D.: wn1.3706
References: <1991Jun26.025626.29367@massey.ac.nz>
Sender: root@sci.kun.nl
Organization: University of Nijmegen, The Netherlands
Lines: 28