dak@ausmelb.OZ (David Kruger) (06/18/87)
I usually use vi with the number and list (ex) options set. I accomplish this by putting the commands in my .exrc file. However, there are some files (as opposed to occasions) that I wish to edit in 80-column mode (both nu & list rob you of screen columns). I have mapped a function key to unset these options but, as I always want to edit certain files in 80-column mode, I am looking for a better method. A UNIX guru once told me that it is possible to somehow enter vi/ex commands at the top of a text file so that when you `vi' the file, the commands are executed. Does anybody out there know how to do it? Thanks in advance, ---------------------------------------------- -----=----- Thanks in advance, ----===---- ---=====--- Dave Kruger --=== ===-- -==== ====- a u s t e c D
boykin@custom.UUCP (Joseph Boykin) (06/19/87)
In article <219@ausmelb.OZ>, dak@ausmelb.OZ (David Kruger) writes: > A UNIX guru once told me that it is possible to somehow enter vi/ex commands at > the top of a text file so that when you `vi' the file, the commands are > executed. Does anybody out there know how to do it? > > Thanks in advance, There is a feature within UNIX VI (and PC/VI) called "mode lines" which is what you are looking for. It was present, but not documented in UNIX VI version 3.7. They were documented for version 3.9 (SVR2). Essentially you put some magic anywhere within the first or last five lines of your file with EX commands in it. The magic is either "ex:" or "vi:" followed by the command, followed by another colon. That is, for your case you would want a mode line which looks like this: vi: set nonu nolist : Mode lines are processed after both global and local initialization (EXINIT and .exrc file(s)), hence the mode line will override your EXINIT and .exrc entries. If you have PC/VI, mode lines are documented in Chapter 4, section 4.8.2. Joe Boykin Custom Software Systems ...necntc!custom!boykin
lavallee@hawk.CS.ULowell.Edu (Warren J. Lavallee) (06/19/87)
In article <219@ausmelb.OZ> dak@ausmelb.OZ (David Kruger) writes: >A UNIX guru once told me that it is possible to somehow enter vi/ex commands at >the top of a text file so that when you `vi' the file, the commands are >executed. Does anybody out there know how to do it? >Dave Kruger If you put a line in the format: (This worked on a BSD4.2 system at my last job. It does not work under Dynix 2.1. I considered it a bug anyways. :-) ) vi:commands or ex:commands fairly near the top (I think it is 10 lines), vi will execute the commands before you start editing the file. vi:q! makes a file virtually uneditable via vi. Warren Lavallee lavallee@ulowell.{csnet,UUCP}
gww@beatnix.UUCP (06/19/87)
In article <219@ausmelb.OZ> dak@ausmelb.OZ (David Kruger) writes: >I usually use vi with the number and list (ex) options set. I accomplish >this by putting the commands in my .exrc file. > > >A UNIX guru once told me that it is possible to somehow enter vi/ex commands at >the top of a text file so that when you `vi' the file, the commands are >executed. Does anybody out there know how to do it? This is a vagely documented feature :-} /usr/src/ucb/ex/ex.news reads in part: ``Version 3.7 October 16, 1981 Mode lines are now supported. Put a line containing ex: xxx : in the first or last 5 lines of the file, where xxx is any ex command you want executed when that file is read in. To make other programs happy, it should probably be inside a comment. You can use vi: as well as ex:. (Note: no space allowed between the "ex" and ":". The spaces around xxx are considered part of the command, and so are optional.) '' I thought this had also made its way into some of the ex/vi documentation, but I can't seem to find it now. Hope this answers your question. Gary.. {ucbvax!sun,lll-lcc!lll-tis,amdahl!altos86}!elxsi!gww
simon@its63b.ed.ac.uk (Simon Brown) (06/22/87)
In article <219@ausmelb.OZ> dak@ausmelb.OZ (David Kruger) writes: > >A UNIX guru once told me that it is possible to somehow enter vi/ex commands at >the top of a text file so that when you `vi' the file, the commands are >executed. Does anybody out there know how to do it? > What you do is you put lines containing things like vi: commands or ex: commands in the first five (or last 5) lines of the file. It doesn't matter whether you use vi or ex. The "vi:" or "ex:" needn't be at the start of the line, so that things like /* * vi: set nonumber nolist */ comments in your C-code will work. %{ Simon! %} -- ---------------------------------- | Simon Brown | UUCP: seismo!mcvax!ukc!its63b!simon | Department of Computer Science | JANET: simon@uk.ac.ed.its63b | University of Edinburgh, | ARPA: simon%its63b.ed.ac.uk@cs.ucl.ac.uk | Scotland, UK. | ---------------------------------- "Life's like that, you know"
ecl@mtgzy.UUCP (Evelyn C. Leeper) (06/22/87)
In article <756@custom.UUCP>, boykin@custom.UUCP (Joseph Boykin) writes: > In article <219@ausmelb.OZ>, dak@ausmelb.OZ (David Kruger) writes: > > [Regarding ex/vi commands in a text file] > Essentially you put some magic anywhere > within the first or last five lines of your file with > EX commands in it. The magic is either "ex:" or > "vi:" followed by the command, followed by another colon. The code is sloppy, so "ei:" or "vx:" will work also. We added a user whose login ended in "ei" to our password file. On one system, we just got a weird error the next time we tried to edit the password file; on the other, the encrypted password started with 'X', so vi dumped us into encryption mode and encrypted the entire password file when we wrote it out!!!! Argghh!! My personal opinion is that since vi has no idea what the file it's editting *should* look like, it not try to 'guess' (in effect) what are commands and what is data. Evelyn C. Leeper (201) 957-2070 UUCP: ihnp4!mtgzy!ecl ARPA: mtgzy!ecl@rutgers.rutgers.edu
gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/23/87)
In article <2628@mtgzy.UUCP> ecl@mtgzy.UUCP (Evelyn C. Leeper) writes:
-We added a user whose login ended in "ei" to our password file.
This has happened at several sites.
-My personal opinion is that since vi has no idea what the file it's editting
-*should* look like, it not try to 'guess' (in effect) what are commands and
-what is data.
Exactly right. A general text editor should be able to edit GENERAL text.
jpn@teddy.UUCP (John P. Nelson) (06/24/87)
>What you do is you put lines containing things like > vi: commands Well, both SUN UN*X and DEC ULTRIX disable this (mis)feature in their binary distributions. Just as well, in my opinion, since this can cause unexpected behavior when editing a file. Perhaps this behavior should be settable in the .exrc (or EXRC), with the default OFF.
dave@astra.necisa.oz (Dave Horsfall) (06/25/87)
Discovered the same thing myself when my passwd file had "alex" in it. Complained bitterly to the supplier, who promised to remove this obnoxious "feature" in the next release. They did too. A pox upon people who encourage "features" like this! You can hardly make a file un-editable with :q! somewhere, since you've got "ed". -- Dave Horsfall (VK2KFU) TEL: +61 2 438-3544 FAX: +61 2 439-7036 NEC Information Systems Aust. ACS: dave@astra.necisa.oz (also CSNET) 3rd Floor, 99 Nicholson St ARPA: dave%astra.necisa.oz@seismo.css.gov St. Leonards NSW 2064 UUCP: {enea,hplabs,mcvax,prlb2,seismo,ukc}!\ AUSTRALIA munnari!astra.necisa.oz!dave
amos@nsta.UUCP (Amos Shapir) (06/25/87)
In article <4135@teddy.UUCP> jpn@teddy.UUCP (John P. Nelson) writes: >>What you do is you put lines containing things like >> vi: commands > >Well, both SUN UN*X and DEC ULTRIX disable this (mis)feature in their >binary distributions. Just as well, in my opinion, since this can cause >unexpected behavior when editing a file. I have been waiting for someone who knows to comment on that, but since nobody did so far, I guess I'll have to: >Perhaps this behavior should be settable in the .exrc (or EXRC), with the >default OFF. The systems mentioned above, and also BSD4.3 do exactly that. To enable this option do (at least on 4.3) :set modelines . -- Amos Shapir National Semiconductor (Israel) 6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel Tel. (972)52-522261 amos%nsta@nsc.com @{hplabs,pyramid,sun,decwrl} 34 48 E / 32 10 N
dricej@drilex.UUCP (Craig Jackson) (06/25/87)
In article <4135@teddy.UUCP> jpn@teddy.UUCP (John P. Nelson) writes: >(Earlier, someone else had written:) >>What you do is you put lines containing things like >> vi: commands >Well, both SUN UN*X and DEC ULTRIX disable this (mis)feature in their >binary distributions. Just as well, in my opinion, since this can cause >unexpected behavior when editing a file. Thank you. >Perhaps this behavior should be settable in the .exrc (or EXRC), with the >default OFF. It definitely should. It seems that computers in Lexington, Mass, (as well as other Lexingtons) frequently get named with a name ending in 'lex'. I work on drilex, which is the Lexington machine of Data Resources; it used to talk to rclex, which was the Lexington office of Ridge Computers. I frequently would get complaints from my news partners, as their sys files came up with lines like: drilex:world,... and 'vi' tried to execute the newsgroup names and distributions. (I didn't have any problem; my vi's too old.) So I definitely vote for making this 'feature' optional. -- Craig Jackson UUCP: {harvard!axiom,linus!axiom,ll-xn}!drilex!dricej BIX: cjackson
mouse@mcgill-vision.UUCP (der Mouse) (06/26/87)
In article <756@custom.UUCP>, boykin@custom.UUCP (Joseph Boykin) writes: > In article <219@ausmelb.OZ>, dak@ausmelb.OZ (David Kruger) writes: >> A UNIX guru once told me that it is possible to somehow enter vi/ex >> commands at the top of a text file so that when you `vi' the file, >> the commands are executed. > [This feature exists. Just put] either "ex:" or "vi:" followed by > the command, followed by another colon. True. This drove us bonkers for the longest time. We just happened to have a user whose name ended with ex or vi (I forget which) near the top or bottom of /etc/passwd. Guess what vipw did! der Mouse (mouse@mcgill-vision.uucp)
john@xanth.UUCP (John Owens) (06/26/87)
In article <4135@teddy.UUCP>, jpn@teddy.UUCP (John P. Nelson) writes: > Perhaps this behavior should be settable in the .exrc (or EXRC), with the > default OFF. And indeed, in the version of ex/vi distributed with 4.3BSD, 3.7 6/7/85, this behavior only happens if the variable "modeline" (no abbreviation) is set when a file is read. Also, there must be a space or tab before the "ex:" or "vi:". "The real documentation is the code." Or, "Use the source...." -- John Owens Old Dominion University - Norfolk, Virginia, USA john@ODU.EDU old arpa: john%odu.edu@RELAY.CS.NET +1 804 440 4529 old uucp: {seismo,harvard,sun,hoptoad}!xanth!john
ado@elsie.UUCP (Arthur David Olson) (06/27/87)
> > My personal opinion is that since vi has no idea what the file it's editting > > *should* look like, it not try to 'guess' (in effect) what are commands and > > what is data. > Exactly right. A general text editor should be able to edit GENERAL text. Before the "vi:" line recognition stuff was added to the editor by Berkeley, we set up our 4.1BSD system so that when you edited a file named, for example, "whatever", the editor looked for a file named "whatever.exrc" and, if it found it, executed the commands in that file. Doing it this way meant that the file being edited could contain "general" text. -- UUCP: ..seismo!elsie!ado ARPA: elsie!ado@seismo.CSS.GOV Elsie and Ado are trademarks of Borden, Inc. ftwa.edu>ra
megabyte@chinet.UUCP (06/29/87)
I came in late on this discussion. I understand that there is some way to embed vi or ex command in a file to be edited. If someone could please e-mail a summary of how this is done... Don't take up net bandwith with this as it was JUST covered in this newsgroup. -- UUCP: (1) seismo!why_not!scsnet!sunder Mark E. Sunderlin (2) ihnp4!chinet!megabyte aka Dr. Megabyte CIS: 74026,3235 (202) 634-2529 Mail: IRS PM:PFR:D:NO 1111 Constitution Ave. NW Washington,DC 20224
huub@swivax.UUCP (Huub Knops) (07/02/87)
In article <825@mcgill-vision.UUCP>, mouse@mcgill-vision.UUCP (der Mouse) writes: > In article <756@custom.UUCP>, boykin@custom.UUCP (Joseph Boykin) writes: > > In article <219@ausmelb.OZ>, dak@ausmelb.OZ (David Kruger) writes: > >> A UNIX guru once told me that it is possible to somehow enter vi/ex > > > [This feature exists. Just put] either "ex:" or "vi:" followed by > > True. This drove us bonkers for the longest time. We just happened to Try to put vi: in your ~/.exrc and bonk the machine ! -- Huub Knops, SWI, Amsterdam (huub@swivax.UUCP)
aj@zyx.UUCP (Arndt Jonasson) (07/05/87)
[Discussing a vi/ex feature, which for a file containing vi: <ex commands> : in its first five lines causes the ex commands to be interpreted when the file is read by vi/ex.] In HP-UX series 200/300, version 5.141, vi doesn't have this feature, but in version 5.22, it does. In article <1419@xanth.UUCP> john@xanth.UUCP (John Owens) writes: > >And indeed, in the version of ex/vi distributed with 4.3BSD, 3.7 >6/7/85, this behavior only happens if the variable "modeline" (no >abbreviation) is set when a file is read. > Not so in HP-UX; in 5.22, neither 'modelines' nor 'modeline' are valid options, so the feature apparently can't be turned off. >Also, there must be a space or tab before the "ex:" or "vi:". This isn't necessary in HP-UX 5.22 vi/ex. >"The real documentation is the code." Or, "Use the source...." If only I had the source ... on the other hand, we have GNU Emacs, so noone here really cares. We haven't been bitten by this feature, anyway. Aside note: I noticed an option in HP-UX 5.22 vi called 'novice', which initially is turned off. Due to its name, it can't be turned on very easily ("vice: no such option"). Thinking that it might have to do with this feature, I did turn it on, but it hadn't. -- Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden UUCP: ...!seismo!mcvax!zyx!aj