Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VI - finding lines longer than 80 characters

1,134 views
Skip to first unread message

Keith Vetter

unread,
Nov 19, 1992, 7:53:43 PM11/19/92
to
In VI, is there an easy way to find all lines whose length
is greater than 80 characters? I realize tabs are a problem but
let's assume that there are no tabs.

Thanks

Keith

Trip Martin

unread,
Nov 20, 1992, 12:04:28 AM11/20/92
to

If you just want to print them out, you can use:

:g/.\{81,\}/p

Unfortunately, the \{n,m\} construction doesn't work in search mode.

BTW, is there a way to easily re-execute the last ex command in vi?
--
Trip Martin
ni...@acm.rpi.edu
--
Trip Martin
ni...@acm.rpi.edu

Jeff Wang

unread,
Nov 20, 1992, 9:48:42 AM11/20/92
to
ni...@acm.rpi.edu (Trip Martin) writes:
|> kei...@cory.Berkeley.EDU (Keith Vetter) writes:
|>>In VI, is there an easy way to find all lines whose length
|>>is greater than 80 characters? I realize tabs are a problem but
|>>let's assume that there are no tabs.
|>
|> If you just want to print them out, you can use:
|>
|> :g/.\{81,\}/p
|>
|> Unfortunately, the \{n,m\} construction doesn't work in search mode.

Try this.. Open up a new line (o) and enter the following keystroke sequence -

/<Esc>81a.<Esc>"ddd@d

This will generate the following on the new line -

/.................................................................................

delete the line to buffer d, and execute it to find the next 81-character
sequence. You can then use n/N to keep searching for other lines. You'd have
to expand your tabs to spaces though.

--
#====}==) #===(==} #====}==) #===(==} {==)===# (=={====# {==)===# (=={====#
>> Jeff Wang Net : hj...@gruc19.nor.chevron.com <<
>> Chevron Petroleum Technology Company Profs : hjiwa (hovmb) <<
>> Geophysical/Geological Applications Phone : (504) 592-6162 <<
>> 935 Gravier Street, Room 1006 Fax : (504) 592-6958 <<
>> New Orleans, Louisiana 70112 Valeo,vales. Die dulci fruimini!! :) <<
#====}==) #===(==} #====}==) #===(==} {==)===# (=={====# {==)===# (=={====#

John Cheevers

unread,
Nov 20, 1992, 4:20:00 PM11/20/92
to
In article <#nz10s#@rpi.edu> ni...@acm.rpi.edu writes:
>
>BTW, is there a way to easily re-execute the last ex command in vi?
>--
>Trip Martin
>ni...@acm.rpi.edu

The "&" key will execute the last substitute command. Strangely, it only
does it once - If your last command was

:s/recieve/receive/g

Then hitting "&" executes

:s/recieve/receive (without the "g")

John Cheevers
chee...@cs.wisc.edu

Boyd Roberts

unread,
Nov 22, 1992, 2:46:28 PM11/22/92
to
I thought this was one well known feature of vi. Lines over 80 chars
usually screw your screen up -- no searching necessary...


Boyd Roberts bo...@prl.dec.com

``When the going gets wierd, the weird turn pro...''

David Rowland

unread,
Nov 22, 1992, 7:36:50 PM11/22/92
to
In article <1992Nov22.1...@prl.dec.com> bo...@prl.dec.com (Boyd Roberts) writes:
>I thought this was one well known feature of vi. Lines over 80 chars
>usually screw your screen up -- no searching necessary...
>
>
>Boyd Roberts bo...@prl.dec.com
>

FLAME WAR ALERT * FLAME WAR ALERT * FLAME WAR ALERT :-)

Seriously, if vi screws you screen up, there must be some sort of
configuration problem with your terminal. Call the help desk.
--
| David Rowland | The British are using New Zealanders. They must |
| Datamark Intl Ltd | really mean business ! |
| Wellington | - General Rommel During Northern African |
| NEW ZEALAND | Campaign WWII. |

DWT

unread,
Nov 21, 1992, 2:15:57 PM11/21/92
to
In article <1992Nov20....@pasteur.Berkeley.EDU>
kei...@cory.Berkeley.EDU (Keith Vetter) asked:

>In VI, is there an easy way to find all lines whose length
>is greater than 80 characters? I realize tabs are a problem but
>let's assume that there are no tabs.

"Easy" is such a subjective term. I make do with this two-fork hack: a
restaurant critic would give it fewer.

:w !cut -c81- | grep -n .

(where the period is a regexp for "any character except newline" and not end
punctuation), though even eighty characters (because an eighty-character line
on an eighty-column screen causes a cursor jump and an empty screen line) are
too many for my purposes and I usually use "79" in that formula rather than
"81".

It's ugly, but it beats the hell out of typing eighty-one periods in a search
pattern.

David W. Tamkin P. O. Box 59297 Northtown Station, Illinois 60659-0297
dattier@{holonet.net|gagme.chi.il.us} CIS: 73720,1570 MCI Mail: 426-1818

DWT

unread,
Nov 22, 1992, 4:04:47 PM11/22/92
to
In article <1992Nov20.2...@cs.wisc.edu> chee...@wolf.cs.wisc.edu
(John Cheevers) wrote:

>The "&" key will execute the last substitute command. Strangely, it only
>does it once - If your last command was
>
> :s/recieve/receive/g
>
>Then hitting "&" executes
>
> :s/recieve/receive (without the "g")

The & command does lose the flags of the subsitute command that it repeats,
but you can reissue the flags by using ex's & command instead of vi's:

:&g

or if the substitution worked out so well that you want to do it everywhere,

:%&g

Chris D Iacovelli

unread,
Nov 23, 1992, 8:26:22 AM11/23/92
to
In article <1992Nov22.1...@prl.dec.com> bo...@prl.dec.com (Boyd Roberts) writes:

<----- WARNING: This is not a flame ----->

Not. What happens if you use a window that is greater than 80
characters wide, i.e. xterm -g66x132. This does not "screw your screen up" and
searching is still necessary.

Just my $0.02.

Chris.
Chris Iacovelli
Member, Technical Staff
Telesciences CO Systems
ciac...@telesciences.com
if (flame)
> /dev/null
fi

0 new messages