Article View: comp.editors
Article #2889Re: A little question on vi
From: John Mackin
Date: Thu, 21 Jan 1993 15:05
Date: Thu, 21 Jan 1993 15:05
59 lines
3040 bytes
3040 bytes
In article <1993Jan21.061448.25739@cdf.toronto.edu>, g2chanhk@cdf.toronto.edu (Simon Ho Ki CHAN) writes: > Hi, is there anybody who knows how to put the EOF marker at the end of > the last line, instead of putting it in a new line? e.g I wanna create a file > like the following > > blah, blah > blah, blah<EOF> > > instead of > > blah, blah > blah, blah > <EOF> Someone has made this point already, but I have a few things to add. The answer to the question is that this is impossible with vi. And as `someone' (what I wouldn't give for a better news-reading interface!) pointed out, there is no "EOF marker" in a UNIX file. A UNIX file is an exact number of characters (bytes, octets) long and therefore has no requirement for an "EOF marker" such as is needed on some filesystems where files don't have an exact length in bytes, but only a sector or block count. (Note, all my remarks here apply to UNIX. If the original poster is using vi on something else, all bets are off.) There is a good reason why this is impossible. The reason is that vi is a text editor, for editing text files. A well-formed UNIX text file consists of zero or more lines. A line consists of zero or more non-null characters followed by a terminating newline character. Hence, a non-empty file with no terminal newline is not a well-formed UNIX text file. You don't want to create one of those, since (unfortunately) far too many UNIX tools will behave in `interesting' ways when presented with one of them. Similarly, you don't want to treat files with embedded nulls as text -- I'll never forget the day grep failed to match patterns that were indeed matched by strings in the file, because the file also had nulls in it. (There is also a well-known bug in many versions of vi to do with this. The above definition of a text file certainly admits the null (that is, zero-length or empty) file as a valid text file, as it must. Unfortunately, many versions of vi don't allow you to create the null file, or indeed operate on it sensibly. You can read it in, but it immediately becomes a one-line file.) This is not to say that a text editor _mustn't_ let you create a file without a terminal newline. Indeed, I tend to come down on the side of never second-guessing the user. But, I can see where the idea came from, and it's not wholly without merit. -- John Mackin <john@civil.su.oz.au> Knox's box is a 286. Fox in Socks does hacks and tricks Knox's box is hard to fix. To fix poor Knox's box for kicks.
Technical Details
Message-ID:
<1993Jan21.150505.28644@physiol.su.OZ.AU>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!physiol.su.OZ.AU!johnReferences:
<1993Jan21.061448.25739@cdf.toronto.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.editors Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!physiol.su.OZ.AU!john From: john@civil.su.oz.au (John Mackin) Subject: Re: A little question on vi Message-ID: <1993Jan21.150505.28644@physiol.su.OZ.AU> Summary: vi is a _text_ editor Sender: john@physiol.su.OZ.AU (John Mackin) Organization: Chickenhawk Software References: <1993Jan21.061448.25739@cdf.toronto.edu> Date: Thu, 21 Jan 1993 15:05:05 GMT Lines: 59