[comp.unix.questions] how do you get modeline

greyham@hades.OZ (Greyham Stoney) (12/16/89)

Can anyone provide me with a working example of how to get modelines to
work under vi?. Our vi (ISC 386/ix) 'set all' shows a 'modelines' option;
(note that it's plural; the BSD manual I have says it's singular) but I
can't seem to get it to do anything.

If anyone can help me out with getting modelines to work, I'd really
appreciate it. Needless to say, I can't find anything on vi by Reading The
Fine Manuals provided by ISC.

							Greyham.

-- 
/*  Greyham Stoney:                            Australia: (02) 428 6476  *
 *     greyham@hades.oz  - Ausonics Pty Ltd, Lane Cove, Sydney, Oz.      *
 *                ISDN: Interface Subscribers Don't Need                 */

allbery@NCoast.ORG (Brandon S. Allbery) (12/18/89)

As quoted from <493@hades.OZ> by greyham@hades.OZ (Greyham Stoney):
+---------------
| Can anyone provide me with a working example of how to get modelines to
| work under vi?. Our vi (ISC 386/ix) 'set all' shows a 'modelines' option;
| (note that it's plural; the BSD manual I have says it's singular) but I
| can't seem to get it to do anything.
+---------------

"modelines" in vi doesn't mean something on the screen; it refers to the
ability to put ex/vi commands in a file, to be executed when the file is read
in.  The commands must be in the first and/or last 5 lines in the file,
prefixed by "[ev][xi]:" (that is, any of "ex:", "vi:", "vx:", or "ei:"), and
be suffixed with a colon.  ("ex: set autoindent:") (Don't worry, I'm going to
make sure that the above isn't in the first/last 5 lines of this message.)
This option is often disabled by default, since it can be somehting of a
security hole.

Perhaps what you want is the "showmode" option.  This option makes the current
mode show up in the lower right-hand corner of the screen; it's blank in
command mode, or may show one of the following:

				APPEND MODE
				INSERT MODE
				CHANGE MODE
				REPLACE MODE
				REPLACE 1 CHAR

There may be others as well.  This goes a long way toward fixing the biggest
problem with vi:  knowing just exactly what it expects you to be doing.  After
all, you can botch things up royally if you think you're in an input mode and
vi thinks you're in command mode.

++Brandon
-- 
Brandon S. Allbery    allbery@NCoast.ORG, BALLBERY (MCI Mail), ALLBERY (Delphi)
uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp
*(comp.sources.misc mail to comp-sources-misc[-request]@backbone.site, please)*
*Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*
expnet.all: Experiments in *net management and organization.  Mail me for info.

maart@cs.vu.nl (Maarten Litmaath) (12/19/89)

In article <1989Dec17.174535.22577@NCoast.ORG> allbery@NCoast.ORG (Brandon S. Allbery) writes:
\...  The commands must be in the first and/or last 5 lines in the file,
\prefixed by "[ev][xi]:" [...]

There must be a leading space/tab in the prefix.
--
  Sci.aquaria votes are only poisson distributed in France.  (Alan M Stanier) |
 Maarten Litmaath @ VU Amsterdam:  maart@cs.vu.nl,  uunet!mcsun!botter!maart

wescott@Columbia.NCR.COM (Mike Wescott) (12/19/89)

In article <493@hades.OZ> writes:
> Can anyone provide me with a working example of how to get modelines to
> work under vi?. Our vi (ISC 386/ix) 'set all' shows a 'modelines' option;
> (note that it's plural; the BSD manual I have says it's singular) but I
> can't seem to get it to do anything.

Assuming that you want modelines (and not showmode as was suggested by
another).  You must have modelines set before you start to edit a file
by using the EXINIT environment variable or in your .exrc.  Or set it
by hand and use :n to edit the file.

The modelines option has nasty possibilities for Trojan Horse attacks,
so use it sparingly and never as root.

For those of you wondering what this option does, it permits the inclusion
of editor commands in the text of the file to be editted. The best (legitimate)
use I can think of is to change shiftwidth and/or tabstop:

/******
	vi:set shiftwidth=4:
	vi:set tabstop=4:
******/

Vi scans the first 5 and last 5 lines of the file for a string of characters
such that the first colon on the line is preceded by the string "ex" or
"vi" (some versions also permit "vx" or "ei") and is followed by a
colon-terminated command string.

-- 
	-Mike Wescott
	 mike.wescott@ncrcae.Columbia.NCR.COM
--
	-Mike Wescott
	 mike.wescott@ncrcae.Columbia.NCR.COM

logan@inpnms.UUCP (Jim Logan) (12/20/89)

In article <493@hades.OZ> greyham@hades.OZ (Greyham Stoney) writes:
# Can anyone provide me with a working example of how to get modelines to
# work under vi?. Our vi (ISC 386/ix) 'set all' shows a 'modelines' option;
# (note that it's plural; the BSD manual I have says it's singular) but I
# can't seem to get it to do anything.

I played with this for a good hour one day, and I would imagine
that others would like to see how it is done; hence the post. 
You're right, there is nothing in the man page that describes
modelines.   

All you have to do is put the line "set modelines" in $HOME/.exrc
and put a line like "ex: set some_flags:" near the top or bottom
of the file.   

A word of warning:  When modelines are used, it changes the files
status to modified.  This makes it a real pain to switch back and
forth between files since you have to explicitly type ":e!#"
rather than being able press <ctrl>-^.    

It is also a problem when looking at source code.  When you use
vi to look at a file, you have to explicitly type ":q!" to get
out of it.  You can't use "ZZ" because it will cause "make" to
recompile when there is no need.  I used it for a while at the
top of header files developed here with 3-space tabs.  You could
turn off "warn" or map "ZZ" to ":q!", but it's too easy to have
an accident that way.  

			-Jim
-- 
James Logan                       UUCP: uunet!inpnms!logan
Data General Telecommunications   Inet: logan%inpnms@uunet.uu.net
(301) 590-3069