xref: /vim-8.2.3635/src/option.c (revision 592e0a2a)
1 /* vi:set ts=8 sts=4 sw=4:
2  *
3  * VIM - Vi IMproved	by Bram Moolenaar
4  *
5  * Do ":help uganda"  in Vim to read copying and usage conditions.
6  * Do ":help credits" in Vim to see a list of people who contributed.
7  * See README.txt for an overview of the Vim source code.
8  */
9 
10 /*
11  * Code to handle user-settable options. This is all pretty much table-
12  * driven. Checklist for adding a new option:
13  * - Put it in the options array below (copy an existing entry).
14  * - For a global option: Add a variable for it in option.h.
15  * - For a buffer or window local option:
16  *   - Add a PV_XX entry to the enum below.
17  *   - Add a variable to the window or buffer struct in structs.h.
18  *   - For a window option, add some code to copy_winopt().
19  *   - For a buffer option, add some code to buf_copy_options().
20  *   - For a buffer string option, add code to check_buf_options().
21  * - If it's a numeric option, add any necessary bounds checks to do_set().
22  * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23  * - When adding an option with expansion (P_EXPAND), but with a different
24  *   default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25  * - Add documentation!  One line in doc/help.txt, full description in
26  *   options.txt, and any other related places.
27  * - Add an entry in runtime/optwin.vim.
28  * When making changes:
29  * - Adjust the help for the option in doc/option.txt.
30  * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31  *   comment at the help for the 'compatible' option.
32  */
33 
34 #define IN_OPTION_C
35 #include "vim.h"
36 
37 /*
38  * The options that are local to a window or buffer have "indir" set to one of
39  * these values.  Special values:
40  * PV_NONE: global option.
41  * PV_BOTH is added: global option which also has a local value.
42  */
43 #define PV_BOTH 0x1000
44 #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
45 
46 typedef enum
47 {
48     PV_NONE = 0
49     , PV_AI
50     , PV_AR
51     , PV_ARAB
52     , PV_BH
53     , PV_BIN
54     , PV_BL
55     , PV_BOMB
56     , PV_BT
57     , PV_CI
58     , PV_CIN
59     , PV_CINK
60     , PV_CINO
61     , PV_CINW
62     , PV_CMS
63     , PV_COM
64     , PV_CPT
65     , PV_CFU
66     , PV_DEF
67     , PV_DICT
68     , PV_DIFF
69     , PV_EFM
70     , PV_EOL
71     , PV_EP
72     , PV_ET
73     , PV_FDC
74     , PV_FDE
75     , PV_FDI
76     , PV_FDL
77     , PV_FDM
78     , PV_FDN
79     , PV_FDT
80     , PV_FEN
81     , PV_FENC
82     , PV_FF
83     , PV_FML
84     , PV_FMR
85     , PV_FO
86     , PV_FT
87     , PV_GP
88     , PV_IMI
89     , PV_IMS
90     , PV_INC
91     , PV_INDE
92     , PV_INDK
93     , PV_INEX
94     , PV_INF
95     , PV_ISK
96     , PV_KEY
97     , PV_KMAP
98     , PV_KP
99     , PV_LBR
100     , PV_LISP
101     , PV_LIST
102     , PV_MA
103     , PV_ML
104     , PV_MOD
105     , PV_MP
106     , PV_MPS
107     , PV_NF
108     , PV_NU
109     , PV_NUW
110     , PV_OFT
111     , PV_PATH
112     , PV_PI
113     , PV_PVW
114     , PV_QE
115     , PV_RL
116     , PV_RLC
117     , PV_RO
118     , PV_SCBIND
119     , PV_SCROLL
120     , PV_SI
121     , PV_SN
122     , PV_STS
123     , PV_SUA
124     , PV_SW
125     , PV_SWF
126     , PV_SYN
127     , PV_TAGS
128     , PV_TS
129     , PV_TSR
130     , PV_TW
131     , PV_TX
132     , PV_WFH
133     , PV_WM
134     , PV_WRAP
135 } idopt_T;
136 
137 /*
138  * Options local to a window have a value local to a buffer and global to all
139  * buffers.  Indicate this by setting "var" to VAR_WIN.
140  */
141 #define VAR_WIN ((char_u *)-1)
142 
143 /*
144  * These the global values for options which are also local to a buffer.
145  * Only to be used in option.c!
146  */
147 static int	p_ai;
148 static int	p_bin;
149 #ifdef FEAT_MBYTE
150 static int	p_bomb;
151 #endif
152 #if defined(FEAT_QUICKFIX)
153 static char_u	*p_bh;
154 static char_u	*p_bt;
155 #endif
156 static int	p_bl;
157 static int	p_ci;
158 #ifdef FEAT_CINDENT
159 static int	p_cin;
160 static char_u	*p_cink;
161 static char_u	*p_cino;
162 #endif
163 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
164 static char_u	*p_cinw;
165 #endif
166 #ifdef FEAT_COMMENTS
167 static char_u	*p_com;
168 #endif
169 #ifdef FEAT_FOLDING
170 static char_u	*p_cms;
171 #endif
172 #ifdef FEAT_INS_EXPAND
173 static char_u	*p_cpt;
174 #endif
175 #ifdef FEAT_COMPL_FUNC
176 static char_u	*p_cfu;
177 #endif
178 static int	p_eol;
179 static int	p_et;
180 #ifdef FEAT_MBYTE
181 static char_u	*p_fenc;
182 #endif
183 static char_u	*p_ff;
184 static char_u	*p_fo;
185 #ifdef FEAT_AUTOCMD
186 static char_u	*p_ft;
187 #endif
188 static long	p_iminsert;
189 static long	p_imsearch;
190 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
191 static char_u	*p_inex;
192 #endif
193 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
194 static char_u	*p_inde;
195 static char_u	*p_indk;
196 #endif
197 static int	p_inf;
198 static char_u	*p_isk;
199 #ifdef FEAT_CRYPT
200 static char_u	*p_key;
201 #endif
202 #ifdef FEAT_LISP
203 static int	p_lisp;
204 #endif
205 static int	p_ml;
206 static int	p_ma;
207 static int	p_mod;
208 static char_u	*p_mps;
209 static char_u	*p_nf;
210 #ifdef FEAT_OSFILETYPE
211 static char_u	*p_oft;
212 #endif
213 static int	p_pi;
214 #ifdef FEAT_TEXTOBJ
215 static char_u	*p_qe;
216 #endif
217 static int	p_ro;
218 #ifdef FEAT_SMARTINDENT
219 static int	p_si;
220 #endif
221 #ifndef SHORT_FNAME
222 static int	p_sn;
223 #endif
224 static long	p_sts;
225 #if defined(FEAT_SEARCHPATH)
226 static char_u	*p_sua;
227 #endif
228 static long	p_sw;
229 static int	p_swf;
230 #ifdef FEAT_SYN_HL
231 static char_u	*p_syn;
232 #endif
233 static long	p_ts;
234 static long	p_tw;
235 static int	p_tx;
236 static long	p_wm;
237 #ifdef FEAT_KEYMAP
238 static char_u	*p_keymap;
239 #endif
240 
241 /* Saved values for when 'bin' is set. */
242 static int	p_et_nobin;
243 static int	p_ml_nobin;
244 static long	p_tw_nobin;
245 static long	p_wm_nobin;
246 
247 /* Saved values for when 'paste' is set */
248 static long	p_tw_nopaste;
249 static long	p_wm_nopaste;
250 static long	p_sts_nopaste;
251 static int	p_ai_nopaste;
252 
253 struct vimoption
254 {
255     char	*fullname;	/* full option name */
256     char	*shortname;	/* permissible abbreviation */
257     long_u	flags;		/* see below */
258     char_u	*var;		/* global option: pointer to variable;
259 				 * window-local option: VAR_WIN;
260 				 * buffer-local option: global value */
261     idopt_T	indir;		/* global option: PV_NONE;
262 				 * local option: indirect option index */
263     char_u	*def_val[2];	/* default values for variable (vi and vim) */
264 #ifdef FEAT_EVAL
265     scid_T	scriptID;	/* script in which the option was last set */
266 #endif
267 };
268 
269 #define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
270 #define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */
271 
272 /*
273  * Flags
274  */
275 #define P_BOOL		0x01	/* the option is boolean */
276 #define P_NUM		0x02	/* the option is numeric */
277 #define P_STRING	0x04	/* the option is a string */
278 #define P_ALLOCED	0x08	/* the string option is in allocated memory,
279 				    must use vim_free() when assigning new
280 				    value. Not set if default is the same. */
281 #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
282 				   never be used for local or hidden options! */
283 #define P_NODEFAULT	0x40	/* don't set to default value */
284 #define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
285 				    use vim_free() when assigning new value */
286 #define P_WAS_SET	0x100	/* option has been set/reset */
287 #define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
288 #define P_VI_DEF	0x400	/* Use Vi default for Vim */
289 #define P_VIM		0x800	/* Vim option, reset when 'cp' set */
290 
291 				/* when option changed, what to display: */
292 #define P_RSTAT		0x1000	/* redraw status lines */
293 #define P_RWIN		0x2000	/* redraw current window */
294 #define P_RBUF		0x4000	/* redraw current buffer */
295 #define P_RALL		0x6000	/* redraw all windows */
296 #define P_RCLR		0x7000	/* clear and redraw all */
297 
298 #define P_COMMA		0x8000	/* comma separated list */
299 #define P_NODUP		0x10000L/* don't allow duplicate strings */
300 #define P_FLAGLIST	0x20000L/* list of single-char flags */
301 
302 #define P_SECURE	0x40000L/* cannot change in modeline or secure mode */
303 #define P_GETTEXT	0x80000L/* expand default value with _() */
304 #define P_NOGLOB       0x100000L/* do not use local value for global vimrc */
305 
306 /*
307  * options[] is initialized here.
308  * The order of the options MUST be alphabetic for ":set all" and findoption().
309  * All option names MUST start with a lowercase letter (for findoption()).
310  * Exception: "t_" options are at the end.
311  * The options with a NULL variable are 'hidden': a set command for them is
312  * ignored and they are not printed.
313  */
314 static struct vimoption
315 #ifdef FEAT_GUI_W16
316 	_far
317 #endif
318 	options[] =
319 {
320     {"aleph",	    "al",   P_NUM|P_VI_DEF,
321 #ifdef FEAT_RIGHTLEFT
322 			    (char_u *)&p_aleph, PV_NONE,
323 #else
324 			    (char_u *)NULL, PV_NONE,
325 #endif
326 			    {
327 #if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
328 			    (char_u *)128L,
329 #else
330 			    (char_u *)224L,
331 #endif
332 					    (char_u *)0L}},
333     {"antialias",   "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
334 #if defined(FEAT_GUI) && defined(MACOS_X)
335 			    (char_u *)&p_antialias, PV_NONE,
336 			    {(char_u *)FALSE, (char_u *)FALSE}
337 #else
338 			    (char_u *)NULL, PV_NONE,
339 			    {(char_u *)FALSE, (char_u *)FALSE}
340 #endif
341 			    },
342     {"arabic",	    "arab", P_BOOL|P_VI_DEF|P_VIM,
343 #ifdef FEAT_ARABIC
344 			    (char_u *)VAR_WIN, PV_ARAB,
345 #else
346 			    (char_u *)NULL, PV_NONE,
347 #endif
348 			    {(char_u *)FALSE, (char_u *)0L}},
349     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
350 #ifdef FEAT_ARABIC
351 			    (char_u *)&p_arshape, PV_NONE,
352 #else
353 			    (char_u *)NULL, PV_NONE,
354 #endif
355 			    {(char_u *)TRUE, (char_u *)0L}},
356     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
357 #ifdef FEAT_RIGHTLEFT
358 			    (char_u *)&p_ari, PV_NONE,
359 #else
360 			    (char_u *)NULL, PV_NONE,
361 #endif
362 			    {(char_u *)FALSE, (char_u *)0L}},
363     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
364 #ifdef FEAT_FKMAP
365 			    (char_u *)&p_altkeymap, PV_NONE,
366 #else
367 			    (char_u *)NULL, PV_NONE,
368 #endif
369 			    {(char_u *)FALSE, (char_u *)0L}},
370     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
371 #if defined(FEAT_MBYTE)
372 			    (char_u *)&p_ambw, PV_NONE,
373 			    {(char_u *)"single", (char_u *)0L}
374 #else
375 			    (char_u *)NULL, PV_NONE,
376 			    {(char_u *)0L, (char_u *)0L}
377 #endif
378 			    },
379 #if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
380     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
381 			    (char_u *)&p_acd, PV_NONE,
382 			    {(char_u *)FALSE, (char_u *)0L}},
383 #endif
384     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
385 			    (char_u *)&p_ai, PV_AI,
386 			    {(char_u *)FALSE, (char_u *)0L}},
387     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
388 			    (char_u *)NULL, PV_NONE,
389 			    {(char_u *)FALSE, (char_u *)0L}},
390     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
391 			    (char_u *)&p_ar, OPT_BOTH(PV_AR),
392 			    {(char_u *)FALSE, (char_u *)0L}},
393     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
394 			    (char_u *)&p_aw, PV_NONE,
395 			    {(char_u *)FALSE, (char_u *)0L}},
396     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
397 			    (char_u *)&p_awa, PV_NONE,
398 			    {(char_u *)FALSE, (char_u *)0L}},
399     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
400 			    (char_u *)&p_bg, PV_NONE,
401 			    {
402 #if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
403 			    (char_u *)"dark",
404 #else
405 			    (char_u *)"light",
406 #endif
407 					    (char_u *)0L}},
408     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
409 			    (char_u *)&p_bs, PV_NONE,
410 			    {(char_u *)"", (char_u *)0L}},
411     {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
412 			    (char_u *)&p_bk, PV_NONE,
413 			    {(char_u *)FALSE, (char_u *)0L}},
414     {"backupcopy",  "bkc",  P_STRING|P_VIM|P_COMMA|P_NODUP,
415 			    (char_u *)&p_bkc, PV_NONE,
416 #ifdef UNIX
417 			    {(char_u *)"yes", (char_u *)"auto"}
418 #else
419 			    {(char_u *)"auto", (char_u *)"auto"}
420 #endif
421 			    },
422     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
423 			    (char_u *)&p_bdir, PV_NONE,
424 			    {(char_u *)DFLT_BDIR, (char_u *)0L}},
425     {"backupext",   "bex",  P_STRING|P_VI_DEF,
426 			    (char_u *)&p_bex, PV_NONE,
427 			    {
428 #ifdef VMS
429 			    (char_u *)"_",
430 #else
431 			    (char_u *)"~",
432 #endif
433 					    (char_u *)0L}},
434     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_COMMA,
435 #ifdef FEAT_WILDIGN
436 			    (char_u *)&p_bsk, PV_NONE,
437 			    {(char_u *)"", (char_u *)0L}
438 #else
439 			    (char_u *)NULL, PV_NONE,
440 			    {(char_u *)0L, (char_u *)0L}
441 #endif
442 			    },
443 #ifdef FEAT_BEVAL
444     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
445 			    (char_u *)&p_bdlay, PV_NONE,
446 			    {(char_u *)600L, (char_u *)0L}},
447 #endif
448 #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
449 	|| defined(FEAT_NETBEANS_INTG))
450     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
451 			    (char_u *)&p_beval, PV_NONE,
452 			    {(char_u*)FALSE, (char_u *)0L}},
453 #endif
454     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
455 			    (char_u *)NULL, PV_NONE,
456 			    {(char_u *)FALSE, (char_u *)0L}},
457     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
458 			    (char_u *)&p_bin, PV_BIN,
459 			    {(char_u *)FALSE, (char_u *)0L}},
460     {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
461 #ifdef MSDOS
462 			    (char_u *)&p_biosk, PV_NONE,
463 #else
464 			    (char_u *)NULL, PV_NONE,
465 #endif
466 			    {(char_u *)TRUE, (char_u *)0L}},
467     {"bomb",	    NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
468 #ifdef FEAT_MBYTE
469 			    (char_u *)&p_bomb, PV_BOMB,
470 #else
471 			    (char_u *)NULL, PV_NONE,
472 #endif
473 			    {(char_u *)FALSE, (char_u *)0L}},
474     {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
475 #ifdef FEAT_LINEBREAK
476 			    (char_u *)&p_breakat, PV_NONE,
477 			    {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
478 #else
479 			    (char_u *)NULL, PV_NONE,
480 			    {(char_u *)0L, (char_u *)0L}
481 #endif
482 			    },
483     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
484 #ifdef FEAT_BROWSE
485 			    (char_u *)&p_bsdir, PV_NONE,
486 			    {(char_u *)"last", (char_u *)0L}
487 #else
488 			    (char_u *)NULL, PV_NONE,
489 			    {(char_u *)0L, (char_u *)0L}
490 #endif
491 			    },
492     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
493 #if defined(FEAT_QUICKFIX)
494 			    (char_u *)&p_bh, PV_BH,
495 			    {(char_u *)"", (char_u *)0L}
496 #else
497 			    (char_u *)NULL, PV_NONE,
498 			    {(char_u *)0L, (char_u *)0L}
499 #endif
500 			    },
501     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
502 			    (char_u *)&p_bl, PV_BL,
503 			    {(char_u *)1L, (char_u *)0L}
504 			    },
505     {"buftype",	    "bt",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
506 #if defined(FEAT_QUICKFIX)
507 			    (char_u *)&p_bt, PV_BT,
508 			    {(char_u *)"", (char_u *)0L}
509 #else
510 			    (char_u *)NULL, PV_NONE,
511 			    {(char_u *)0L, (char_u *)0L}
512 #endif
513 			    },
514     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
515 			    (char_u *)&p_cmp, PV_NONE,
516 			    {(char_u *)"internal,keepascii", (char_u *)0L}
517 			    },
518     {"cdpath",	    "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
519 #ifdef FEAT_SEARCHPATH
520 			    (char_u *)&p_cdpath, PV_NONE,
521 			    {(char_u *)",,", (char_u *)0L}
522 #else
523 			    (char_u *)NULL, PV_NONE,
524 			    {(char_u *)0L, (char_u *)0L}
525 #endif
526 			    },
527     {"cedit",	    NULL,   P_STRING,
528 #ifdef FEAT_CMDWIN
529 			    (char_u *)&p_cedit, PV_NONE,
530 			    {(char_u *)"", (char_u *)CTRL_F_STR}
531 #else
532 			    (char_u *)NULL, PV_NONE,
533 			    {(char_u *)0L, (char_u *)0L}
534 #endif
535 			    },
536     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
537 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
538 			    (char_u *)&p_ccv, PV_NONE,
539 			    {(char_u *)"", (char_u *)0L}
540 #else
541 			    (char_u *)NULL, PV_NONE,
542 			    {(char_u *)0L, (char_u *)0L}
543 #endif
544 			    },
545     {"cindent",	    "cin",  P_BOOL|P_VI_DEF|P_VIM,
546 #ifdef FEAT_CINDENT
547 			    (char_u *)&p_cin, PV_CIN,
548 #else
549 			    (char_u *)NULL, PV_NONE,
550 #endif
551 			    {(char_u *)FALSE, (char_u *)0L}},
552     {"cinkeys",	    "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
553 #ifdef FEAT_CINDENT
554 			    (char_u *)&p_cink, PV_CINK,
555 			    {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
556 #else
557 			    (char_u *)NULL, PV_NONE,
558 			    {(char_u *)0L, (char_u *)0L}
559 #endif
560 			    },
561     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
562 #ifdef FEAT_CINDENT
563 			    (char_u *)&p_cino, PV_CINO,
564 #else
565 			    (char_u *)NULL, PV_NONE,
566 #endif
567 			    {(char_u *)"", (char_u *)0L}},
568     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
569 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
570 			    (char_u *)&p_cinw, PV_CINW,
571 			    {(char_u *)"if,else,while,do,for,switch",
572 				(char_u *)0L}
573 #else
574 			    (char_u *)NULL, PV_NONE,
575 			    {(char_u *)0L, (char_u *)0L}
576 #endif
577 			    },
578     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
579 #ifdef FEAT_CLIPBOARD
580 			    (char_u *)&p_cb, PV_NONE,
581 # ifdef FEAT_XCLIPBOARD
582 			    {(char_u *)"autoselect,exclude:cons\\|linux",
583 							       (char_u *)0L}
584 # else
585 			    {(char_u *)"", (char_u *)0L}
586 # endif
587 #else
588 			    (char_u *)NULL, PV_NONE,
589 			    {(char_u *)"", (char_u *)0L}
590 #endif
591 			    },
592     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
593 			    (char_u *)&p_ch, PV_NONE,
594 			    {(char_u *)1L, (char_u *)0L}},
595     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
596 #ifdef FEAT_CMDWIN
597 			    (char_u *)&p_cwh, PV_NONE,
598 #else
599 			    (char_u *)NULL, PV_NONE,
600 #endif
601 			    {(char_u *)7L, (char_u *)0L}},
602     {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
603 			    (char_u *)&Columns, PV_NONE,
604 			    {(char_u *)80L, (char_u *)0L}},
605     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
606 #ifdef FEAT_COMMENTS
607 			    (char_u *)&p_com, PV_COM,
608 			    {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
609 				(char_u *)0L}
610 #else
611 			    (char_u *)NULL, PV_NONE,
612 			    {(char_u *)0L, (char_u *)0L}
613 #endif
614 			    },
615     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF,
616 #ifdef FEAT_FOLDING
617 			    (char_u *)&p_cms, PV_CMS,
618 			    {(char_u *)"/*%s*/", (char_u *)0L}
619 #else
620 			    (char_u *)NULL, PV_NONE,
621 			    {(char_u *)0L, (char_u *)0L}
622 #endif
623 			    },
624     {"compatible",  "cp",   P_BOOL|P_RALL,
625 			    (char_u *)&p_cp, PV_NONE,
626 			    {(char_u *)TRUE, (char_u *)FALSE}},
627     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
628 #ifdef FEAT_INS_EXPAND
629 			    (char_u *)&p_cpt, PV_CPT,
630 			    {(char_u *)".,w,b,u,t,i", (char_u *)0L}
631 #else
632 			    (char_u *)NULL, PV_NONE,
633 			    {(char_u *)0L, (char_u *)0L}
634 #endif
635 			    },
636     {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
637 #ifdef FEAT_COMPL_FUNC
638 			    (char_u *)&p_cfu, PV_CFU,
639 			    {(char_u *)"", (char_u *)0L}
640 #else
641 			    (char_u *)NULL, PV_NONE,
642 			    {(char_u *)0L, (char_u *)0L}
643 #endif
644 			    },
645     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
646 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
647 			    (char_u *)&p_confirm, PV_NONE,
648 #else
649 			    (char_u *)NULL, PV_NONE,
650 #endif
651 			    {(char_u *)FALSE, (char_u *)0L}},
652     {"conskey",	    "consk",P_BOOL|P_VI_DEF,
653 #ifdef MSDOS
654 			    (char_u *)&p_consk, PV_NONE,
655 #else
656 			    (char_u *)NULL, PV_NONE,
657 #endif
658 			    {(char_u *)FALSE, (char_u *)0L}},
659     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
660 			    (char_u *)&p_ci, PV_CI,
661 			    {(char_u *)FALSE, (char_u *)0L}},
662     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
663 			    (char_u *)&p_cpo, PV_NONE,
664 			    {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}},
665     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
666 #ifdef FEAT_CSCOPE
667 			    (char_u *)&p_cspc, PV_NONE,
668 #else
669 			    (char_u *)NULL, PV_NONE,
670 #endif
671 			    {(char_u *)0L, (char_u *)0L}},
672     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
673 #ifdef FEAT_CSCOPE
674 			    (char_u *)&p_csprg, PV_NONE,
675 			    {(char_u *)"cscope", (char_u *)0L}
676 #else
677 			    (char_u *)NULL, PV_NONE,
678 			    {(char_u *)0L, (char_u *)0L}
679 #endif
680 			    },
681     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
682 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
683 			    (char_u *)&p_csqf, PV_NONE,
684 			    {(char_u *)"", (char_u *)0L}
685 #else
686 			    (char_u *)NULL, PV_NONE,
687 			    {(char_u *)0L, (char_u *)0L}
688 #endif
689 			    },
690     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
691 #ifdef FEAT_CSCOPE
692 			    (char_u *)&p_cst, PV_NONE,
693 #else
694 			    (char_u *)NULL, PV_NONE,
695 #endif
696 			    {(char_u *)0L, (char_u *)0L}},
697     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
698 #ifdef FEAT_CSCOPE
699 			    (char_u *)&p_csto, PV_NONE,
700 #else
701 			    (char_u *)NULL, PV_NONE,
702 #endif
703 			    {(char_u *)0L, (char_u *)0L}},
704     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
705 #ifdef FEAT_CSCOPE
706 			    (char_u *)&p_csverbose, PV_NONE,
707 #else
708 			    (char_u *)NULL, PV_NONE,
709 #endif
710 			    {(char_u *)0L, (char_u *)0L}},
711     {"debug",	    NULL,   P_STRING|P_VI_DEF,
712 			    (char_u *)&p_debug, PV_NONE,
713 			    {(char_u *)"", (char_u *)0L}},
714     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF,
715 #ifdef FEAT_FIND_ID
716 			    (char_u *)&p_def, OPT_BOTH(PV_DEF),
717 			    {(char_u *)"^\\s#\\s*define", (char_u *)0L}
718 #else
719 			    (char_u *)NULL, PV_NONE,
720 			    {(char_u *)NULL, (char_u *)0L}
721 #endif
722 			    },
723     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
724 #ifdef FEAT_MBYTE
725 			    (char_u *)&p_deco, PV_NONE,
726 #else
727 			    (char_u *)NULL, PV_NONE,
728 #endif
729 			    {(char_u *)FALSE, (char_u *)0L}
730 			    },
731     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732 #ifdef FEAT_INS_EXPAND
733 			    (char_u *)&p_dict, OPT_BOTH(PV_DICT),
734 #else
735 			    (char_u *)NULL, PV_NONE,
736 #endif
737 			    {(char_u *)"", (char_u *)0L}},
738     {"diff",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
739 #ifdef FEAT_DIFF
740 			    (char_u *)VAR_WIN, PV_DIFF,
741 #else
742 			    (char_u *)NULL, PV_NONE,
743 #endif
744 			    {(char_u *)FALSE, (char_u *)0L}},
745     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE,
746 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
747 			    (char_u *)&p_dex, PV_NONE,
748 			    {(char_u *)"", (char_u *)0L}
749 #else
750 			    (char_u *)NULL, PV_NONE,
751 			    {(char_u *)0L, (char_u *)0L}
752 #endif
753 			    },
754     {"diffopt",	    "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
755 #ifdef FEAT_DIFF
756 			    (char_u *)&p_dip, PV_NONE,
757 			    {(char_u *)"filler", (char_u *)NULL}
758 #else
759 			    (char_u *)NULL, PV_NONE,
760 			    {(char_u *)"", (char_u *)NULL}
761 #endif
762 			    },
763     {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
764 #ifdef FEAT_DIGRAPHS
765 			    (char_u *)&p_dg, PV_NONE,
766 #else
767 			    (char_u *)NULL, PV_NONE,
768 #endif
769 			    {(char_u *)FALSE, (char_u *)0L}},
770     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
771 			    (char_u *)&p_dir, PV_NONE,
772 			    {(char_u *)DFLT_DIR, (char_u *)0L}},
773     {"display",	    "dy",   P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
774 			    (char_u *)&p_dy, PV_NONE,
775 			    {(char_u *)"", (char_u *)0L}},
776     {"eadirection", "ead",  P_STRING|P_VI_DEF,
777 #ifdef FEAT_VERTSPLIT
778 			    (char_u *)&p_ead, PV_NONE,
779 			    {(char_u *)"both", (char_u *)0L}
780 #else
781 			    (char_u *)NULL, PV_NONE,
782 			    {(char_u *)NULL, (char_u *)0L}
783 #endif
784 			    },
785     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
786 			    (char_u *)&p_ed, PV_NONE,
787 			    {(char_u *)FALSE, (char_u *)0L}},
788     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR,
789 #ifdef FEAT_MBYTE
790 			    (char_u *)&p_enc, PV_NONE,
791 			    {(char_u *)ENC_DFLT, (char_u *)0L}
792 #else
793 			    (char_u *)NULL, PV_NONE,
794 			    {(char_u *)0L, (char_u *)0L}
795 #endif
796 			    },
797     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
798 			    (char_u *)&p_eol, PV_EOL,
799 			    {(char_u *)TRUE, (char_u *)0L}},
800     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
801 			    (char_u *)&p_ea, PV_NONE,
802 			    {(char_u *)TRUE, (char_u *)0L}},
803     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
804 			    (char_u *)&p_ep, OPT_BOTH(PV_EP),
805 			    {(char_u *)"", (char_u *)0L}},
806     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
807 			    (char_u *)&p_eb, PV_NONE,
808 			    {(char_u *)FALSE, (char_u *)0L}},
809     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
810 #ifdef FEAT_QUICKFIX
811 			    (char_u *)&p_ef, PV_NONE,
812 			    {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
813 #else
814 			    (char_u *)NULL, PV_NONE,
815 			    {(char_u *)NULL, (char_u *)0L}
816 #endif
817 			    },
818     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
819 #ifdef FEAT_QUICKFIX
820 			    (char_u *)&p_efm, OPT_BOTH(PV_EFM),
821 			    {(char_u *)DFLT_EFM, (char_u *)0L},
822 #else
823 			    (char_u *)NULL, PV_NONE,
824 			    {(char_u *)NULL, (char_u *)0L}
825 #endif
826 			    },
827     {"esckeys",	    "ek",   P_BOOL|P_VIM,
828 			    (char_u *)&p_ek, PV_NONE,
829 			    {(char_u *)FALSE, (char_u *)TRUE}},
830     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
831 #ifdef FEAT_AUTOCMD
832 			    (char_u *)&p_ei, PV_NONE,
833 #else
834 			    (char_u *)NULL, PV_NONE,
835 #endif
836 			    {(char_u *)"", (char_u *)0L}},
837     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
838 			    (char_u *)&p_et, PV_ET,
839 			    {(char_u *)FALSE, (char_u *)0L}},
840     {"exrc",	    "ex",   P_BOOL|P_VI_DEF|P_SECURE,
841 			    (char_u *)&p_exrc, PV_NONE,
842 			    {(char_u *)FALSE, (char_u *)0L}},
843     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
844 #ifdef FEAT_MBYTE
845 			    (char_u *)&p_fenc, PV_FENC,
846 			    {(char_u *)"", (char_u *)0L}
847 #else
848 			    (char_u *)NULL, PV_NONE,
849 			    {(char_u *)0L, (char_u *)0L}
850 #endif
851 			    },
852     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
853 #ifdef FEAT_MBYTE
854 			    (char_u *)&p_fencs, PV_NONE,
855 			    {(char_u *)"ucs-bom", (char_u *)0L}
856 #else
857 			    (char_u *)NULL, PV_NONE,
858 			    {(char_u *)0L, (char_u *)0L}
859 #endif
860 			    },
861     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC,
862 			    (char_u *)&p_ff, PV_FF,
863 			    {(char_u *)DFLT_FF, (char_u *)0L}},
864     {"fileformats", "ffs",  P_STRING|P_VIM|P_COMMA|P_NODUP,
865 			    (char_u *)&p_ffs, PV_NONE,
866 			    {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}},
867     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
868 #ifdef FEAT_AUTOCMD
869 			    (char_u *)&p_ft, PV_FT,
870 			    {(char_u *)"", (char_u *)0L}
871 #else
872 			    (char_u *)NULL, PV_NONE,
873 			    {(char_u *)0L, (char_u *)0L}
874 #endif
875 			    },
876     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
877 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
878 			    (char_u *)&p_fcs, PV_NONE,
879 			    {(char_u *)"vert:|,fold:-", (char_u *)0L}
880 #else
881 			    (char_u *)NULL, PV_NONE,
882 			    {(char_u *)"", (char_u *)0L}
883 #endif
884 			    },
885     {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
886 #ifdef FEAT_FKMAP
887 			    (char_u *)&p_fkmap, PV_NONE,
888 #else
889 			    (char_u *)NULL, PV_NONE,
890 #endif
891 			    {(char_u *)FALSE, (char_u *)0L}},
892     {"flash",	    "fl",   P_BOOL|P_VI_DEF,
893 			    (char_u *)NULL, PV_NONE,
894 			    {(char_u *)FALSE, (char_u *)0L}},
895 #ifdef FEAT_FOLDING
896     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
897 			    (char_u *)&p_fcl, PV_NONE,
898 			    {(char_u *)"", (char_u *)0L}},
899     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
900 			    (char_u *)VAR_WIN, PV_FDC,
901 			    {(char_u *)FALSE, (char_u *)0L}},
902     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
903 			    (char_u *)VAR_WIN, PV_FEN,
904 			    {(char_u *)TRUE, (char_u *)0L}},
905     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
906 # ifdef FEAT_EVAL
907 			    (char_u *)VAR_WIN, PV_FDE,
908 			    {(char_u *)"0", (char_u *)NULL}
909 # else
910 			    (char_u *)NULL, PV_NONE,
911 			    {(char_u *)NULL, (char_u *)0L}
912 # endif
913 			    },
914     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
915 			    (char_u *)VAR_WIN, PV_FDI,
916 			    {(char_u *)"#", (char_u *)NULL}},
917     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
918 			    (char_u *)VAR_WIN, PV_FDL,
919 			    {(char_u *)0L, (char_u *)0L}},
920     {"foldlevelstart","fdls", P_NUM|P_VI_DEF,
921 			    (char_u *)&p_fdls, PV_NONE,
922 			    {(char_u *)-1L, (char_u *)0L}},
923     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
924 						       P_RWIN|P_COMMA|P_NODUP,
925 			    (char_u *)VAR_WIN, PV_FMR,
926 			    {(char_u *)"{{{,}}}", (char_u *)NULL}},
927     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
928 			    (char_u *)VAR_WIN, PV_FDM,
929 			    {(char_u *)"manual", (char_u *)NULL}},
930     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
931 			    (char_u *)VAR_WIN, PV_FML,
932 			    {(char_u *)1L, (char_u *)0L}},
933     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
934 			    (char_u *)VAR_WIN, PV_FDN,
935 			    {(char_u *)20L, (char_u *)0L}},
936     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
937 			    (char_u *)&p_fdo, PV_NONE,
938 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
939 							       (char_u *)0L}},
940     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
941 # ifdef FEAT_EVAL
942 			    (char_u *)VAR_WIN, PV_FDT,
943 			    {(char_u *)"foldtext()", (char_u *)NULL}
944 #else
945 			    (char_u *)NULL, PV_NONE,
946 			    {(char_u *)NULL, (char_u *)0L}
947 #endif
948 			    },
949 #endif
950     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
951 			    (char_u *)&p_fo, PV_FO,
952 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}},
953     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
954 			    (char_u *)&p_fp, PV_NONE,
955 			    {(char_u *)"", (char_u *)0L}},
956     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
957 			    (char_u *)&p_gd, PV_NONE,
958 			    {(char_u *)FALSE, (char_u *)0L}},
959     {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
960 			    (char_u *)NULL, PV_NONE,
961 			    {(char_u *)FALSE, (char_u *)0L}},
962     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
963 #ifdef FEAT_QUICKFIX
964 			    (char_u *)&p_gefm, PV_NONE,
965 			    {(char_u *)DFLT_GREPFORMAT, (char_u *)0L},
966 #else
967 			    (char_u *)NULL, PV_NONE,
968 			    {(char_u *)NULL, (char_u *)0L}
969 #endif
970 			    },
971     {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
972 #ifdef FEAT_QUICKFIX
973 			    (char_u *)&p_gp, OPT_BOTH(PV_GP),
974 			    {
975 # ifdef WIN3264
976 			    /* may be changed to "grep -n" in os_win32.c */
977 			    (char_u *)"findstr /n",
978 # else
979 #  ifdef UNIX
980 			    /* Add an extra file name so that grep will always
981 			     * insert a file name in the match line. */
982 			    (char_u *)"grep -n $* /dev/null",
983 #  else
984 #   ifdef VMS
985 			    (char_u *)"SEARCH/NUMBERS ",
986 #   else
987 			    (char_u *)"grep -n ",
988 #endif
989 #endif
990 # endif
991 			    (char_u *)0L},
992 #else
993 			    (char_u *)NULL, PV_NONE,
994 			    {(char_u *)NULL, (char_u *)0L}
995 #endif
996 			    },
997     {"guicursor",    "gcr",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
998 #ifdef CURSOR_SHAPE
999 			    (char_u *)&p_guicursor, PV_NONE,
1000 			    {
1001 # ifdef FEAT_GUI
1002 				(char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1003 # else	/* MSDOS or Win32 console */
1004 				(char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1005 # endif
1006 				    (char_u *)0L}
1007 #else
1008 			    (char_u *)NULL, PV_NONE,
1009 			    {(char_u *)NULL, (char_u *)0L}
1010 #endif
1011 				    },
1012     {"guifont",	    "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1013 #ifdef FEAT_GUI
1014 			    (char_u *)&p_guifont, PV_NONE,
1015 			    {(char_u *)"", (char_u *)0L}
1016 #else
1017 			    (char_u *)NULL, PV_NONE,
1018 			    {(char_u *)NULL, (char_u *)0L}
1019 #endif
1020 				    },
1021     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1022 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1023 			    (char_u *)&p_guifontset, PV_NONE,
1024 			    {(char_u *)"", (char_u *)0L}
1025 #else
1026 			    (char_u *)NULL, PV_NONE,
1027 			    {(char_u *)NULL, (char_u *)0L}
1028 #endif
1029 				    },
1030     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1031 #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1032 			    (char_u *)&p_guifontwide, PV_NONE,
1033 			    {(char_u *)"", (char_u *)0L}
1034 #else
1035 			    (char_u *)NULL, PV_NONE,
1036 			    {(char_u *)NULL, (char_u *)0L}
1037 #endif
1038 				    },
1039     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
1040 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_KDE)
1041 			    (char_u *)&p_ghr, PV_NONE,
1042 #else
1043 			    (char_u *)NULL, PV_NONE,
1044 #endif
1045 			    {(char_u *)50L, (char_u *)0L}},
1046     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1047 #if defined(FEAT_GUI) || defined(FEAT_GUI_KDE)
1048 			    (char_u *)&p_go, PV_NONE,
1049 # if defined(UNIX) && !defined(MACOS)
1050 			    {(char_u *)"agimrLtT", (char_u *)0L}
1051 # else
1052 			    {(char_u *)"gmrLtT", (char_u *)0L}
1053 # endif
1054 #else
1055 			    (char_u *)NULL, PV_NONE,
1056 			    {(char_u *)NULL, (char_u *)0L}
1057 #endif
1058 				    },
1059     {"guipty",	    NULL,   P_BOOL|P_VI_DEF,
1060 #if defined(FEAT_GUI)
1061 			    (char_u *)&p_guipty, PV_NONE,
1062 #else
1063 			    (char_u *)NULL, PV_NONE,
1064 #endif
1065 			    {(char_u *)TRUE, (char_u *)0L}},
1066     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
1067 			    (char_u *)NULL, PV_NONE,
1068 			    {(char_u *)0L, (char_u *)0L}},
1069     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1070 			    (char_u *)&p_hf, PV_NONE,
1071 			    {(char_u *)DFLT_HELPFILE, (char_u *)0L}},
1072     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
1073 #ifdef FEAT_WINDOWS
1074 			    (char_u *)&p_hh, PV_NONE,
1075 #else
1076 			    (char_u *)NULL, PV_NONE,
1077 #endif
1078 			    {(char_u *)20L, (char_u *)0L}},
1079     {"helplang",    "hlg",  P_STRING|P_VI_DEF|P_COMMA,
1080 #ifdef FEAT_MULTI_LANG
1081 			    (char_u *)&p_hlg, PV_NONE,
1082 			    {(char_u *)"", (char_u *)0L}
1083 #else
1084 			    (char_u *)NULL, PV_NONE,
1085 			    {(char_u *)0L, (char_u *)0L}
1086 #endif
1087     },
1088     {"hidden",	    "hid",  P_BOOL|P_VI_DEF,
1089 			    (char_u *)&p_hid, PV_NONE,
1090 			    {(char_u *)FALSE, (char_u *)0L}},
1091     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1092 			    (char_u *)&p_hl, PV_NONE,
1093 			    {(char_u *)"8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn",
1094 				(char_u *)0L}},
1095     {"history",	    "hi",   P_NUM|P_VIM,
1096 			    (char_u *)&p_hi, PV_NONE,
1097 			    {(char_u *)0L, (char_u *)20L}},
1098     {"hkmap",	    "hk",   P_BOOL|P_VI_DEF|P_VIM,
1099 #ifdef FEAT_RIGHTLEFT
1100 			    (char_u *)&p_hkmap, PV_NONE,
1101 #else
1102 			    (char_u *)NULL, PV_NONE,
1103 #endif
1104 			    {(char_u *)FALSE, (char_u *)0L}},
1105     {"hkmapp",	    "hkp",  P_BOOL|P_VI_DEF|P_VIM,
1106 #ifdef FEAT_RIGHTLEFT
1107 			    (char_u *)&p_hkmapp, PV_NONE,
1108 #else
1109 			    (char_u *)NULL, PV_NONE,
1110 #endif
1111 			    {(char_u *)FALSE, (char_u *)0L}},
1112     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1113 			    (char_u *)&p_hls, PV_NONE,
1114 			    {(char_u *)FALSE, (char_u *)0L}},
1115     {"icon",	    NULL,   P_BOOL|P_VI_DEF,
1116 #ifdef FEAT_TITLE
1117 			    (char_u *)&p_icon, PV_NONE,
1118 #else
1119 			    (char_u *)NULL, PV_NONE,
1120 #endif
1121 			    {(char_u *)FALSE, (char_u *)0L}},
1122     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
1123 #ifdef FEAT_TITLE
1124 			    (char_u *)&p_iconstring, PV_NONE,
1125 #else
1126 			    (char_u *)NULL, PV_NONE,
1127 #endif
1128 			    {(char_u *)"", (char_u *)0L}},
1129     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
1130 			    (char_u *)&p_ic, PV_NONE,
1131 			    {(char_u *)FALSE, (char_u *)0L}},
1132     {"imactivatekey","imak",P_STRING|P_VI_DEF,
1133 #if defined(FEAT_XIM) && (defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE))
1134 			    (char_u *)&p_imak, PV_NONE,
1135 #else
1136 			    (char_u *)NULL, PV_NONE,
1137 #endif
1138 			    {(char_u *)"", (char_u *)0L}},
1139     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
1140 #ifdef USE_IM_CONTROL
1141 			    (char_u *)&p_imcmdline, PV_NONE,
1142 #else
1143 			    (char_u *)NULL, PV_NONE,
1144 #endif
1145 			    {(char_u *)FALSE, (char_u *)0L}},
1146     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
1147 #ifdef USE_IM_CONTROL
1148 			    (char_u *)&p_imdisable, PV_NONE,
1149 #else
1150 			    (char_u *)NULL, PV_NONE,
1151 #endif
1152 #ifdef __sgi
1153 			    {(char_u *)TRUE, (char_u *)0L}
1154 #else
1155 			    {(char_u *)FALSE, (char_u *)0L}
1156 #endif
1157 			    },
1158     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
1159 			    (char_u *)&p_iminsert, PV_IMI,
1160 #ifdef B_IMODE_IM
1161 			    {(char_u *)B_IMODE_IM, (char_u *)0L}
1162 #else
1163 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1164 #endif
1165 			    },
1166     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
1167 			    (char_u *)&p_imsearch, PV_IMS,
1168 #ifdef B_IMODE_IM
1169 			    {(char_u *)B_IMODE_IM, (char_u *)0L}
1170 #else
1171 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1172 #endif
1173 			    },
1174     {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
1175 #ifdef FEAT_FIND_ID
1176 			    (char_u *)&p_inc, OPT_BOTH(PV_INC),
1177 			    {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1178 #else
1179 			    (char_u *)NULL, PV_NONE,
1180 			    {(char_u *)0L, (char_u *)0L}
1181 #endif
1182 			    },
1183     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1184 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1185 			    (char_u *)&p_inex, PV_INEX,
1186 			    {(char_u *)"", (char_u *)0L}
1187 #else
1188 			    (char_u *)NULL, PV_NONE,
1189 			    {(char_u *)0L, (char_u *)0L}
1190 #endif
1191 			    },
1192     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
1193 			    (char_u *)&p_is, PV_NONE,
1194 			    {(char_u *)FALSE, (char_u *)0L}},
1195     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1196 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1197 			    (char_u *)&p_inde, PV_INDE,
1198 			    {(char_u *)"", (char_u *)0L}
1199 #else
1200 			    (char_u *)NULL, PV_NONE,
1201 			    {(char_u *)0L, (char_u *)0L}
1202 #endif
1203 			    },
1204     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1205 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1206 			    (char_u *)&p_indk, PV_INDK,
1207 			    {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1208 #else
1209 			    (char_u *)NULL, PV_NONE,
1210 			    {(char_u *)0L, (char_u *)0L}
1211 #endif
1212 			    },
1213     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
1214 			    (char_u *)&p_inf, PV_INF,
1215 			    {(char_u *)FALSE, (char_u *)0L}},
1216     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
1217 			    (char_u *)&p_im, PV_NONE,
1218 			    {(char_u *)FALSE, (char_u *)0L}},
1219     {"isfname",	    "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1220 			    (char_u *)&p_isf, PV_NONE,
1221 			    {
1222 #ifdef BACKSLASH_IN_FILENAME
1223 				/* Excluded are: & and ^ are special in cmd.exe
1224 				 * ( and ) are used in text separating fnames */
1225 			    (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1226 #else
1227 # ifdef AMIGA
1228 			    (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1229 # else
1230 #  ifdef VMS
1231 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1232 #  else /* UNIX et al. */
1233 #   ifdef EBCDIC
1234 			    (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1235 #   else
1236 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1237 #   endif
1238 #  endif
1239 # endif
1240 #endif
1241 				(char_u *)0L}},
1242     {"isident",	    "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1243 			    (char_u *)&p_isi, PV_NONE,
1244 			    {
1245 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1246 			    (char_u *)"@,48-57,_,128-167,224-235",
1247 #else
1248 # ifdef EBCDIC
1249 			    /* TODO: EBCDIC Check this! @ == isalpha()*/
1250 			    (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1251 				    "112-120,128,140-142,156,158,172,"
1252 				    "174,186,191,203-207,219-225,235-239,"
1253 				    "251-254",
1254 # else
1255 			    (char_u *)"@,48-57,_,192-255",
1256 # endif
1257 #endif
1258 				(char_u *)0L}},
1259     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1260 			    (char_u *)&p_isk, PV_ISK,
1261 			    {
1262 #ifdef EBCDIC
1263 			     (char_u *)"@,240-249,_",
1264 			     /* TODO: EBCDIC Check this! @ == isalpha()*/
1265 			     (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1266 				    "112-120,128,140-142,156,158,172,"
1267 				    "174,186,191,203-207,219-225,235-239,"
1268 				    "251-254",
1269 #else
1270 				(char_u *)"@,48-57,_",
1271 # if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1272 				(char_u *)"@,48-57,_,128-167,224-235"
1273 # else
1274 				(char_u *)"@,48-57,_,192-255"
1275 # endif
1276 #endif
1277 				}},
1278     {"isprint",	    "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1279 			    (char_u *)&p_isp, PV_NONE,
1280 			    {
1281 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
1282 		|| defined(VMS)
1283 			    (char_u *)"@,~-255",
1284 #else
1285 # ifdef EBCDIC
1286 			    /* all chars above 63 are printable */
1287 			    (char_u *)"63-255",
1288 # else
1289 			    (char_u *)"@,161-255",
1290 # endif
1291 #endif
1292 				(char_u *)0L}},
1293     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
1294 			    (char_u *)&p_js, PV_NONE,
1295 			    {(char_u *)TRUE, (char_u *)0L}},
1296     {"key",	    NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1297 #ifdef FEAT_CRYPT
1298 			    (char_u *)&p_key, PV_KEY,
1299 			    {(char_u *)"", (char_u *)0L}
1300 #else
1301 			    (char_u *)NULL, PV_NONE,
1302 			    {(char_u *)0L, (char_u *)0L}
1303 #endif
1304 			    },
1305     {"keymap",	    "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT,
1306 #ifdef FEAT_KEYMAP
1307 			    (char_u *)&p_keymap, PV_KMAP,
1308 			    {(char_u *)"", (char_u *)0L}
1309 #else
1310 			    (char_u *)NULL, PV_NONE,
1311 			    {(char_u *)"", (char_u *)0L}
1312 #endif
1313 	},
1314     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1315 #ifdef FEAT_VISUAL
1316 			    (char_u *)&p_km, PV_NONE,
1317 #else
1318 			    (char_u *)NULL, PV_NONE,
1319 #endif
1320 			    {(char_u *)"", (char_u *)0L}},
1321     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1322 			    (char_u *)&p_kp, OPT_BOTH(PV_KP),
1323 			    {
1324 #if defined(MSDOS) || defined(MSWIN)
1325 			    (char_u *)":help",
1326 #else
1327 #ifdef VMS
1328 			    (char_u *)"help",
1329 #else
1330 # if defined(OS2)
1331 			    (char_u *)"view /",
1332 # else
1333 #  ifdef USEMAN_S
1334 			    (char_u *)"man -s",
1335 #  else
1336 			    (char_u *)"man",
1337 #  endif
1338 # endif
1339 #endif
1340 #endif
1341 				(char_u *)0L}},
1342     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1343 #ifdef FEAT_LANGMAP
1344 			    (char_u *)&p_langmap, PV_NONE,
1345 			    {(char_u *)"",	/* unmatched } */
1346 #else
1347 			    (char_u *)NULL, PV_NONE,
1348 			    {(char_u *)NULL,
1349 #endif
1350 				(char_u *)0L}},
1351     {"langmenu",    "lm",   P_STRING|P_VI_DEF,
1352 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1353 			    (char_u *)&p_lm, PV_NONE,
1354 #else
1355 			    (char_u *)NULL, PV_NONE,
1356 #endif
1357 			    {(char_u *)"", (char_u *)0L}},
1358     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
1359 #ifdef FEAT_WINDOWS
1360 			    (char_u *)&p_ls, PV_NONE,
1361 #else
1362 			    (char_u *)NULL, PV_NONE,
1363 #endif
1364 			    {(char_u *)1L, (char_u *)0L}},
1365     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
1366 			    (char_u *)&p_lz, PV_NONE,
1367 			    {(char_u *)FALSE, (char_u *)0L}},
1368     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
1369 #ifdef FEAT_LINEBREAK
1370 			    (char_u *)VAR_WIN, PV_LBR,
1371 #else
1372 			    (char_u *)NULL, PV_NONE,
1373 #endif
1374 			    {(char_u *)FALSE, (char_u *)0L}},
1375     {"lines",	    NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1376 			    (char_u *)&Rows, PV_NONE,
1377 			    {
1378 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1379 			    (char_u *)25L,
1380 #else
1381 			    (char_u *)24L,
1382 #endif
1383 					    (char_u *)0L}},
1384     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
1385 #ifdef FEAT_GUI
1386 			    (char_u *)&p_linespace, PV_NONE,
1387 #else
1388 			    (char_u *)NULL, PV_NONE,
1389 #endif
1390 #ifdef FEAT_GUI_W32
1391 			    {(char_u *)1L, (char_u *)0L}
1392 #else
1393 			    {(char_u *)0L, (char_u *)0L}
1394 #endif
1395 			    },
1396     {"lisp",	    NULL,   P_BOOL|P_VI_DEF,
1397 #ifdef FEAT_LISP
1398 			    (char_u *)&p_lisp, PV_LISP,
1399 #else
1400 			    (char_u *)NULL, PV_NONE,
1401 #endif
1402 			    {(char_u *)FALSE, (char_u *)0L}},
1403     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1404 #ifdef FEAT_LISP
1405 			    (char_u *)&p_lispwords, PV_NONE,
1406 			    {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1407 #else
1408 			    (char_u *)NULL, PV_NONE,
1409 			    {(char_u *)"", (char_u *)0L}
1410 #endif
1411 			    },
1412     {"list",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
1413 			    (char_u *)VAR_WIN, PV_LIST,
1414 			    {(char_u *)FALSE, (char_u *)0L}},
1415     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1416 			    (char_u *)&p_lcs, PV_NONE,
1417 			    {(char_u *)"eol:$", (char_u *)0L}},
1418     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
1419 			    (char_u *)&p_lpl, PV_NONE,
1420 			    {(char_u *)TRUE, (char_u *)0L}},
1421     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
1422 			    (char_u *)&p_magic, PV_NONE,
1423 			    {(char_u *)TRUE, (char_u *)0L}},
1424     {"makeef",	    "mef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1425 #ifdef FEAT_QUICKFIX
1426 			    (char_u *)&p_mef, PV_NONE,
1427 			    {(char_u *)"", (char_u *)0L}
1428 #else
1429 			    (char_u *)NULL, PV_NONE,
1430 			    {(char_u *)NULL, (char_u *)0L}
1431 #endif
1432 			    },
1433     {"makeprg",	    "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1434 #ifdef FEAT_QUICKFIX
1435 			    (char_u *)&p_mp, OPT_BOTH(PV_MP),
1436 # ifdef VMS
1437 			    {(char_u *)"MMS", (char_u *)0L}
1438 # else
1439 			    {(char_u *)"make", (char_u *)0L}
1440 # endif
1441 #else
1442 			    (char_u *)NULL, PV_NONE,
1443 			    {(char_u *)NULL, (char_u *)0L}
1444 #endif
1445 			    },
1446     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1447 			    (char_u *)&p_mps, PV_MPS,
1448 			    {(char_u *)"(:),{:},[:]", (char_u *)0L}},
1449     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
1450 			    (char_u *)&p_mat, PV_NONE,
1451 			    {(char_u *)5L, (char_u *)0L}},
1452     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1453 #ifdef FEAT_EVAL
1454 			    (char_u *)&p_mfd, PV_NONE,
1455 #else
1456 			    (char_u *)NULL, PV_NONE,
1457 #endif
1458 			    {(char_u *)100L, (char_u *)0L}},
1459     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
1460 			    (char_u *)&p_mmd, PV_NONE,
1461 			    {(char_u *)1000L, (char_u *)0L}},
1462     {"maxmem",	    "mm",   P_NUM|P_VI_DEF,
1463 			    (char_u *)&p_mm, PV_NONE,
1464 			    {(char_u *)DFLT_MAXMEM, (char_u *)0L}},
1465     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
1466 			    (char_u *)&p_mmt, PV_NONE,
1467 			    {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}},
1468     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
1469 #ifdef FEAT_MENU
1470 			    (char_u *)&p_mis, PV_NONE,
1471 #else
1472 			    (char_u *)NULL, PV_NONE,
1473 #endif
1474 			    {(char_u *)25L, (char_u *)0L}},
1475     {"mesg",	    NULL,   P_BOOL|P_VI_DEF,
1476 			    (char_u *)NULL, PV_NONE,
1477 			    {(char_u *)FALSE, (char_u *)0L}},
1478     {"modeline",    "ml",   P_BOOL|P_VIM,
1479 			    (char_u *)&p_ml, PV_ML,
1480 			    {(char_u *)FALSE, (char_u *)TRUE}},
1481     {"modelines",   "mls",  P_NUM|P_VI_DEF,
1482 			    (char_u *)&p_mls, PV_NONE,
1483 			    {(char_u *)5L, (char_u *)0L}},
1484     {"modifiable",  "ma",   P_BOOL|P_VI_DEF|P_NOGLOB,
1485 			    (char_u *)&p_ma, PV_MA,
1486 			    {(char_u *)TRUE, (char_u *)0L}},
1487     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1488 			    (char_u *)&p_mod, PV_MOD,
1489 			    {(char_u *)FALSE, (char_u *)0L}},
1490     {"more",	    NULL,   P_BOOL|P_VIM,
1491 			    (char_u *)&p_more, PV_NONE,
1492 			    {(char_u *)FALSE, (char_u *)TRUE}},
1493     {"mouse",	    NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
1494 			    (char_u *)&p_mouse, PV_NONE,
1495 			    {
1496 #if defined(MSDOS) || defined(WIN3264)
1497 				(char_u *)"a",
1498 #else
1499 				(char_u *)"",
1500 #endif
1501 				(char_u *)0L}},
1502     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
1503 #ifdef FEAT_GUI
1504 			    (char_u *)&p_mousef, PV_NONE,
1505 #else
1506 			    (char_u *)NULL, PV_NONE,
1507 #endif
1508 			    {(char_u *)FALSE, (char_u *)0L}},
1509     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
1510 #ifdef FEAT_GUI
1511 			    (char_u *)&p_mh, PV_NONE,
1512 #else
1513 			    (char_u *)NULL, PV_NONE,
1514 #endif
1515 			    {(char_u *)TRUE, (char_u *)0L}},
1516     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
1517 			    (char_u *)&p_mousem, PV_NONE,
1518 			    {
1519 #if defined(MSDOS) || defined(MSWIN)
1520 				(char_u *)"popup",
1521 #else
1522 # if defined(MACOS)
1523 				(char_u *)"popup_setpos",
1524 # else
1525 				(char_u *)"extend",
1526 # endif
1527 #endif
1528 				(char_u *)0L}},
1529     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1530 #ifdef FEAT_MOUSESHAPE
1531 			    (char_u *)&p_mouseshape, PV_NONE,
1532 			    {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1533 #else
1534 			    (char_u *)NULL, PV_NONE,
1535 			    {(char_u *)NULL, (char_u *)0L}
1536 #endif
1537 			    },
1538     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
1539 			    (char_u *)&p_mouset, PV_NONE,
1540 			    {(char_u *)500L, (char_u *)0L}},
1541     {"novice",	    NULL,   P_BOOL|P_VI_DEF,
1542 			    (char_u *)NULL, PV_NONE,
1543 			    {(char_u *)FALSE, (char_u *)0L}},
1544     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1545 			    (char_u *)&p_nf, PV_NF,
1546 			    {(char_u *)"octal,hex", (char_u *)0L}},
1547     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
1548 			    (char_u *)VAR_WIN, PV_NU,
1549 			    {(char_u *)FALSE, (char_u *)0L}},
1550     {"numberwidth", "nuw",  P_NUM|P_RWIN|P_VIM,
1551 #ifdef FEAT_LINEBREAK
1552 			    (char_u *)VAR_WIN, PV_NUW,
1553 #else
1554 			    (char_u *)NULL, PV_NONE,
1555 #endif
1556 			    {(char_u *)8L, (char_u *)4L}},
1557     {"open",	    NULL,   P_BOOL|P_VI_DEF,
1558 			    (char_u *)NULL, PV_NONE,
1559 			    {(char_u *)FALSE, (char_u *)0L}},
1560     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
1561 			    (char_u *)NULL, PV_NONE,
1562 			    {(char_u *)FALSE, (char_u *)0L}},
1563     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
1564 #ifdef FEAT_OSFILETYPE
1565 			    (char_u *)&p_oft, PV_OFT,
1566 			    {(char_u *)DFLT_OFT, (char_u *)0L}
1567 #else
1568 			    (char_u *)NULL, PV_NONE,
1569 			    {(char_u *)0L, (char_u *)0L}
1570 #endif
1571 			    },
1572     {"paragraphs",  "para", P_STRING|P_VI_DEF,
1573 			    (char_u *)&p_para, PV_NONE,
1574 			    {(char_u *)"IPLPPPQPP LIpplpipbp", (char_u *)0L}},
1575     {"paste",	    NULL,   P_BOOL|P_VI_DEF,
1576 			    (char_u *)&p_paste, PV_NONE,
1577 			    {(char_u *)FALSE, (char_u *)0L}},
1578     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
1579 			    (char_u *)&p_pt, PV_NONE,
1580 			    {(char_u *)"", (char_u *)0L}},
1581     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
1582 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1583 			    (char_u *)&p_pex, PV_NONE,
1584 			    {(char_u *)"", (char_u *)0L}
1585 #else
1586 			    (char_u *)NULL, PV_NONE,
1587 			    {(char_u *)0L, (char_u *)0L}
1588 #endif
1589 			    },
1590     {"patchmode",   "pm",   P_STRING|P_VI_DEF,
1591 			    (char_u *)&p_pm, PV_NONE,
1592 			    {(char_u *)"", (char_u *)0L}},
1593     {"path",	    "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1594 			    (char_u *)&p_path, OPT_BOTH(PV_PATH),
1595 			    {
1596 #if defined AMIGA || defined MSDOS || defined MSWIN
1597 			    (char_u *)".,,",
1598 #else
1599 # if defined(__EMX__)
1600 			    (char_u *)".,/emx/include,,",
1601 # else /* Unix, probably */
1602 			    (char_u *)".,/usr/include,,",
1603 # endif
1604 #endif
1605 				(char_u *)0L}},
1606     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1607 			    (char_u *)&p_pi, PV_PI,
1608 			    {(char_u *)FALSE, (char_u *)0L}},
1609     {"previewheight", "pvh", P_NUM|P_VI_DEF,
1610 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1611 			    (char_u *)&p_pvh, PV_NONE,
1612 #else
1613 			    (char_u *)NULL, PV_NONE,
1614 #endif
1615 			    {(char_u *)12L, (char_u *)0L}},
1616     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1617 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1618 			    (char_u *)VAR_WIN, PV_PVW,
1619 #else
1620 			    (char_u *)NULL, PV_NONE,
1621 #endif
1622 			    {(char_u *)FALSE, (char_u *)0L}},
1623     {"printdevice", "pdev", P_STRING|P_VI_DEF,
1624 #ifdef FEAT_PRINTER
1625 			    (char_u *)&p_pdev, PV_NONE,
1626 			    {(char_u *)"", (char_u *)0L}
1627 #else
1628 			    (char_u *)NULL, PV_NONE,
1629 			    {(char_u *)NULL, (char_u *)0L}
1630 #endif
1631 			    },
1632     {"printencoding", "penc", P_STRING|P_VI_DEF,
1633 #ifdef FEAT_POSTSCRIPT
1634 			    (char_u *)&p_penc, PV_NONE,
1635 			    {(char_u *)"", (char_u *)0L}
1636 #else
1637 			    (char_u *)NULL, PV_NONE,
1638 			    {(char_u *)NULL, (char_u *)0L}
1639 #endif
1640 			    },
1641     {"printexpr", "pexpr",  P_STRING|P_VI_DEF,
1642 #ifdef FEAT_POSTSCRIPT
1643 			    (char_u *)&p_pexpr, PV_NONE,
1644 			    {(char_u *)"", (char_u *)0L}
1645 #else
1646 			    (char_u *)NULL, PV_NONE,
1647 			    {(char_u *)NULL, (char_u *)0L}
1648 #endif
1649 			    },
1650     {"printfont", "pfn",    P_STRING|P_VI_DEF,
1651 #ifdef FEAT_PRINTER
1652 			    (char_u *)&p_pfn, PV_NONE,
1653 			    {
1654 # ifdef MSWIN
1655 				(char_u *)"Courier_New:h10",
1656 # else
1657 				(char_u *)"courier",
1658 # endif
1659 				(char_u *)0L}
1660 #else
1661 			    (char_u *)NULL, PV_NONE,
1662 			    {(char_u *)NULL, (char_u *)0L}
1663 #endif
1664 			    },
1665     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
1666 #ifdef FEAT_PRINTER
1667 			    (char_u *)&p_header, PV_NONE,
1668 			    {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
1669 #else
1670 			    (char_u *)NULL, PV_NONE,
1671 			    {(char_u *)NULL, (char_u *)0L}
1672 #endif
1673 			    },
1674     {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1675 #ifdef FEAT_PRINTER
1676 			    (char_u *)&p_popt, PV_NONE,
1677 			    {(char_u *)"", (char_u *)0L}
1678 #else
1679 			    (char_u *)NULL, PV_NONE,
1680 			    {(char_u *)NULL, (char_u *)0L}
1681 #endif
1682 			    },
1683     {"prompt",	    NULL,   P_BOOL|P_VI_DEF,
1684 			    (char_u *)NULL, PV_NONE,
1685 			    {(char_u *)FALSE, (char_u *)0L}},
1686     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
1687 #ifdef FEAT_TEXTOBJ
1688 			    (char_u *)&p_qe, PV_QE,
1689 			    {(char_u *)"\\", (char_u *)0L}
1690 #else
1691 			    (char_u *)NULL, PV_NONE,
1692 			    {(char_u *)NULL, (char_u *)0L}
1693 #endif
1694 			    },
1695     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
1696 			    (char_u *)&p_ro, PV_RO,
1697 			    {(char_u *)FALSE, (char_u *)0L}},
1698     {"redraw",	    NULL,   P_BOOL|P_VI_DEF,
1699 			    (char_u *)NULL, PV_NONE,
1700 			    {(char_u *)FALSE, (char_u *)0L}},
1701     {"remap",	    NULL,   P_BOOL|P_VI_DEF,
1702 			    (char_u *)&p_remap, PV_NONE,
1703 			    {(char_u *)TRUE, (char_u *)0L}},
1704     {"report",	    NULL,   P_NUM|P_VI_DEF,
1705 			    (char_u *)&p_report, PV_NONE,
1706 			    {(char_u *)2L, (char_u *)0L}},
1707     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
1708 #ifdef WIN3264
1709 			    (char_u *)&p_rs, PV_NONE,
1710 #else
1711 			    (char_u *)NULL, PV_NONE,
1712 #endif
1713 			    {(char_u *)TRUE, (char_u *)0L}},
1714     {"revins",	    "ri",   P_BOOL|P_VI_DEF|P_VIM,
1715 #ifdef FEAT_RIGHTLEFT
1716 			    (char_u *)&p_ri, PV_NONE,
1717 #else
1718 			    (char_u *)NULL, PV_NONE,
1719 #endif
1720 			    {(char_u *)FALSE, (char_u *)0L}},
1721     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
1722 #ifdef FEAT_RIGHTLEFT
1723 			    (char_u *)VAR_WIN, PV_RL,
1724 #else
1725 			    (char_u *)NULL, PV_NONE,
1726 #endif
1727 			    {(char_u *)FALSE, (char_u *)0L}},
1728     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
1729 #ifdef FEAT_RIGHTLEFT
1730 			    (char_u *)VAR_WIN, PV_RLC,
1731 			    {(char_u *)"search", (char_u *)NULL}
1732 #else
1733 			    (char_u *)NULL, PV_NONE,
1734 			    {(char_u *)NULL, (char_u *)0L}
1735 #endif
1736 			    },
1737     {"ruler",	    "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
1738 #ifdef FEAT_CMDL_INFO
1739 			    (char_u *)&p_ru, PV_NONE,
1740 #else
1741 			    (char_u *)NULL, PV_NONE,
1742 #endif
1743 			    {(char_u *)FALSE, (char_u *)0L}},
1744     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1745 #ifdef FEAT_STL_OPT
1746 			    (char_u *)&p_ruf, PV_NONE,
1747 #else
1748 			    (char_u *)NULL, PV_NONE,
1749 #endif
1750 			    {(char_u *)"", (char_u *)0L}},
1751     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
1752 			    (char_u *)&p_rtp, PV_NONE,
1753 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}},
1754     {"scroll",	    "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
1755 			    (char_u *)VAR_WIN, PV_SCROLL,
1756 			    {(char_u *)12L, (char_u *)0L}},
1757     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
1758 #ifdef FEAT_SCROLLBIND
1759 			    (char_u *)VAR_WIN, PV_SCBIND,
1760 #else
1761 			    (char_u *)NULL, PV_NONE,
1762 #endif
1763 			    {(char_u *)FALSE, (char_u *)0L}},
1764     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
1765 			    (char_u *)&p_sj, PV_NONE,
1766 			    {(char_u *)1L, (char_u *)0L}},
1767     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
1768 			    (char_u *)&p_so, PV_NONE,
1769 			    {(char_u *)0L, (char_u *)0L}},
1770     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1771 #ifdef FEAT_SCROLLBIND
1772 			    (char_u *)&p_sbo, PV_NONE,
1773 			    {(char_u *)"ver,jump", (char_u *)0L}
1774 #else
1775 			    (char_u *)NULL, PV_NONE,
1776 			    {(char_u *)0L, (char_u *)0L}
1777 #endif
1778 			    },
1779     {"sections",    "sect", P_STRING|P_VI_DEF,
1780 			    (char_u *)&p_sections, PV_NONE,
1781 			    {(char_u *)"SHNHH HUnhsh", (char_u *)0L}},
1782     {"secure",	    NULL,   P_BOOL|P_VI_DEF|P_SECURE,
1783 			    (char_u *)&p_secure, PV_NONE,
1784 			    {(char_u *)FALSE, (char_u *)0L}},
1785     {"selection",   "sel",  P_STRING|P_VI_DEF,
1786 #ifdef FEAT_VISUAL
1787 			    (char_u *)&p_sel, PV_NONE,
1788 #else
1789 			    (char_u *)NULL, PV_NONE,
1790 #endif
1791 			    {(char_u *)"inclusive", (char_u *)0L}},
1792     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1793 #ifdef FEAT_VISUAL
1794 			    (char_u *)&p_slm, PV_NONE,
1795 #else
1796 			    (char_u *)NULL, PV_NONE,
1797 #endif
1798 			    {(char_u *)"", (char_u *)0L}},
1799     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1800 #ifdef FEAT_SESSION
1801 			    (char_u *)&p_ssop, PV_NONE,
1802 		 {(char_u *)"blank,buffers,curdir,folds,help,options,winsize",
1803 							       (char_u *)0L}
1804 #else
1805 			    (char_u *)NULL, PV_NONE,
1806 			    {(char_u *)0L, (char_u *)0L}
1807 #endif
1808 			    },
1809     {"shell",	    "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1810 			    (char_u *)&p_sh, PV_NONE,
1811 			    {
1812 #ifdef VMS
1813 			    (char_u *)"-",
1814 #else
1815 # if defined(MSDOS)
1816 			    (char_u *)"command",
1817 # else
1818 #  if defined(WIN16)
1819 			    (char_u *)"command.com",
1820 #  else
1821 #   if defined(WIN3264)
1822 			    (char_u *)"",	/* set in set_init_1() */
1823 #   else
1824 #    if defined(OS2)
1825 			    (char_u *)"cmd.exe",
1826 #    else
1827 #     if defined(ARCHIE)
1828 			    (char_u *)"gos",
1829 #     else
1830 			    (char_u *)"sh",
1831 #     endif
1832 #    endif
1833 #   endif
1834 #  endif
1835 # endif
1836 #endif /* VMS */
1837 				(char_u *)0L}},
1838     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
1839 			    (char_u *)&p_shcf, PV_NONE,
1840 			    {
1841 #if defined(MSDOS) || defined(MSWIN)
1842 			    (char_u *)"/c",
1843 #else
1844 # if defined(OS2)
1845 			    (char_u *)"/c",
1846 # else
1847 			    (char_u *)"-c",
1848 # endif
1849 #endif
1850 				(char_u *)0L}},
1851     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
1852 #ifdef FEAT_QUICKFIX
1853 			    (char_u *)&p_sp, PV_NONE,
1854 			    {
1855 #if defined(UNIX) || defined(OS2)
1856 # ifdef ARCHIE
1857 			    (char_u *)"2>",
1858 # else
1859 			    (char_u *)"| tee",
1860 # endif
1861 #else
1862 			    (char_u *)">",
1863 #endif
1864 				(char_u *)0L}
1865 #else
1866 			    (char_u *)NULL, PV_NONE,
1867 			    {(char_u *)0L, (char_u *)0L}
1868 #endif
1869     },
1870     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
1871 			    (char_u *)&p_shq, PV_NONE,
1872 			    {(char_u *)"", (char_u *)0L}},
1873     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
1874 			    (char_u *)&p_srr, PV_NONE,
1875 			    {(char_u *)">", (char_u *)0L}},
1876     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
1877 #ifdef BACKSLASH_IN_FILENAME
1878 			    (char_u *)&p_ssl, PV_NONE,
1879 #else
1880 			    (char_u *)NULL, PV_NONE,
1881 #endif
1882 			    {(char_u *)FALSE, (char_u *)0L}},
1883     {"shelltype",   "st",   P_NUM|P_VI_DEF,
1884 #ifdef AMIGA
1885 			    (char_u *)&p_st, PV_NONE,
1886 #else
1887 			    (char_u *)NULL, PV_NONE,
1888 #endif
1889 			    {(char_u *)0L, (char_u *)0L}},
1890     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
1891 			    (char_u *)&p_sxq, PV_NONE,
1892 			    {
1893 #if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
1894 			    (char_u *)"\"",
1895 #else
1896 			    (char_u *)"",
1897 #endif
1898 				(char_u *)0L}},
1899     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
1900 			    (char_u *)&p_sr, PV_NONE,
1901 			    {(char_u *)FALSE, (char_u *)0L}},
1902     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
1903 			    (char_u *)&p_sw, PV_SW,
1904 			    {(char_u *)8L, (char_u *)0L}},
1905     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
1906 			    (char_u *)&p_shm, PV_NONE,
1907 			    {(char_u *)"", (char_u *)"filnxtToO"}},
1908     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
1909 #ifdef SHORT_FNAME
1910 			    (char_u *)NULL, PV_NONE,
1911 #else
1912 			    (char_u *)&p_sn, PV_SN,
1913 #endif
1914 			    {(char_u *)FALSE, (char_u *)0L}},
1915     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
1916 #ifdef FEAT_LINEBREAK
1917 			    (char_u *)&p_sbr, PV_NONE,
1918 #else
1919 			    (char_u *)NULL, PV_NONE,
1920 #endif
1921 			    {(char_u *)"", (char_u *)0L}},
1922     {"showcmd",	    "sc",   P_BOOL|P_VIM,
1923 #ifdef FEAT_CMDL_INFO
1924 			    (char_u *)&p_sc, PV_NONE,
1925 #else
1926 			    (char_u *)NULL, PV_NONE,
1927 #endif
1928 			    {(char_u *)FALSE,
1929 #ifdef UNIX
1930 				(char_u *)FALSE
1931 #else
1932 				(char_u *)TRUE
1933 #endif
1934 				}},
1935     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
1936 			    (char_u *)&p_sft, PV_NONE,
1937 			    {(char_u *)FALSE, (char_u *)0L}},
1938     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
1939 			    (char_u *)&p_sm, PV_NONE,
1940 			    {(char_u *)FALSE, (char_u *)0L}},
1941     {"showmode",    "smd",  P_BOOL|P_VIM,
1942 			    (char_u *)&p_smd, PV_NONE,
1943 			    {(char_u *)FALSE, (char_u *)TRUE}},
1944     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
1945 			    (char_u *)&p_ss, PV_NONE,
1946 			    {(char_u *)0L, (char_u *)0L}},
1947     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
1948 			    (char_u *)&p_siso, PV_NONE,
1949 			    {(char_u *)0L, (char_u *)0L}},
1950     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
1951 			    (char_u *)NULL, PV_NONE,
1952 			    {(char_u *)FALSE, (char_u *)0L}},
1953     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
1954 			    (char_u *)&p_scs, PV_NONE,
1955 			    {(char_u *)FALSE, (char_u *)0L}},
1956     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
1957 #ifdef FEAT_SMARTINDENT
1958 			    (char_u *)&p_si, PV_SI,
1959 #else
1960 			    (char_u *)NULL, PV_NONE,
1961 #endif
1962 			    {(char_u *)FALSE, (char_u *)0L}},
1963     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
1964 			    (char_u *)&p_sta, PV_NONE,
1965 			    {(char_u *)FALSE, (char_u *)0L}},
1966     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
1967 			    (char_u *)&p_sts, PV_STS,
1968 			    {(char_u *)0L, (char_u *)0L}},
1969     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
1970 			    (char_u *)NULL, PV_NONE,
1971 			    {(char_u *)FALSE, (char_u *)0L}},
1972     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
1973 #ifdef FEAT_WINDOWS
1974 			    (char_u *)&p_sb, PV_NONE,
1975 #else
1976 			    (char_u *)NULL, PV_NONE,
1977 #endif
1978 			    {(char_u *)FALSE, (char_u *)0L}},
1979     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
1980 #ifdef FEAT_VERTSPLIT
1981 			    (char_u *)&p_spr, PV_NONE,
1982 #else
1983 			    (char_u *)NULL, PV_NONE,
1984 #endif
1985 			    {(char_u *)FALSE, (char_u *)0L}},
1986     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
1987 			    (char_u *)&p_sol, PV_NONE,
1988 			    {(char_u *)TRUE, (char_u *)0L}},
1989     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
1990 #ifdef FEAT_STL_OPT
1991 			    (char_u *)&p_stl, PV_NONE,
1992 #else
1993 			    (char_u *)NULL, PV_NONE,
1994 #endif
1995 			    {(char_u *)"", (char_u *)0L}},
1996     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1997 			    (char_u *)&p_su, PV_NONE,
1998 			    {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
1999 				(char_u *)0L}},
2000     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
2001 #if defined(FEAT_SEARCHPATH)
2002 			    (char_u *)&p_sua, PV_SUA,
2003 			    {(char_u *)"", (char_u *)0L}
2004 #else
2005 			    (char_u *)NULL, PV_NONE,
2006 			    {(char_u *)0L, (char_u *)0L}
2007 #endif
2008 			    },
2009     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
2010 			    (char_u *)&p_swf, PV_SWF,
2011 			    {(char_u *)TRUE, (char_u *)0L}},
2012     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
2013 			    (char_u *)&p_sws, PV_NONE,
2014 			    {(char_u *)"fsync", (char_u *)0L}},
2015     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2016 			    (char_u *)&p_swb, PV_NONE,
2017 			    {(char_u *)"", (char_u *)0L}},
2018     {"syntax",	    "syn",  P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
2019 #ifdef FEAT_SYN_HL
2020 			    (char_u *)&p_syn, PV_SYN,
2021 			    {(char_u *)"", (char_u *)0L}
2022 #else
2023 			    (char_u *)NULL, PV_NONE,
2024 			    {(char_u *)0L, (char_u *)0L}
2025 #endif
2026 			    },
2027     {"tabstop",	    "ts",   P_NUM|P_VI_DEF|P_RBUF,
2028 			    (char_u *)&p_ts, PV_TS,
2029 			    {(char_u *)8L, (char_u *)0L}},
2030     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
2031 			    (char_u *)&p_tbs, PV_NONE,
2032 #ifdef VMS	/* binary searching doesn't appear to work on VMS */
2033 			    {(char_u *)0L, (char_u *)0L}
2034 #else
2035 			    {(char_u *)TRUE, (char_u *)0L}
2036 #endif
2037 			    },
2038     {"taglength",   "tl",   P_NUM|P_VI_DEF,
2039 			    (char_u *)&p_tl, PV_NONE,
2040 			    {(char_u *)0L, (char_u *)0L}},
2041     {"tagrelative", "tr",   P_BOOL|P_VIM,
2042 			    (char_u *)&p_tr, PV_NONE,
2043 			    {(char_u *)FALSE, (char_u *)TRUE}},
2044     {"tags",	    "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2045 			    (char_u *)&p_tags, OPT_BOTH(PV_TAGS),
2046 			    {
2047 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2048 			    (char_u *)"./tags,./TAGS,tags,TAGS",
2049 #else
2050 			    (char_u *)"./tags,tags",
2051 #endif
2052 				(char_u *)0L}},
2053     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
2054 			    (char_u *)&p_tgst, PV_NONE,
2055 			    {(char_u *)TRUE, (char_u *)0L}},
2056     {"term",	    NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2057 			    (char_u *)&T_NAME, PV_NONE,
2058 			    {(char_u *)"", (char_u *)0L}},
2059     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
2060 #ifdef FEAT_ARABIC
2061 			    (char_u *)&p_tbidi, PV_NONE,
2062 #else
2063 			    (char_u *)NULL, PV_NONE,
2064 #endif
2065 			    {(char_u *)FALSE, (char_u *)0L}},
2066     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2067 #ifdef FEAT_MBYTE
2068 			    (char_u *)&p_tenc, PV_NONE,
2069 			    {(char_u *)"", (char_u *)0L}
2070 #else
2071 			    (char_u *)NULL, PV_NONE,
2072 			    {(char_u *)0L, (char_u *)0L}
2073 #endif
2074 			    },
2075     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
2076 			    (char_u *)&p_terse, PV_NONE,
2077 			    {(char_u *)FALSE, (char_u *)0L}},
2078     {"textauto",    "ta",   P_BOOL|P_VIM,
2079 			    (char_u *)&p_ta, PV_NONE,
2080 			    {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}},
2081     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
2082 			    (char_u *)&p_tx, PV_TX,
2083 			    {
2084 #ifdef USE_CRNL
2085 			    (char_u *)TRUE,
2086 #else
2087 			    (char_u *)FALSE,
2088 #endif
2089 				(char_u *)0L}},
2090     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM,
2091 			    (char_u *)&p_tw, PV_TW,
2092 			    {(char_u *)0L, (char_u *)0L}},
2093     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2094 #ifdef FEAT_INS_EXPAND
2095 			    (char_u *)&p_tsr, OPT_BOTH(PV_TSR),
2096 #else
2097 			    (char_u *)NULL, PV_NONE,
2098 #endif
2099 			    {(char_u *)"", (char_u *)0L}},
2100     {"tildeop",	    "top",  P_BOOL|P_VI_DEF|P_VIM,
2101 			    (char_u *)&p_to, PV_NONE,
2102 			    {(char_u *)FALSE, (char_u *)0L}},
2103     {"timeout",	    "to",   P_BOOL|P_VI_DEF,
2104 			    (char_u *)&p_timeout, PV_NONE,
2105 			    {(char_u *)TRUE, (char_u *)0L}},
2106     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
2107 			    (char_u *)&p_tm, PV_NONE,
2108 			    {(char_u *)1000L, (char_u *)0L}},
2109     {"title",	    NULL,   P_BOOL|P_VI_DEF,
2110 #ifdef FEAT_TITLE
2111 			    (char_u *)&p_title, PV_NONE,
2112 #else
2113 			    (char_u *)NULL, PV_NONE,
2114 #endif
2115 			    {(char_u *)FALSE, (char_u *)0L}},
2116     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
2117 #ifdef FEAT_TITLE
2118 			    (char_u *)&p_titlelen, PV_NONE,
2119 #else
2120 			    (char_u *)NULL, PV_NONE,
2121 #endif
2122 			    {(char_u *)85L, (char_u *)0L}},
2123     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT,
2124 #ifdef FEAT_TITLE
2125 			    (char_u *)&p_titleold, PV_NONE,
2126 			    {(char_u *)N_("Thanks for flying Vim"),
2127 							       (char_u *)0L}
2128 #else
2129 			    (char_u *)NULL, PV_NONE,
2130 			    {(char_u *)0L, (char_u *)0L}
2131 #endif
2132 			    },
2133     {"titlestring", NULL,   P_STRING|P_VI_DEF,
2134 #ifdef FEAT_TITLE
2135 			    (char_u *)&p_titlestring, PV_NONE,
2136 #else
2137 			    (char_u *)NULL, PV_NONE,
2138 #endif
2139 			    {(char_u *)"", (char_u *)0L}},
2140 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2141     {"toolbar",     "tb",   P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2142 			    (char_u *)&p_toolbar, PV_NONE,
2143 			    {(char_u *)"icons,tooltips", (char_u *)0L}},
2144 #endif
2145 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
2146     {"toolbariconsize",	"tbis", P_STRING|P_VI_DEF,
2147 			    (char_u *)&p_tbis, PV_NONE,
2148 			    {(char_u *)"small", (char_u *)0L}},
2149 #endif
2150     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
2151 			    (char_u *)&p_ttimeout, PV_NONE,
2152 			    {(char_u *)FALSE, (char_u *)0L}},
2153     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
2154 			    (char_u *)&p_ttm, PV_NONE,
2155 			    {(char_u *)-1L, (char_u *)0L}},
2156     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
2157 			    (char_u *)&p_tbi, PV_NONE,
2158 			    {(char_u *)TRUE, (char_u *)0L}},
2159     {"ttyfast",	    "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
2160 			    (char_u *)&p_tf, PV_NONE,
2161 			    {(char_u *)FALSE, (char_u *)0L}},
2162     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2163 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2164 			    (char_u *)&p_ttym, PV_NONE,
2165 #else
2166 			    (char_u *)NULL, PV_NONE,
2167 #endif
2168 			    {(char_u *)"", (char_u *)0L}},
2169     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
2170 			    (char_u *)&p_ttyscroll, PV_NONE,
2171 			    {(char_u *)999L, (char_u *)0L}},
2172     {"ttytype",	    "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2173 			    (char_u *)&T_NAME, PV_NONE,
2174 			    {(char_u *)"", (char_u *)0L}},
2175     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
2176 			    (char_u *)&p_ul, PV_NONE,
2177 			    {
2178 #if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2179 			    (char_u *)1000L,
2180 #else
2181 			    (char_u *)100L,
2182 #endif
2183 				(char_u *)0L}},
2184     {"updatecount", "uc",   P_NUM|P_VI_DEF,
2185 			    (char_u *)&p_uc, PV_NONE,
2186 			    {(char_u *)200L, (char_u *)0L}},
2187     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
2188 			    (char_u *)&p_ut, PV_NONE,
2189 			    {(char_u *)4000L, (char_u *)0L}},
2190     {"verbose",	    "vbs",  P_NUM|P_VI_DEF,
2191 			    (char_u *)&p_verbose, PV_NONE,
2192 			    {(char_u *)0L, (char_u *)0L}},
2193     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2194 #ifdef FEAT_SESSION
2195 			    (char_u *)&p_vdir, PV_NONE,
2196 			    {(char_u *)DFLT_VDIR, (char_u *)0L}
2197 #else
2198 			    (char_u *)NULL, PV_NONE,
2199 			    {(char_u *)0L, (char_u *)0L}
2200 #endif
2201 			    },
2202     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2203 #ifdef FEAT_SESSION
2204 			    (char_u *)&p_vop, PV_NONE,
2205 			    {(char_u *)"folds,options,cursor", (char_u *)0L}
2206 #else
2207 			    (char_u *)NULL, PV_NONE,
2208 			    {(char_u *)0L, (char_u *)0L}
2209 #endif
2210 			    },
2211     {"viminfo",	    "vi",   P_STRING|P_COMMA|P_NODUP|P_SECURE,
2212 #ifdef FEAT_VIMINFO
2213 			    (char_u *)&p_viminfo, PV_NONE,
2214 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2215 			    {(char_u *)"", (char_u *)"'20,<50,s10,h,rA:,rB:"}
2216 #else
2217 # ifdef AMIGA
2218 			    {(char_u *)"",
2219 				 (char_u *)"'20,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2220 # else
2221 			    {(char_u *)"", (char_u *)"'20,<50,s10,h"}
2222 # endif
2223 #endif
2224 #else
2225 			    (char_u *)NULL, PV_NONE,
2226 			    {(char_u *)0L, (char_u *)0L}
2227 #endif
2228 			    },
2229     {"virtualedit", "ve",   P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM,
2230 #ifdef FEAT_VIRTUALEDIT
2231 			    (char_u *)&p_ve, PV_NONE,
2232 			    {(char_u *)"", (char_u *)""}
2233 #else
2234 			    (char_u *)NULL, PV_NONE,
2235 			    {(char_u *)0L, (char_u *)0L}
2236 #endif
2237 			    },
2238     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
2239 			    (char_u *)&p_vb, PV_NONE,
2240 			    {(char_u *)FALSE, (char_u *)0L}},
2241     {"w300",	    NULL,   P_NUM|P_VI_DEF,
2242 			    (char_u *)NULL, PV_NONE,
2243 			    {(char_u *)0L, (char_u *)0L}},
2244     {"w1200",	    NULL,   P_NUM|P_VI_DEF,
2245 			    (char_u *)NULL, PV_NONE,
2246 			    {(char_u *)0L, (char_u *)0L}},
2247     {"w9600",	    NULL,   P_NUM|P_VI_DEF,
2248 			    (char_u *)NULL, PV_NONE,
2249 			    {(char_u *)0L, (char_u *)0L}},
2250     {"warn",	    NULL,   P_BOOL|P_VI_DEF,
2251 			    (char_u *)&p_warn, PV_NONE,
2252 			    {(char_u *)TRUE, (char_u *)0L}},
2253     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
2254 			    (char_u *)&p_wiv, PV_NONE,
2255 			    {(char_u *)FALSE, (char_u *)0L}},
2256     {"whichwrap",   "ww",   P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2257 			    (char_u *)&p_ww, PV_NONE,
2258 			    {(char_u *)"", (char_u *)"b,s"}},
2259     {"wildchar",    "wc",   P_NUM|P_VIM,
2260 			    (char_u *)&p_wc, PV_NONE,
2261 			    {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}},
2262     {"wildcharm",   "wcm",   P_NUM|P_VI_DEF,
2263 			    (char_u *)&p_wcm, PV_NONE,
2264 			    {(char_u *)0L, (char_u *)0L}},
2265     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2266 #ifdef FEAT_WILDIGN
2267 			    (char_u *)&p_wig, PV_NONE,
2268 #else
2269 			    (char_u *)NULL, PV_NONE,
2270 #endif
2271 			    {(char_u *)"", (char_u *)0L}},
2272     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
2273 #ifdef FEAT_WILDMENU
2274 			    (char_u *)&p_wmnu, PV_NONE,
2275 #else
2276 			    (char_u *)NULL, PV_NONE,
2277 #endif
2278 			    {(char_u *)FALSE, (char_u *)0L}},
2279     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2280 			    (char_u *)&p_wim, PV_NONE,
2281 			    {(char_u *)"full", (char_u *)0L}},
2282     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
2283 #ifdef FEAT_WAK
2284 			    (char_u *)&p_wak, PV_NONE,
2285 			    {(char_u *)"menu", (char_u *)0L}
2286 #else
2287 			    (char_u *)NULL, PV_NONE,
2288 			    {(char_u *)NULL, (char_u *)0L}
2289 #endif
2290 			    },
2291     {"window",	    "wi",   P_NUM|P_VI_DEF,
2292 			    (char_u *)NULL, PV_NONE,
2293 			    {(char_u *)0L, (char_u *)0L}},
2294     {"winheight",   "wh",   P_NUM|P_VI_DEF,
2295 #ifdef FEAT_WINDOWS
2296 			    (char_u *)&p_wh, PV_NONE,
2297 #else
2298 			    (char_u *)NULL, PV_NONE,
2299 #endif
2300 			    {(char_u *)1L, (char_u *)0L}},
2301     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
2302 #if defined(FEAT_WINDOWS)
2303 			    (char_u *)VAR_WIN, PV_WFH,
2304 #else
2305 			    (char_u *)NULL, PV_NONE,
2306 #endif
2307 			    {(char_u *)FALSE, (char_u *)0L}},
2308     {"winminheight", "wmh", P_NUM|P_VI_DEF,
2309 #ifdef FEAT_WINDOWS
2310 			    (char_u *)&p_wmh, PV_NONE,
2311 #else
2312 			    (char_u *)NULL, PV_NONE,
2313 #endif
2314 			    {(char_u *)1L, (char_u *)0L}},
2315     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2316 #ifdef FEAT_VERTSPLIT
2317 			    (char_u *)&p_wmw, PV_NONE,
2318 #else
2319 			    (char_u *)NULL, PV_NONE,
2320 #endif
2321 			    {(char_u *)1L, (char_u *)0L}},
2322     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
2323 #ifdef FEAT_VERTSPLIT
2324 			    (char_u *)&p_wiw, PV_NONE,
2325 #else
2326 			    (char_u *)NULL, PV_NONE,
2327 #endif
2328 			    {(char_u *)20L, (char_u *)0L}},
2329     {"wrap",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
2330 			    (char_u *)VAR_WIN, PV_WRAP,
2331 			    {(char_u *)TRUE, (char_u *)0L}},
2332     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
2333 			    (char_u *)&p_wm, PV_WM,
2334 			    {(char_u *)0L, (char_u *)0L}},
2335     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
2336 			    (char_u *)&p_ws, PV_NONE,
2337 			    {(char_u *)TRUE, (char_u *)0L}},
2338     {"write",	    NULL,   P_BOOL|P_VI_DEF,
2339 			    (char_u *)&p_write, PV_NONE,
2340 			    {(char_u *)TRUE, (char_u *)0L}},
2341     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
2342 			    (char_u *)&p_wa, PV_NONE,
2343 			    {(char_u *)FALSE, (char_u *)0L}},
2344     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
2345 			    (char_u *)&p_wb, PV_NONE,
2346 			    {
2347 #ifdef FEAT_WRITEBACKUP
2348 			    (char_u *)TRUE,
2349 #else
2350 			    (char_u *)FALSE,
2351 #endif
2352 				(char_u *)0L}},
2353     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
2354 			    (char_u *)&p_wd, PV_NONE,
2355 			    {(char_u *)0L, (char_u *)0L}},
2356 
2357 /* terminal output codes */
2358 #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL, \
2359 			    (char_u *)&vvv, PV_NONE, \
2360 			    {(char_u *)"", (char_u *)0L}},
2361 
2362     p_term("t_AB", T_CAB)
2363     p_term("t_AF", T_CAF)
2364     p_term("t_AL", T_CAL)
2365     p_term("t_al", T_AL)
2366     p_term("t_bc", T_BC)
2367     p_term("t_cd", T_CD)
2368     p_term("t_ce", T_CE)
2369     p_term("t_cl", T_CL)
2370     p_term("t_cm", T_CM)
2371     p_term("t_Co", T_CCO)
2372     p_term("t_CS", T_CCS)
2373     p_term("t_cs", T_CS)
2374 #ifdef FEAT_VERTSPLIT
2375     p_term("t_CV", T_CSV)
2376 #endif
2377     p_term("t_ut", T_UT)
2378     p_term("t_da", T_DA)
2379     p_term("t_db", T_DB)
2380     p_term("t_DL", T_CDL)
2381     p_term("t_dl", T_DL)
2382     p_term("t_fs", T_FS)
2383     p_term("t_IE", T_CIE)
2384     p_term("t_IS", T_CIS)
2385     p_term("t_ke", T_KE)
2386     p_term("t_ks", T_KS)
2387     p_term("t_le", T_LE)
2388     p_term("t_mb", T_MB)
2389     p_term("t_md", T_MD)
2390     p_term("t_me", T_ME)
2391     p_term("t_mr", T_MR)
2392     p_term("t_ms", T_MS)
2393     p_term("t_nd", T_ND)
2394     p_term("t_op", T_OP)
2395     p_term("t_RI", T_CRI)
2396     p_term("t_RV", T_CRV)
2397     p_term("t_Sb", T_CSB)
2398     p_term("t_Sf", T_CSF)
2399     p_term("t_se", T_SE)
2400     p_term("t_so", T_SO)
2401     p_term("t_sr", T_SR)
2402     p_term("t_ts", T_TS)
2403     p_term("t_te", T_TE)
2404     p_term("t_ti", T_TI)
2405     p_term("t_ue", T_UE)
2406     p_term("t_us", T_US)
2407     p_term("t_vb", T_VB)
2408     p_term("t_ve", T_VE)
2409     p_term("t_vi", T_VI)
2410     p_term("t_vs", T_VS)
2411     p_term("t_WP", T_CWP)
2412     p_term("t_WS", T_CWS)
2413     p_term("t_xs", T_XS)
2414     p_term("t_ZH", T_CZH)
2415     p_term("t_ZR", T_CZR)
2416 
2417 /* terminal key codes are not in here */
2418 
2419     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL}}	/* end marker */
2420 };
2421 
2422 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2423 
2424 #ifdef FEAT_MBYTE
2425 static char *(p_ambw_values[]) = {"single", "double", NULL};
2426 #endif
2427 static char *(p_bg_values[]) = {"light", "dark", NULL};
2428 static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2429 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
2430 #ifdef FEAT_WAK
2431 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2432 #endif
2433 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
2434 #ifdef FEAT_VISUAL
2435 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2436 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
2437 #endif
2438 #ifdef FEAT_VISUAL
2439 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
2440 #endif
2441 #ifdef FEAT_BROWSE
2442 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2443 #endif
2444 #ifdef FEAT_SCROLLBIND
2445 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
2446 #endif
2447 static char *(p_swb_values[]) = {"useopen", "split", NULL};
2448 static char *(p_debug_values[]) = {"msg", NULL};
2449 #ifdef FEAT_VERTSPLIT
2450 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
2451 #endif
2452 #if defined(FEAT_QUICKFIX)
2453 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
2454 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
2455 #endif
2456 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
2457 #ifdef FEAT_FOLDING
2458 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
2459 #ifdef FEAT_DIFF
2460 				"diff",
2461 #endif
2462 				NULL};
2463 static char *(p_fcl_values[]) = {"all", NULL};
2464 #endif
2465 
2466 static void set_option_default __ARGS((int, int opt_flags, int compatible));
2467 static void set_options_default __ARGS((int opt_flags));
2468 static char_u *illegal_char __ARGS((char_u *, int));
2469 static int string_to_key __ARGS((char_u *arg));
2470 #ifdef FEAT_CMDWIN
2471 static char_u *check_cedit __ARGS((void));
2472 #endif
2473 #ifdef FEAT_TITLE
2474 static void did_set_title __ARGS((int icon));
2475 #endif
2476 static char_u *option_expand __ARGS((int opt_idx, char_u *val));
2477 static void didset_options __ARGS((void));
2478 static void check_string_option __ARGS((char_u **pp));
2479 static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2480 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2481 static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
2482 static char_u *set_chars_option __ARGS((char_u **varp));
2483 #ifdef FEAT_CLIPBOARD
2484 static char_u *check_clipboard_option __ARGS((void));
2485 #endif
2486 static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
2487 static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, int opt_flags));
2488 static void check_redraw __ARGS((long_u flags));
2489 static int findoption __ARGS((char_u *));
2490 static int find_key_option __ARGS((char_u *));
2491 static void showoptions __ARGS((int all, int opt_flags));
2492 static int optval_default __ARGS((struct vimoption *, char_u *varp));
2493 static void showoneopt __ARGS((struct vimoption *, int opt_flags));
2494 static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
2495 static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
2496 static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
2497 static int  istermoption __ARGS((struct vimoption *));
2498 static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
2499 static char_u *get_varp __ARGS((struct vimoption *));
2500 static void option_value2string __ARGS((struct vimoption *, int opt_flags));
2501 static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
2502 #ifdef FEAT_LANGMAP
2503 static void langmap_init __ARGS((void));
2504 static void langmap_set __ARGS((void));
2505 #endif
2506 static void paste_option_changed __ARGS((void));
2507 static void compatible_set __ARGS((void));
2508 #ifdef FEAT_LINEBREAK
2509 static void fill_breakat_flags __ARGS((void));
2510 #endif
2511 static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
2512 static int check_opt_strings __ARGS((char_u *val, char **values, int));
2513 static int check_opt_wim __ARGS((void));
2514 
2515 /*
2516  * Initialize the options, first part.
2517  *
2518  * Called only once from main(), just after creating the first buffer.
2519  */
2520     void
2521 set_init_1()
2522 {
2523     char_u	*p;
2524     int		opt_idx;
2525     long	n;
2526 
2527 #ifdef FEAT_LANGMAP
2528     langmap_init();
2529 #endif
2530 
2531     /* Be Vi compatible by default */
2532     p_cp = TRUE;
2533 
2534     /*
2535      * Find default value for 'shell' option.
2536      */
2537     if ((p = mch_getenv((char_u *)"SHELL")) != NULL
2538 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
2539 # ifdef __EMX__
2540 	    || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL
2541 # endif
2542 	    || (p = mch_getenv((char_u *)"COMSPEC")) != NULL
2543 # ifdef WIN3264
2544 	    || (p = default_shell()) != NULL
2545 # endif
2546 #endif
2547        )
2548 	set_string_default("sh", p);
2549 
2550 #ifdef FEAT_WILDIGN
2551     /*
2552      * Set the default for 'backupskip' to include environment variables for
2553      * temp files.
2554      */
2555     {
2556 # ifdef UNIX
2557 	static char	*(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
2558 # else
2559 	static char	*(names[3]) = {"TMPDIR", "TEMP", "TMP"};
2560 # endif
2561 	int	len;
2562 	garray_T ga;
2563 
2564 	ga_init2(&ga, 1, 100);
2565 	for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
2566 	{
2567 # ifdef UNIX
2568 	    if (*names[n] == NUL)
2569 		p = (char_u *)"/tmp";
2570 	    else
2571 # endif
2572 		p = mch_getenv((char_u *)names[n]);
2573 	    if (p != NULL && *p != NUL)
2574 	    {
2575 		/* First time count the NUL, otherwise count the ','. */
2576 		len = STRLEN(p) + 3;
2577 		if (ga_grow(&ga, len) == OK)
2578 		{
2579 		    if (ga.ga_len > 0)
2580 			STRCAT(ga.ga_data, ",");
2581 		    STRCAT(ga.ga_data, p);
2582 		    add_pathsep(ga.ga_data);
2583 		    STRCAT(ga.ga_data, "*");
2584 		    ga.ga_room -= len;
2585 		    ga.ga_len += len;
2586 		}
2587 	    }
2588 	}
2589 	if (ga.ga_data != NULL)
2590 	{
2591 	    set_string_default("bsk", ga.ga_data);
2592 	    vim_free(ga.ga_data);
2593 	}
2594     }
2595 #endif
2596 
2597     /*
2598      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
2599      */
2600     opt_idx = findoption((char_u *)"maxmemtot");
2601 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2602     if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
2603 #endif
2604     {
2605 #ifdef HAVE_AVAIL_MEM
2606 	/* Use amount of memory available at this moment. */
2607 	n = (mch_avail_mem(FALSE) >> 11);
2608 #else
2609 # ifdef HAVE_TOTAL_MEM
2610 	/* Use amount of memory available to Vim. */
2611 	n = (mch_total_mem(FALSE) >> 11);
2612 # else
2613 	n = (0x7fffffff >> 11);
2614 # endif
2615 #endif
2616 	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2617 	opt_idx = findoption((char_u *)"maxmem");
2618 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
2619 	if ((long)options[opt_idx].def_val[VI_DEFAULT] > n
2620 			  || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
2621 #endif
2622 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
2623     }
2624 
2625 #ifdef FEAT_GUI_W32
2626     /* force 'shortname' for Win32s */
2627     if (gui_is_win32s())
2628 	options[findoption((char_u *)"shortname")].def_val[VI_DEFAULT] =
2629 							       (char_u *)TRUE;
2630 #endif
2631 
2632 #ifdef FEAT_SEARCHPATH
2633     {
2634 	char_u	*cdpath;
2635 	char_u	*buf;
2636 	int	i;
2637 	int	j;
2638 
2639 	/* Initialize the 'cdpath' option's default value. */
2640 	cdpath = mch_getenv((char_u *)"CDPATH");
2641 	if (cdpath != NULL)
2642 	{
2643 	    buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
2644 	    if (buf != NULL)
2645 	    {
2646 		buf[0] = ',';	    /* start with ",", current dir first */
2647 		j = 1;
2648 		for (i = 0; cdpath[i] != NUL; ++i)
2649 		{
2650 		    if (vim_ispathlistsep(cdpath[i]))
2651 			buf[j++] = ',';
2652 		    else
2653 		    {
2654 			if (cdpath[i] == ' ' || cdpath[i] == ',')
2655 			    buf[j++] = '\\';
2656 			buf[j++] = cdpath[i];
2657 		    }
2658 		}
2659 		buf[j] = NUL;
2660 		opt_idx = findoption((char_u *)"cdpath");
2661 		options[opt_idx].def_val[VI_DEFAULT] = buf;
2662 		options[opt_idx].flags |= P_DEF_ALLOCED;
2663 	    }
2664 	}
2665     }
2666 #endif
2667 
2668 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
2669     /* Set print encoding on platforms that don't default to latin1 */
2670     set_string_default("penc",
2671 # if defined(MSWIN) || defined(OS2)
2672 		       (char_u *)"cp1252"
2673 # else
2674 #  ifdef VMS
2675 		       (char_u *)"dec-mcs"
2676 #  else
2677 #   ifdef EBCDIC
2678 		       (char_u *)"ebcdic-uk"
2679 #   else
2680 #    ifdef MAC
2681 		       (char_u *)"mac-roman"
2682 #    else /* HPUX */
2683 		       (char_u *)"hp-roman8"
2684 #    endif
2685 #   endif
2686 #  endif
2687 # endif
2688 		       );
2689 #endif
2690 
2691 #ifdef FEAT_POSTSCRIPT
2692     /* 'printexpr' must be allocated to be able to evaluate it. */
2693     set_string_default("pexpr",
2694 # if defined(MSWIN) || defined(MSDOS) || defined(OS2)
2695 	    (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
2696 # else
2697 #  ifdef VMS
2698 	    (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
2699 
2700 #  else
2701 	    (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
2702 #  endif
2703 # endif
2704 	    );
2705 #endif
2706 
2707     /*
2708      * Set all the options (except the terminal options) to their default
2709      * value.  Also set the global value for local options.
2710      */
2711     set_options_default(0);
2712 
2713 #ifdef FEAT_GUI
2714     if (found_reverse_arg)
2715 	set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
2716 #endif
2717 
2718     curbuf->b_p_initialized = TRUE;
2719     curbuf->b_p_ar = -1;	/* no local 'autoread' value */
2720     check_buf_options(curbuf);
2721     check_win_options(curwin);
2722     check_options();
2723 
2724     /* Must be before option_expand(), because that one needs vim_isIDc() */
2725     didset_options();
2726 
2727 #ifdef FEAT_LINEBREAK
2728     /*
2729      * initialize the table for 'breakat'.
2730      */
2731     fill_breakat_flags();
2732 #endif
2733 
2734     /*
2735      * Expand environment variables and things like "~" for the defaults.
2736      * If option_expand() returns non-NULL the variable is expanded.  This can
2737      * only happen for non-indirect options.
2738      * Also set the default to the expanded value, so ":set" does not list
2739      * them.
2740      * Don't set the P_ALLOCED flag, because we don't want to free the
2741      * default.
2742      */
2743     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
2744     {
2745 	if ((options[opt_idx].flags & P_GETTEXT)
2746 					      && options[opt_idx].var != NULL)
2747 	    p = (char_u *)_(*(char **)options[opt_idx].var);
2748 	else
2749 	    p = option_expand(opt_idx, NULL);
2750 	if (p != NULL && (p = vim_strsave(p)) != NULL)
2751 	{
2752 	    *(char_u **)options[opt_idx].var = p;
2753 	    /* VIMEXP
2754 	     * Defaults for all expanded options are currently the same for Vi
2755 	     * and Vim.  When this changes, add some code here!  Also need to
2756 	     * split P_DEF_ALLOCED in two.
2757 	     */
2758 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
2759 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2760 	    options[opt_idx].def_val[VI_DEFAULT] = p;
2761 	    options[opt_idx].flags |= P_DEF_ALLOCED;
2762 	}
2763     }
2764 
2765     /* Initialize the highlight_attr[] table. */
2766     highlight_changed();
2767 
2768     save_file_ff(curbuf);	/* Buffer is unchanged */
2769 
2770     /* Parse default for 'wildmode'  */
2771     check_opt_wim();
2772 
2773 #if defined(FEAT_ARABIC)
2774     /* Detect use of mlterm.
2775      * Mlterm is a terminal emulator akin to xterm that has some special
2776      * abilities (bidi namely).
2777      * NOTE: mlterm's author is being asked to 'set' a variable
2778      *       instead of an environment variable due to inheritance.
2779      */
2780     if (mch_getenv((char_u *)"MLTERM") != NULL)
2781 	set_option_value((char_u *)"tbidi", 1L, NULL, 0);
2782 #endif
2783 
2784 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
2785     /* Parse default for 'fillchars'. */
2786     (void)set_chars_option(&p_fcs);
2787 #endif
2788 
2789 #ifdef FEAT_CLIPBOARD
2790     /* Parse default for 'clipboard' */
2791     (void)check_clipboard_option();
2792 #endif
2793 
2794 #ifdef FEAT_MBYTE
2795 # if defined(WIN3264) && defined(FEAT_GETTEXT)
2796     /*
2797      * If $LANG isn't set, try to get a good value for it.  This makes the
2798      * right language be used automatically.  Don't do this for English.
2799      */
2800     if (mch_getenv((char_u *)"LANG") == NULL)
2801     {
2802 	char	buf[20];
2803 
2804 	/* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
2805 	 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
2806 	 * only the first two. */
2807 	n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
2808 							     (LPTSTR)buf, 20);
2809 	if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
2810 	{
2811 	    /* There are a few exceptions (probably more) */
2812 	    if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
2813 		STRCPY(buf, "zh_TW");
2814 	    else if (STRNICMP(buf, "chs", 3) == 0
2815 					      || STRNICMP(buf, "zhc", 3) == 0)
2816 		STRCPY(buf, "zh_CN");
2817 	    else if (STRNICMP(buf, "jp", 2) == 0)
2818 		STRCPY(buf, "ja");
2819 	    else
2820 		buf[2] = NUL;		/* truncate to two-letter code */
2821 	    vim_setenv("LANG", buf);
2822 	}
2823     }
2824 # endif
2825 
2826     /* enc_locale() will try to find the encoding of the current locale. */
2827     p = enc_locale();
2828     if (p != NULL)
2829     {
2830 	char_u *save_enc;
2831 
2832 	/* Try setting 'encoding' and check if the value is valid.
2833 	 * If not, go back to the default "latin1". */
2834 	save_enc = p_enc;
2835 	p_enc = p;
2836 	if (mb_init() == NULL)
2837 	{
2838 	    opt_idx = findoption((char_u *)"encoding");
2839 	    options[opt_idx].def_val[VI_DEFAULT] = p_enc;
2840 	    options[opt_idx].flags |= P_DEF_ALLOCED;
2841 
2842 # if defined(WIN3264) && !defined(FEAT_GUI)
2843 	    /* Win32 console: When GetACP() returns a different value from
2844 	     * GetConsoleCP() set 'termencoding'. */
2845 	    if (GetACP() != GetConsoleCP())
2846 	    {
2847 		char	buf[50];
2848 
2849 		sprintf(buf, "cp%ld", (long)GetConsoleCP());
2850 		p_tenc = vim_strsave((char_u *)buf);
2851 		if (p_tenc != NULL)
2852 		{
2853 		    opt_idx = findoption((char_u *)"termencoding");
2854 		    options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
2855 		    options[opt_idx].flags |= P_DEF_ALLOCED;
2856 		    convert_setup(&input_conv, p_tenc, p_enc);
2857 		    convert_setup(&output_conv, p_enc, p_tenc);
2858 		}
2859 		else
2860 		    p_tenc = empty_option;
2861 	    }
2862 # endif
2863 	}
2864 	else
2865 	{
2866 	    vim_free(p_enc);
2867 	    p_enc = save_enc;
2868 	}
2869     }
2870 #endif
2871 
2872 #ifdef FEAT_MULTI_LANG
2873     /* Set the default for 'helplang'. */
2874     set_helplang_default(get_mess_lang());
2875 #endif
2876 }
2877 
2878 /*
2879  * Set an option to its default value.
2880  * This does not take care of side effects!
2881  */
2882     static void
2883 set_option_default(opt_idx, opt_flags, compatible)
2884     int		opt_idx;
2885     int		opt_flags;	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2886     int		compatible;	/* use Vi default value */
2887 {
2888     char_u	*varp;		/* pointer to variable for current option */
2889     int		dvi;		/* index in def_val[] */
2890     long_u	flags;
2891     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
2892 
2893     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
2894     flags = options[opt_idx].flags;
2895     if (varp != NULL)	    /* nothing to do for hidden option */
2896     {
2897 	dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
2898 	if (flags & P_STRING)
2899 	{
2900 	    /* Use set_string_option_direct() for local options to handle
2901 	     * freeing and allocating the value. */
2902 	    if (options[opt_idx].indir != PV_NONE)
2903 		set_string_option_direct(NULL, opt_idx,
2904 				    options[opt_idx].def_val[dvi], opt_flags);
2905 	    else
2906 	    {
2907 		if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
2908 		    free_string_option(*(char_u **)(varp));
2909 		*(char_u **)varp = options[opt_idx].def_val[dvi];
2910 		options[opt_idx].flags &= ~P_ALLOCED;
2911 	    }
2912 	}
2913 	else if (flags & P_NUM)
2914 	{
2915 	    if (varp == (char_u *)PV_SCROLL)
2916 		win_comp_scroll(curwin);
2917 	    else
2918 	    {
2919 		*(long *)varp = (long)options[opt_idx].def_val[dvi];
2920 		/* May also set global value for local option. */
2921 		if (both)
2922 		    *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2923 								*(long *)varp;
2924 	    }
2925 	}
2926 	else	/* P_BOOL */
2927 	{
2928 	    /* the cast to long is required for Manx C */
2929 	    *(int *)varp = (int)(long)options[opt_idx].def_val[dvi];
2930 	    /* May also set global value for local option. */
2931 	    if (both)
2932 		*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
2933 								*(int *)varp;
2934 	}
2935     }
2936 
2937 #ifdef FEAT_EVAL
2938     /* Remember where the option was set. */
2939     options[opt_idx].scriptID = current_SID;
2940 #endif
2941 }
2942 
2943 /*
2944  * Set all options (except terminal options) to their default value.
2945  */
2946     static void
2947 set_options_default(opt_flags)
2948     int		opt_flags;	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
2949 {
2950     int		i;
2951 #ifdef FEAT_WINDOWS
2952     win_T	*wp;
2953 #endif
2954 
2955     for (i = 0; !istermoption(&options[i]); i++)
2956 	if (!(options[i].flags & P_NODEFAULT))
2957 	    set_option_default(i, opt_flags, p_cp);
2958 
2959 #ifdef FEAT_WINDOWS
2960     /* The 'scroll' option must be computed for all windows. */
2961     for (wp = firstwin; wp != NULL; wp = wp->w_next)
2962 	win_comp_scroll(wp);
2963 #else
2964 	win_comp_scroll(curwin);
2965 #endif
2966 }
2967 
2968 /*
2969  * Set the Vi-default value of a string option.
2970  * Used for 'sh', 'backupskip' and 'term'.
2971  */
2972     void
2973 set_string_default(name, val)
2974     char	*name;
2975     char_u	*val;
2976 {
2977     char_u	*p;
2978     int		opt_idx;
2979 
2980     p = vim_strsave(val);
2981     if (p != NULL)		/* we don't want a NULL */
2982     {
2983 	opt_idx = findoption((char_u *)name);
2984 	if (options[opt_idx].flags & P_DEF_ALLOCED)
2985 	    vim_free(options[opt_idx].def_val[VI_DEFAULT]);
2986 	options[opt_idx].def_val[VI_DEFAULT] = p;
2987 	options[opt_idx].flags |= P_DEF_ALLOCED;
2988     }
2989 }
2990 
2991 /*
2992  * Set the Vi-default value of a number option.
2993  * Used for 'lines' and 'columns'.
2994  */
2995     void
2996 set_number_default(name, val)
2997     char	*name;
2998     long	val;
2999 {
3000     options[findoption((char_u *)name)].def_val[VI_DEFAULT] = (char_u *)val;
3001 }
3002 
3003 /*
3004  * Initialize the options, part two: After getting Rows and Columns and
3005  * setting 'term'.
3006  */
3007     void
3008 set_init_2()
3009 {
3010     /*
3011      * 'scroll' defaults to half the window height. Note that this default is
3012      * wrong when the window height changes.
3013      */
3014     options[findoption((char_u *)"scroll")].def_val[VI_DEFAULT]
3015 					      = (char_u *)((long_u)Rows >> 1);
3016     comp_col();
3017 
3018 #if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
3019     {
3020 	int	idx4;
3021 
3022 	/*
3023 	 * If 'background' wasn't set by the user, try guessing the value,
3024 	 * depending on the terminal name.  Only need to check for terminals
3025 	 * with a dark background, that can handle color.  Only "linux"
3026 	 * console at the moment.
3027 	 */
3028 	idx4 = findoption((char_u *)"bg");
3029 	if (!(options[idx4].flags & P_WAS_SET) && STRCMP(T_NAME, "linux") == 0)
3030 	{
3031 	    set_string_option_direct(NULL, idx4, (char_u *)"dark", OPT_FREE);
3032 	    /* don't mark it as set, when starting the GUI it may be changed
3033 	     * again */
3034 	    options[idx4].flags &= ~P_WAS_SET;
3035 	}
3036     }
3037 #endif
3038 }
3039 
3040 /*
3041  * Initialize the options, part three: After reading the .vimrc
3042  */
3043     void
3044 set_init_3()
3045 {
3046 #if defined(UNIX) || defined(OS2) || defined(WIN3264)
3047 /*
3048  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3049  * This is done after other initializations, where 'shell' might have been
3050  * set, but only if they have not been set before.
3051  */
3052     char_u  *p;
3053     int	    idx_srr;
3054     int	    do_srr;
3055 #ifdef FEAT_QUICKFIX
3056     int	    idx_sp;
3057     int	    do_sp;
3058 #endif
3059 
3060     idx_srr = findoption((char_u *)"srr");
3061     do_srr = !(options[idx_srr].flags & P_WAS_SET);
3062 #ifdef FEAT_QUICKFIX
3063     idx_sp = findoption((char_u *)"sp");
3064     do_sp = !(options[idx_sp].flags & P_WAS_SET);
3065 #endif
3066 
3067     /*
3068      * Isolate the name of the shell:
3069      * - Skip beyond any path.  E.g., "/usr/bin/csh -f" -> "csh -f".
3070      * - Remove any argument.  E.g., "csh -f" -> "csh".
3071      */
3072     p = gettail(p_sh);
3073     p = vim_strnsave(p, (int)(skiptowhite(p) - p));
3074     if (p != NULL)
3075     {
3076 	/*
3077 	 * Default for p_sp is "| tee", for p_srr is ">".
3078 	 * For known shells it is changed here to include stderr.
3079 	 */
3080 	if (	   fnamecmp(p, "csh") == 0
3081 		|| fnamecmp(p, "tcsh") == 0
3082 # if defined(OS2) || defined(WIN3264)	/* also check with .exe extension */
3083 		|| fnamecmp(p, "csh.exe") == 0
3084 		|| fnamecmp(p, "tcsh.exe") == 0
3085 # endif
3086 	   )
3087 	{
3088 #if defined(FEAT_QUICKFIX)
3089 	    if (do_sp)
3090 	    {
3091 # ifdef WIN3264
3092 		p_sp = (char_u *)">&";
3093 # else
3094 		p_sp = (char_u *)"|& tee";
3095 # endif
3096 		options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3097 	    }
3098 #endif
3099 	    if (do_srr)
3100 	    {
3101 		p_srr = (char_u *)">&";
3102 		options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3103 	    }
3104 	}
3105 	else
3106 # ifndef OS2	/* Always use bourne shell style redirection if we reach this */
3107 	    if (       fnamecmp(p, "sh") == 0
3108 		    || fnamecmp(p, "ksh") == 0
3109 		    || fnamecmp(p, "zsh") == 0
3110 		    || fnamecmp(p, "bash") == 0
3111 #  ifdef WIN3264
3112 		    || fnamecmp(p, "cmd") == 0
3113 		    || fnamecmp(p, "sh.exe") == 0
3114 		    || fnamecmp(p, "ksh.exe") == 0
3115 		    || fnamecmp(p, "zsh.exe") == 0
3116 		    || fnamecmp(p, "bash.exe") == 0
3117 		    || fnamecmp(p, "cmd.exe") == 0
3118 #  endif
3119 		    )
3120 # endif
3121 	    {
3122 #if defined(FEAT_QUICKFIX)
3123 		if (do_sp)
3124 		{
3125 # ifdef WIN3264
3126 		    p_sp = (char_u *)">%s 2>&1";
3127 # else
3128 		    p_sp = (char_u *)"2>&1| tee";
3129 # endif
3130 		    options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3131 		}
3132 #endif
3133 		if (do_srr)
3134 		{
3135 		    p_srr = (char_u *)">%s 2>&1";
3136 		    options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3137 		}
3138 	    }
3139 	vim_free(p);
3140     }
3141 #endif
3142 
3143 #if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3144     /*
3145      * Set 'shellcmdflag and 'shellquote' depending on the 'shell' option.
3146      * This is done after other initializations, where 'shell' might have been
3147      * set, but only if they have not been set before.  Default for p_shcf is
3148      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
3149      * "-c" and "\"", but not for DJGPP, because it starts the shell without
3150      * command.com.  And for Win32 we need to set p_sxq instead.
3151      */
3152     if (strstr((char *)gettail(p_sh), "sh") != NULL)
3153     {
3154 	int	idx3;
3155 
3156 	idx3 = findoption((char_u *)"shcf");
3157 	if (!(options[idx3].flags & P_WAS_SET))
3158 	{
3159 	    p_shcf = (char_u *)"-c";
3160 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
3161 	}
3162 
3163 # ifndef DJGPP
3164 #  ifdef WIN3264
3165 	/* Somehow Win32 requires the quotes around the redirection too */
3166 	idx3 = findoption((char_u *)"sxq");
3167 	if (!(options[idx3].flags & P_WAS_SET))
3168 	{
3169 	    p_sxq = (char_u *)"\"";
3170 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
3171 	}
3172 #  else
3173 	idx3 = findoption((char_u *)"shq");
3174 	if (!(options[idx3].flags & P_WAS_SET))
3175 	{
3176 	    p_shq = (char_u *)"\"";
3177 	    options[idx3].def_val[VI_DEFAULT] = p_shq;
3178 	}
3179 #  endif
3180 # endif
3181     }
3182 #endif
3183 
3184 #ifdef FEAT_TITLE
3185     set_title_defaults();
3186 #endif
3187 }
3188 
3189 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
3190 /*
3191  * When 'helplang' is still at its default value, set it to "lang".
3192  * Only the first two characters of "lang" are used.
3193  */
3194     void
3195 set_helplang_default(lang)
3196     char_u	*lang;
3197 {
3198     int		idx;
3199 
3200     if (lang == NULL || STRLEN(lang) < 2)	/* safety check */
3201 	return;
3202     idx = findoption((char_u *)"hlg");
3203     if (!(options[idx].flags & P_WAS_SET))
3204     {
3205 	if (options[idx].flags & P_ALLOCED)
3206 	    free_string_option(p_hlg);
3207 	p_hlg = vim_strsave(lang);
3208 	if (p_hlg == NULL)
3209 	    p_hlg = empty_option;
3210 	else
3211 	    p_hlg[2] = NUL;
3212 	options[idx].flags |= P_ALLOCED;
3213     }
3214 }
3215 #endif
3216 
3217 #ifdef FEAT_GUI
3218 static char_u *gui_bg_default __ARGS((void));
3219 
3220     static char_u *
3221 gui_bg_default()
3222 {
3223     if (gui_get_lightness(gui.back_pixel) < 127)
3224 	return (char_u *)"dark";
3225     return (char_u *)"light";
3226 }
3227 
3228 /*
3229  * Option initializations that can only be done after opening the GUI window.
3230  */
3231     void
3232 init_gui_options()
3233 {
3234     /* Set the 'background' option according to the lightness of the
3235      * background color, unless the user has set it already. */
3236     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
3237     {
3238 	set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
3239 	highlight_changed();
3240     }
3241 }
3242 #endif
3243 
3244 #ifdef FEAT_TITLE
3245 /*
3246  * 'title' and 'icon' only default to true if they have not been set or reset
3247  * in .vimrc and we can read the old value.
3248  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
3249  * they can be reset.  This reduces startup time when using X on a remote
3250  * machine.
3251  */
3252     void
3253 set_title_defaults()
3254 {
3255     int	    idx1;
3256     long    val;
3257 
3258     /*
3259      * If GUI is (going to be) used, we can always set the window title and
3260      * icon name.  Saves a bit of time, because the X11 display server does
3261      * not need to be contacted.
3262      */
3263     idx1 = findoption((char_u *)"title");
3264     if (!(options[idx1].flags & P_WAS_SET))
3265     {
3266 #ifdef FEAT_GUI
3267 	if (gui.starting || gui.in_use)
3268 	    val = TRUE;
3269 	else
3270 #endif
3271 	    val = mch_can_restore_title();
3272 	options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3273 	p_title = val;
3274     }
3275     idx1 = findoption((char_u *)"icon");
3276     if (!(options[idx1].flags & P_WAS_SET))
3277     {
3278 #ifdef FEAT_GUI
3279 	if (gui.starting || gui.in_use)
3280 	    val = TRUE;
3281 	else
3282 #endif
3283 	    val = mch_can_restore_icon();
3284 	options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
3285 	p_icon = val;
3286     }
3287 }
3288 #endif
3289 
3290 /*
3291  * Parse 'arg' for option settings.
3292  *
3293  * 'arg' may be IObuff, but only when no errors can be present and option
3294  * does not need to be expanded with option_expand().
3295  * "opt_flags":
3296  * 0 for ":set"
3297  * OPT_GLOBAL for ":setglobal"
3298  * OPT_LOCAL for ":setlocal" and a modeline
3299  * OPT_MODELINE for a modeline
3300  *
3301  * returns FAIL if an error is detected, OK otherwise
3302  */
3303     int
3304 do_set(arg, opt_flags)
3305     char_u	*arg;		/* option string (may be written to!) */
3306     int		opt_flags;
3307 {
3308     int		opt_idx;
3309     char_u	*errmsg;
3310     char_u	errbuf[80];
3311     char_u	*startarg;
3312     int		prefix;	/* 1: nothing, 0: "no", 2: "inv" in front of name */
3313     int		nextchar;	    /* next non-white char after option name */
3314     int		afterchar;	    /* character just after option name */
3315     int		len;
3316     int		i;
3317     long	value;
3318     int		key;
3319     long_u	flags;		    /* flags for current option */
3320     char_u	*varp = NULL;	    /* pointer to variable for current option */
3321     int		did_show = FALSE;   /* already showed one value */
3322     int		adding;		    /* "opt+=arg" */
3323     int		prepending;	    /* "opt^=arg" */
3324     int		removing;	    /* "opt-=arg" */
3325     int		cp_val = 0;
3326     char_u	key_name[2];
3327 
3328     if (*arg == NUL)
3329     {
3330 	showoptions(0, opt_flags);
3331 	return OK;
3332     }
3333 
3334     while (*arg != NUL)		/* loop to process all options */
3335     {
3336 	errmsg = NULL;
3337 	startarg = arg;		/* remember for error message */
3338 
3339 	if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]))
3340 	{
3341 	    /*
3342 	     * ":set all"  show all options.
3343 	     * ":set all&" set all options to their default value.
3344 	     */
3345 	    arg += 3;
3346 	    if (*arg == '&')
3347 	    {
3348 		++arg;
3349 		/* Only for :set command set global value of local options. */
3350 		set_options_default(OPT_FREE | opt_flags);
3351 	    }
3352 	    else
3353 		showoptions(1, opt_flags);
3354 	}
3355 	else if (STRNCMP(arg, "termcap", 7) == 0)
3356 	{
3357 	    showoptions(2, opt_flags);
3358 	    show_termcodes();
3359 	    arg += 7;
3360 	}
3361 	else
3362 	{
3363 	    prefix = 1;
3364 	    if (STRNCMP(arg, "no", 2) == 0)
3365 	    {
3366 		prefix = 0;
3367 		arg += 2;
3368 	    }
3369 	    else if (STRNCMP(arg, "inv", 3) == 0)
3370 	    {
3371 		prefix = 2;
3372 		arg += 3;
3373 	    }
3374 
3375 	    /* find end of name */
3376 	    key = 0;
3377 	    if (*arg == '<')
3378 	    {
3379 		nextchar = 0;
3380 		opt_idx = -1;
3381 		/* look out for <t_>;> */
3382 		if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
3383 		    len = 5;
3384 		else
3385 		{
3386 		    len = 1;
3387 		    while (arg[len] != NUL && arg[len] != '>')
3388 			++len;
3389 		}
3390 		if (arg[len] != '>')
3391 		{
3392 		    errmsg = e_invarg;
3393 		    goto skip;
3394 		}
3395 		arg[len] = NUL;			    /* put NUL after name */
3396 		if (arg[1] == 't' && arg[2] == '_') /* could be term code */
3397 		    opt_idx = findoption(arg + 1);
3398 		arg[len++] = '>';		    /* restore '>' */
3399 		if (opt_idx == -1)
3400 		    key = find_key_option(arg + 1);
3401 	    }
3402 	    else
3403 	    {
3404 		len = 0;
3405 		/*
3406 		 * The two characters after "t_" may not be alphanumeric.
3407 		 */
3408 		if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
3409 		    len = 4;
3410 		else
3411 		    while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
3412 			++len;
3413 		nextchar = arg[len];
3414 		arg[len] = NUL;			    /* put NUL after name */
3415 		opt_idx = findoption(arg);
3416 		arg[len] = nextchar;		    /* restore nextchar */
3417 		if (opt_idx == -1)
3418 		    key = find_key_option(arg);
3419 	    }
3420 
3421 	    /* remember character after option name */
3422 	    afterchar = arg[len];
3423 
3424 	    /* skip white space, allow ":set ai  ?" */
3425 	    while (vim_iswhite(arg[len]))
3426 		++len;
3427 
3428 	    adding = FALSE;
3429 	    prepending = FALSE;
3430 	    removing = FALSE;
3431 	    if (arg[len] != NUL && arg[len + 1] == '=')
3432 	    {
3433 		if (arg[len] == '+')
3434 		{
3435 		    adding = TRUE;		/* "+=" */
3436 		    ++len;
3437 		}
3438 		else if (arg[len] == '^')
3439 		{
3440 		    prepending = TRUE;		/* "^=" */
3441 		    ++len;
3442 		}
3443 		else if (arg[len] == '-')
3444 		{
3445 		    removing = TRUE;		/* "-=" */
3446 		    ++len;
3447 		}
3448 	    }
3449 	    nextchar = arg[len];
3450 
3451 	    if (opt_idx == -1 && key == 0)	/* found a mismatch: skip */
3452 	    {
3453 		errmsg = (char_u *)N_("E518: Unknown option");
3454 		goto skip;
3455 	    }
3456 
3457 	    if (opt_idx >= 0)
3458 	    {
3459 		if (options[opt_idx].var == NULL)   /* hidden option: skip */
3460 		{
3461 		    /* Only give an error message when requesting the value of
3462 		     * a hidden option, ignore setting it. */
3463 		    if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
3464 			    && (!(options[opt_idx].flags & P_BOOL)
3465 				|| nextchar == '?'))
3466 			errmsg = (char_u *)N_("E519: Option not supported");
3467 		    goto skip;
3468 		}
3469 
3470 		flags = options[opt_idx].flags;
3471 		varp = get_varp_scope(&(options[opt_idx]), opt_flags);
3472 	    }
3473 	    else
3474 	    {
3475 		flags = P_STRING;
3476 		if (key < 0)
3477 		{
3478 		    key_name[0] = KEY2TERMCAP0(key);
3479 		    key_name[1] = KEY2TERMCAP1(key);
3480 		}
3481 		else
3482 		{
3483 		    key_name[0] = KS_KEY;
3484 		    key_name[1] = (key & 0xff);
3485 		}
3486 	    }
3487 
3488 	    /* Disallow changing some options from modelines */
3489 	    if ((opt_flags & OPT_MODELINE) && (flags & P_SECURE))
3490 	    {
3491 		errmsg = (char_u *)_("E520: Not allowed in a modeline");
3492 		goto skip;
3493 	    }
3494 
3495 #ifdef HAVE_SANDBOX
3496 	    /* Disallow changing some options in the sandbox */
3497 	    if (sandbox > 0 && (flags & P_SECURE))
3498 	    {
3499 		errmsg = (char_u *)_(e_sandbox);
3500 		goto skip;
3501 	    }
3502 #endif
3503 
3504 	    if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
3505 	    {
3506 		arg += len;
3507 		cp_val = p_cp;
3508 		if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
3509 		{
3510 		    if (arg[3] == 'm')	/* "opt&vim": set to Vim default */
3511 		    {
3512 			cp_val = FALSE;
3513 			arg += 3;
3514 		    }
3515 		    else		/* "opt&vi": set to Vi default */
3516 		    {
3517 			cp_val = TRUE;
3518 			arg += 2;
3519 		    }
3520 		}
3521 		if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
3522 			&& arg[1] != NUL && !vim_iswhite(arg[1]))
3523 		{
3524 		    errmsg = e_trailing;
3525 		    goto skip;
3526 		}
3527 	    }
3528 
3529 	    /*
3530 	     * allow '=' and ':' as MSDOS command.com allows only one
3531 	     * '=' character per "set" command line. grrr. (jw)
3532 	     */
3533 	    if (nextchar == '?'
3534 		    || (prefix == 1
3535 			&& vim_strchr((char_u *)"=:&<", nextchar) == NULL
3536 			&& !(flags & P_BOOL)))
3537 	    {
3538 		/*
3539 		 * print value
3540 		 */
3541 		if (did_show)
3542 		    msg_putchar('\n');	    /* cursor below last one */
3543 		else
3544 		{
3545 		    gotocmdline(TRUE);	    /* cursor at status line */
3546 		    did_show = TRUE;	    /* remember that we did a line */
3547 		}
3548 		if (opt_idx >= 0)
3549 		{
3550 		    showoneopt(&options[opt_idx], opt_flags);
3551 #ifdef FEAT_EVAL
3552 		    if (p_verbose > 0)
3553 		    {
3554 			if (options[opt_idx].scriptID != 0)
3555 			{
3556 			    MSG_PUTS(_("\n\tLast set from "));
3557 			    MSG_PUTS(get_scriptname(options[opt_idx].scriptID));
3558 			}
3559 		    }
3560 #endif
3561 		}
3562 		else
3563 		{
3564 		    char_u	    *p;
3565 
3566 		    p = find_termcode(key_name);
3567 		    if (p == NULL)
3568 		    {
3569 			errmsg = (char_u *)N_("E518: Unknown option");
3570 			goto skip;
3571 		    }
3572 		    else
3573 			(void)show_one_termcode(key_name, p, TRUE);
3574 		}
3575 		if (nextchar != '?'
3576 			&& nextchar != NUL && !vim_iswhite(afterchar))
3577 		    errmsg = e_trailing;
3578 	    }
3579 	    else
3580 	    {
3581 		if (flags & P_BOOL)		    /* boolean */
3582 		{
3583 		    if (nextchar == '=' || nextchar == ':')
3584 		    {
3585 			errmsg = e_invarg;
3586 			goto skip;
3587 		    }
3588 
3589 		    /*
3590 		     * ":set opt!": invert
3591 		     * ":set opt&": reset to default value
3592 		     * ":set opt<": reset to global value
3593 		     */
3594 		    if (nextchar == '!')
3595 			value = *(int *)(varp) ^ 1;
3596 		    else if (nextchar == '&')
3597 			value = (int)(long)options[opt_idx].def_val[
3598 						((flags & P_VI_DEF) || cp_val)
3599 						 ?  VI_DEFAULT : VIM_DEFAULT];
3600 		    else if (nextchar == '<')
3601 		    {
3602 			/* For 'autoread' -1 means to use global value. */
3603 			if ((int *)varp == &curbuf->b_p_ar
3604 						    && opt_flags == OPT_LOCAL)
3605 			    value = -1;
3606 			else
3607 			    value = *(int *)get_varp_scope(&(options[opt_idx]),
3608 								  OPT_GLOBAL);
3609 		    }
3610 		    else
3611 		    {
3612 			/*
3613 			 * ":set invopt": invert
3614 			 * ":set opt" or ":set noopt": set or reset
3615 			 */
3616 			if (nextchar != NUL && !vim_iswhite(afterchar))
3617 			{
3618 			    errmsg = e_trailing;
3619 			    goto skip;
3620 			}
3621 			if (prefix == 2)	/* inv */
3622 			    value = *(int *)(varp) ^ 1;
3623 			else
3624 			    value = prefix;
3625 		    }
3626 
3627 		    errmsg = set_bool_option(opt_idx, varp, (int)value,
3628 								   opt_flags);
3629 		}
3630 		else				    /* numeric or string */
3631 		{
3632 		    if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
3633 							       || prefix != 1)
3634 		    {
3635 			errmsg = e_invarg;
3636 			goto skip;
3637 		    }
3638 
3639 		    if (flags & P_NUM)		    /* numeric */
3640 		    {
3641 			/*
3642 			 * Different ways to set a number option:
3643 			 * &	    set to default value
3644 			 * <	    set to global value
3645 			 * <xx>	    accept special key codes for 'wildchar'
3646 			 * c	    accept any non-digit for 'wildchar'
3647 			 * [-]0-9   set number
3648 			 * other    error
3649 			 */
3650 			++arg;
3651 			if (nextchar == '&')
3652 			    value = (long)options[opt_idx].def_val[
3653 						((flags & P_VI_DEF) || cp_val)
3654 						 ?  VI_DEFAULT : VIM_DEFAULT];
3655 			else if (nextchar == '<')
3656 			    value = *(long *)get_varp_scope(&(options[opt_idx]),
3657 								  OPT_GLOBAL);
3658 			else if (((long *)varp == &p_wc
3659 				    || (long *)varp == &p_wcm)
3660 				&& (*arg == '<'
3661 				    || *arg == '^'
3662 				    || ((!arg[1] || vim_iswhite(arg[1]))
3663 					&& !VIM_ISDIGIT(*arg))))
3664 			{
3665 			    value = string_to_key(arg);
3666 			    if (value == 0 && (long *)varp != &p_wcm)
3667 			    {
3668 				errmsg = e_invarg;
3669 				goto skip;
3670 			    }
3671 			}
3672 				/* allow negative numbers (for 'undolevels') */
3673 			else if (*arg == '-' || VIM_ISDIGIT(*arg))
3674 			{
3675 			    i = 0;
3676 			    if (*arg == '-')
3677 				i = 1;
3678 #ifdef HAVE_STRTOL
3679 			    value = strtol((char *)arg, NULL, 0);
3680 			    if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
3681 				i += 2;
3682 #else
3683 			    value = atol((char *)arg);
3684 #endif
3685 			    while (VIM_ISDIGIT(arg[i]))
3686 				++i;
3687 			    if (arg[i] != NUL && !vim_iswhite(arg[i]))
3688 			    {
3689 				errmsg = e_invarg;
3690 				goto skip;
3691 			    }
3692 			}
3693 			else
3694 			{
3695 			    errmsg = (char_u *)N_("E521: Number required after =");
3696 			    goto skip;
3697 			}
3698 
3699 			if (adding)
3700 			    value = *(long *)varp + value;
3701 			if (prepending)
3702 			    value = *(long *)varp * value;
3703 			if (removing)
3704 			    value = *(long *)varp - value;
3705 			errmsg = set_num_option(opt_idx, varp, value,
3706 							   errbuf, opt_flags);
3707 		    }
3708 		    else if (opt_idx >= 0)		    /* string */
3709 		    {
3710 			char_u	    *save_arg = NULL;
3711 			char_u	    *s = NULL;
3712 			char_u	    *oldval;	/* previous value if *varp */
3713 			char_u	    *newval;
3714 			char_u	    *origval;
3715 			unsigned    newlen;
3716 			int	    comma;
3717 			int	    bs;
3718 			int	    new_value_alloced;	/* new string option
3719 							   was allocated */
3720 
3721 			/* When using ":set opt=val" for a global option
3722 			 * with a local value the local value will be
3723 			 * reset, use the global value here. */
3724 			if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
3725 				&& (int)options[opt_idx].indir >= PV_BOTH)
3726 			    varp = options[opt_idx].var;
3727 
3728 			/* The old value is kept until we are sure that the
3729 			 * new value is valid. */
3730 			oldval = *(char_u **)varp;
3731 			if (nextchar == '&')	/* set to default val */
3732 			{
3733 			    newval = options[opt_idx].def_val[
3734 						((flags & P_VI_DEF) || cp_val)
3735 						 ?  VI_DEFAULT : VIM_DEFAULT];
3736 			    if ((char_u **)varp == &p_bg)
3737 			    {
3738 				/* guess the value of 'background' */
3739 #ifdef FEAT_GUI
3740 				if (gui.in_use)
3741 				    newval = gui_bg_default();
3742 				else
3743 #endif
3744 				    if (STRCMP(T_NAME, "linux") == 0)
3745 					newval = (char_u *)"dark";
3746 			    }
3747 
3748 			    /* expand environment variables and ~ (since the
3749 			     * default value was already expanded, only
3750 			     * required when an environment variable was set
3751 			     * later */
3752 			    if (newval == NULL)
3753 				newval = empty_option;
3754 			    else
3755 			    {
3756 				s = option_expand(opt_idx, newval);
3757 				if (s == NULL)
3758 				    s = newval;
3759 				newval = vim_strsave(s);
3760 			    }
3761 			    new_value_alloced = TRUE;
3762 			}
3763 			else if (nextchar == '<')	/* set to global val */
3764 			{
3765 			    newval = vim_strsave(*(char_u **)get_varp_scope(
3766 					     &(options[opt_idx]), OPT_GLOBAL));
3767 			    new_value_alloced = TRUE;
3768 			}
3769 			else
3770 			{
3771 			    ++arg;	/* jump to after the '=' or ':' */
3772 
3773 			    /*
3774 			     * Set 'keywordprg' to ":help" if an empty
3775 			     * value was passed to :set by the user.
3776 			     * Misuse errbuf[] for the resulting string.
3777 			     */
3778 			    if (varp == (char_u *)&p_kp
3779 					      && (*arg == NUL || *arg == ' '))
3780 			    {
3781 				STRCPY(errbuf, ":help");
3782 				save_arg = arg;
3783 				arg = errbuf;
3784 			    }
3785 			    /*
3786 			     * Convert 'whichwrap' number to string, for
3787 			     * backwards compatibility with Vim 3.0.
3788 			     * Misuse errbuf[] for the resulting string.
3789 			     */
3790 			    else if (varp == (char_u *)&p_ww
3791 							 && VIM_ISDIGIT(*arg))
3792 			    {
3793 				*errbuf = NUL;
3794 				i = getdigits(&arg);
3795 				if (i & 1)
3796 				    STRCAT(errbuf, "b,");
3797 				if (i & 2)
3798 				    STRCAT(errbuf, "s,");
3799 				if (i & 4)
3800 				    STRCAT(errbuf, "h,l,");
3801 				if (i & 8)
3802 				    STRCAT(errbuf, "<,>,");
3803 				if (i & 16)
3804 				    STRCAT(errbuf, "[,],");
3805 				if (*errbuf != NUL)	/* remove trailing , */
3806 				    errbuf[STRLEN(errbuf) - 1] = NUL;
3807 				save_arg = arg;
3808 				arg = errbuf;
3809 			    }
3810 			    /*
3811 			     * Remove '>' before 'dir' and 'bdir', for
3812 			     * backwards compatibility with version 3.0
3813 			     */
3814 			    else if (  *arg == '>'
3815 				    && (varp == (char_u *)&p_dir
3816 					    || varp == (char_u *)&p_bdir))
3817 			    {
3818 				++arg;
3819 			    }
3820 
3821 			    /* When setting the local value of a global
3822 			     * option, the old value may be the global value. */
3823 			    if ((int)options[opt_idx].indir >= PV_BOTH
3824 						   && (opt_flags & OPT_LOCAL))
3825 				origval = *(char_u **)get_varp(
3826 							   &options[opt_idx]);
3827 			    else
3828 				origval = oldval;
3829 
3830 			    /*
3831 			     * Copy the new string into allocated memory.
3832 			     * Can't use set_string_option_direct(), because
3833 			     * we need to remove the backslashes.
3834 			     */
3835 			    /* get a bit too much */
3836 			    newlen = (unsigned)STRLEN(arg) + 1;
3837 			    if (adding || prepending || removing)
3838 				newlen += (unsigned)STRLEN(origval) + 1;
3839 			    newval = alloc(newlen);
3840 			    if (newval == NULL)  /* out of mem, don't change */
3841 				break;
3842 			    s = newval;
3843 
3844 			    /*
3845 			     * Copy the string, skip over escaped chars.
3846 			     * For MS-DOS and WIN32 backslashes before normal
3847 			     * file name characters are not removed, and keep
3848 			     * backslash at start, for "\\machine\path", but
3849 			     * do remove it for "\\\\machine\\path".
3850 			     * The reverse is found in ExpandOldSetting().
3851 			     */
3852 			    while (*arg && !vim_iswhite(*arg))
3853 			    {
3854 				if (*arg == '\\' && arg[1] != NUL
3855 #ifdef BACKSLASH_IN_FILENAME
3856 					&& !((flags & P_EXPAND)
3857 						&& vim_isfilec(arg[1])
3858 						&& (arg[1] != '\\'
3859 						    || (s == newval
3860 							&& arg[2] != '\\')))
3861 #endif
3862 								    )
3863 				    ++arg;	/* remove backslash */
3864 #ifdef FEAT_MBYTE
3865 				if (has_mbyte
3866 					&& (i = (*mb_ptr2len_check)(arg)) > 1)
3867 				{
3868 				    /* copy multibyte char */
3869 				    mch_memmove(s, arg, (size_t)i);
3870 				    arg += i;
3871 				    s += i;
3872 				}
3873 				else
3874 #endif
3875 				    *s++ = *arg++;
3876 			    }
3877 			    *s = NUL;
3878 
3879 			    /*
3880 			     * Expand environment variables and ~.
3881 			     * Don't do it when adding without inserting a
3882 			     * comma.
3883 			     */
3884 			    if (!(adding || prepending || removing)
3885 							 || (flags & P_COMMA))
3886 			    {
3887 				s = option_expand(opt_idx, newval);
3888 				if (s != NULL)
3889 				{
3890 				    vim_free(newval);
3891 				    newlen = (unsigned)STRLEN(s) + 1;
3892 				    if (adding || prepending || removing)
3893 					newlen += (unsigned)STRLEN(origval) + 1;
3894 				    newval = alloc(newlen);
3895 				    if (newval == NULL)
3896 					break;
3897 				    STRCPY(newval, s);
3898 				}
3899 			    }
3900 
3901 			    /* locate newval[] in origval[] when removing it
3902 			     * and when adding to avoid duplicates */
3903 			    i = 0;	/* init for GCC */
3904 			    if (removing || (flags & P_NODUP))
3905 			    {
3906 				i = (int)STRLEN(newval);
3907 				bs = 0;
3908 				for (s = origval; *s; ++s)
3909 				{
3910 				    if ((!(flags & P_COMMA)
3911 						|| s == origval
3912 						|| (s[-1] == ',' && !(bs & 1)))
3913 					    && STRNCMP(s, newval, i) == 0
3914 					    && (!(flags & P_COMMA)
3915 						|| s[i] == ','
3916 						|| s[i] == NUL))
3917 					break;
3918 				    /* Count backspaces.  Only a comma with an
3919 				     * even number of backspaces before it is
3920 				     * recognized as a separator */
3921 				    if (s > origval && s[-1] == '\\')
3922 					++bs;
3923 				    else
3924 					bs = 0;
3925 				}
3926 
3927 				/* do not add if already there */
3928 				if ((adding || prepending) && *s)
3929 				{
3930 				    prepending = FALSE;
3931 				    adding = FALSE;
3932 				    STRCPY(newval, origval);
3933 				}
3934 			    }
3935 
3936 			    /* concatenate the two strings; add a ',' if
3937 			     * needed */
3938 			    if (adding || prepending)
3939 			    {
3940 				comma = ((flags & P_COMMA) && *origval != NUL
3941 							   && *newval != NUL);
3942 				if (adding)
3943 				{
3944 				    i = (int)STRLEN(origval);
3945 				    mch_memmove(newval + i + comma, newval,
3946 							  STRLEN(newval) + 1);
3947 				    mch_memmove(newval, origval, (size_t)i);
3948 				}
3949 				else
3950 				{
3951 				    i = (int)STRLEN(newval);
3952 				    mch_memmove(newval + i + comma, origval,
3953 							  STRLEN(origval) + 1);
3954 				}
3955 				if (comma)
3956 				    newval[i] = ',';
3957 			    }
3958 
3959 			    /* Remove newval[] from origval[]. (Note: "i" has
3960 			     * been set above and is used here). */
3961 			    if (removing)
3962 			    {
3963 				STRCPY(newval, origval);
3964 				if (*s)
3965 				{
3966 				    /* may need to remove a comma */
3967 				    if (flags & P_COMMA)
3968 				    {
3969 					if (s == origval)
3970 					{
3971 					    /* include comma after string */
3972 					    if (s[i] == ',')
3973 						++i;
3974 					}
3975 					else
3976 					{
3977 					    /* include comma before string */
3978 					    --s;
3979 					    ++i;
3980 					}
3981 				    }
3982 				    mch_memmove(newval + (s - origval), s + i,
3983 							   STRLEN(s + i) + 1);
3984 				}
3985 			    }
3986 
3987 			    if (flags & P_FLAGLIST)
3988 			    {
3989 				/* Remove flags that appear twice. */
3990 				for (s = newval; *s; ++s)
3991 				    if ((!(flags & P_COMMA) || *s != ',')
3992 					    && vim_strchr(s + 1, *s) != NULL)
3993 				    {
3994 					STRCPY(s, s + 1);
3995 					--s;
3996 				    }
3997 			    }
3998 
3999 			    if (save_arg != NULL)   /* number for 'whichwrap' */
4000 				arg = save_arg;
4001 			    new_value_alloced = TRUE;
4002 			}
4003 
4004 			/* Set the new value. */
4005 			*(char_u **)(varp) = newval;
4006 
4007 			/* Handle side effects, and set the global value for
4008 			 * ":set" on local options. */
4009 			errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4010 				new_value_alloced, oldval, errbuf, opt_flags);
4011 
4012 			/* If error detected, print the error message. */
4013 			if (errmsg != NULL)
4014 			    goto skip;
4015 		    }
4016 		    else	    /* key code option */
4017 		    {
4018 			char_u	    *p;
4019 
4020 			if (nextchar == '&')
4021 			{
4022 			    if (add_termcap_entry(key_name, TRUE) == FAIL)
4023 				errmsg = (char_u *)N_("E522: Not found in termcap");
4024 			}
4025 			else
4026 			{
4027 			    ++arg; /* jump to after the '=' or ':' */
4028 			    for (p = arg; *p && !vim_iswhite(*p); ++p)
4029 				if (*p == '\\' && p[1] != NUL)
4030 				    ++p;
4031 			    nextchar = *p;
4032 			    *p = NUL;
4033 			    add_termcode(key_name, arg, FALSE);
4034 			    *p = nextchar;
4035 			}
4036 			if (full_screen)
4037 			    ttest(FALSE);
4038 			redraw_all_later(CLEAR);
4039 		    }
4040 		}
4041 		if (opt_idx >= 0)
4042 		    options[opt_idx].flags |= P_WAS_SET;
4043 	    }
4044 
4045 skip:
4046 	    /*
4047 	     * Advance to next argument.
4048 	     * - skip until a blank found, taking care of backslashes
4049 	     * - skip blanks
4050 	     * - skip one "=val" argument (for hidden options ":set gfn =xx")
4051 	     */
4052 	    for (i = 0; i < 2 ; ++i)
4053 	    {
4054 		while (*arg != NUL && !vim_iswhite(*arg))
4055 		    if (*arg++ == '\\' && *arg != NUL)
4056 			++arg;
4057 		arg = skipwhite(arg);
4058 		if (*arg != '=')
4059 		    break;
4060 	    }
4061 	}
4062 
4063 	if (errmsg != NULL)
4064 	{
4065 	    STRNCPY(IObuff, _(errmsg), IOSIZE - 1);
4066 	    IObuff[IOSIZE - 1] = NUL;
4067 	    i = STRLEN(IObuff) + 2;
4068 	    if (i + (arg - startarg) < IOSIZE)
4069 	    {
4070 		/* append the argument with the error */
4071 		STRCAT(IObuff, ": ");
4072 		mch_memmove(IObuff + i, startarg, (arg - startarg));
4073 		IObuff[i + (arg - startarg)] = NUL;
4074 	    }
4075 	    /* make sure all characters are printable */
4076 	    trans_characters(IObuff, IOSIZE);
4077 
4078 	    ++no_wait_return;	/* wait_return done later */
4079 	    emsg(IObuff);	/* show error highlighted */
4080 	    --no_wait_return;
4081 
4082 	    return FAIL;
4083 	}
4084 
4085 	arg = skipwhite(arg);
4086     }
4087 
4088     return OK;
4089 }
4090 
4091     static char_u *
4092 illegal_char(errbuf, c)
4093     char_u	*errbuf;
4094     int		c;
4095 {
4096     if (errbuf == NULL)
4097 	return (char_u *)"";
4098     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
4099 	    (char *)transchar(c));
4100     return errbuf;
4101 }
4102 
4103 /*
4104  * Convert a key name or string into a key value.
4105  * Used for 'wildchar' and 'cedit' options.
4106  */
4107     static int
4108 string_to_key(arg)
4109     char_u	*arg;
4110 {
4111     if (*arg == '<')
4112 	return find_key_option(arg + 1);
4113     if (*arg == '^')
4114 	return Ctrl_chr(arg[1]);
4115     return *arg;
4116 }
4117 
4118 #ifdef FEAT_CMDWIN
4119 /*
4120  * Check value of 'cedit' and set cedit_key.
4121  * Returns NULL if value is OK, error message otherwise.
4122  */
4123     static char_u *
4124 check_cedit()
4125 {
4126     int n;
4127 
4128     if (*p_cedit == NUL)
4129 	cedit_key = -1;
4130     else
4131     {
4132 	n = string_to_key(p_cedit);
4133 	if (vim_isprintc(n))
4134 	    return e_invarg;
4135 	cedit_key = n;
4136     }
4137     return NULL;
4138 }
4139 #endif
4140 
4141 #ifdef FEAT_TITLE
4142 /*
4143  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
4144  * maketitle() to create and display it.
4145  * When switching the title or icon off, call mch_restore_title() to get
4146  * the old value back.
4147  */
4148     static void
4149 did_set_title(icon)
4150     int	    icon;	    /* Did set icon instead of title */
4151 {
4152     if (starting != NO_SCREEN
4153 #ifdef FEAT_GUI
4154 	    && !gui.starting
4155 #endif
4156 				)
4157     {
4158 	maketitle();
4159 	if (icon)
4160 	{
4161 	    if (!p_icon)
4162 		mch_restore_title(2);
4163 	}
4164 	else
4165 	{
4166 	    if (!p_title)
4167 		mch_restore_title(1);
4168 	}
4169     }
4170 }
4171 #endif
4172 
4173 /*
4174  * set_options_bin -  called when 'bin' changes value.
4175  */
4176     void
4177 set_options_bin(oldval, newval, opt_flags)
4178     int		oldval;
4179     int		newval;
4180     int		opt_flags;	/* OPT_LOCAL and/or OPT_GLOBAL */
4181 {
4182     /*
4183      * The option values that are changed when 'bin' changes are
4184      * copied when 'bin is set and restored when 'bin' is reset.
4185      */
4186     if (newval)
4187     {
4188 	if (!oldval)		/* switched on */
4189 	{
4190 	    if (!(opt_flags & OPT_GLOBAL))
4191 	    {
4192 		curbuf->b_p_tw_nobin = curbuf->b_p_tw;
4193 		curbuf->b_p_wm_nobin = curbuf->b_p_wm;
4194 		curbuf->b_p_ml_nobin = curbuf->b_p_ml;
4195 		curbuf->b_p_et_nobin = curbuf->b_p_et;
4196 	    }
4197 	    if (!(opt_flags & OPT_LOCAL))
4198 	    {
4199 		p_tw_nobin = p_tw;
4200 		p_wm_nobin = p_wm;
4201 		p_ml_nobin = p_ml;
4202 		p_et_nobin = p_et;
4203 	    }
4204 	}
4205 
4206 	if (!(opt_flags & OPT_GLOBAL))
4207 	{
4208 	    curbuf->b_p_tw = 0;	/* no automatic line wrap */
4209 	    curbuf->b_p_wm = 0;	/* no automatic line wrap */
4210 	    curbuf->b_p_ml = 0;	/* no modelines */
4211 	    curbuf->b_p_et = 0;	/* no expandtab */
4212 	}
4213 	if (!(opt_flags & OPT_LOCAL))
4214 	{
4215 	    p_tw = 0;
4216 	    p_wm = 0;
4217 	    p_ml = FALSE;
4218 	    p_et = FALSE;
4219 	    p_bin = TRUE;	/* needed when called for the "-b" argument */
4220 	}
4221     }
4222     else if (oldval)		/* switched off */
4223     {
4224 	if (!(opt_flags & OPT_GLOBAL))
4225 	{
4226 	    curbuf->b_p_tw = curbuf->b_p_tw_nobin;
4227 	    curbuf->b_p_wm = curbuf->b_p_wm_nobin;
4228 	    curbuf->b_p_ml = curbuf->b_p_ml_nobin;
4229 	    curbuf->b_p_et = curbuf->b_p_et_nobin;
4230 	}
4231 	if (!(opt_flags & OPT_LOCAL))
4232 	{
4233 	    p_tw = p_tw_nobin;
4234 	    p_wm = p_wm_nobin;
4235 	    p_ml = p_ml_nobin;
4236 	    p_et = p_et_nobin;
4237 	}
4238     }
4239 }
4240 
4241 #ifdef FEAT_VIMINFO
4242 /*
4243  * Find the parameter represented by the given character (eg ', :, ", or /),
4244  * and return its associated value in the 'viminfo' string.
4245  * Only works for number parameters, not for 'r' or 'n'.
4246  * If the parameter is not specified in the string, return -1.
4247  */
4248     int
4249 get_viminfo_parameter(type)
4250     int	    type;
4251 {
4252     char_u  *p;
4253 
4254     p = find_viminfo_parameter(type);
4255     if (p != NULL && VIM_ISDIGIT(*p))
4256 	return atoi((char *)p);
4257     return -1;
4258 }
4259 
4260 /*
4261  * Find the parameter represented by the given character (eg ''', ':', '"', or
4262  * '/') in the 'viminfo' option and return a pointer to the string after it.
4263  * Return NULL if the parameter is not specified in the string.
4264  */
4265     char_u *
4266 find_viminfo_parameter(type)
4267     int	    type;
4268 {
4269     char_u  *p;
4270 
4271     for (p = p_viminfo; *p; ++p)
4272     {
4273 	if (*p == type)
4274 	    return p + 1;
4275 	if (*p == 'n')		    /* 'n' is always the last one */
4276 	    break;
4277 	p = vim_strchr(p, ',');	    /* skip until next ',' */
4278 	if (p == NULL)		    /* hit the end without finding parameter */
4279 	    break;
4280     }
4281     return NULL;
4282 }
4283 #endif
4284 
4285 /*
4286  * Expand environment variables for some string options.
4287  * These string options cannot be indirect!
4288  * If "val" is NULL expand the current value of the option.
4289  * Return pointer to NameBuff, or NULL when not expanded.
4290  */
4291     static char_u *
4292 option_expand(opt_idx, val)
4293     int		opt_idx;
4294     char_u	*val;
4295 {
4296     /* if option doesn't need expansion nothing to do */
4297     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
4298 	return NULL;
4299 
4300     /* If val is longer than MAXPATHL no meaningful expansion can be done,
4301      * expand_env() would truncate the string. */
4302     if (val != NULL && STRLEN(val) > MAXPATHL)
4303 	return NULL;
4304 
4305     if (val == NULL)
4306 	val = *(char_u **)options[opt_idx].var;
4307 
4308     /*
4309      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
4310      * Escape spaces when expanding 'tags', they are used to separate file
4311      * names.
4312      */
4313     expand_env_esc(val, NameBuff, MAXPATHL,
4314 				  (char_u **)options[opt_idx].var == &p_tags);
4315     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
4316 	return NULL;
4317 
4318     return NameBuff;
4319 }
4320 
4321 /*
4322  * After setting various option values: recompute variables that depend on
4323  * option values.
4324  */
4325     static void
4326 didset_options()
4327 {
4328     /* initialize the table for 'iskeyword' et.al. */
4329     (void)init_chartab();
4330 
4331     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
4332     (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
4333 #ifdef FEAT_SESSION
4334     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
4335     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
4336 #endif
4337 #ifdef FEAT_FOLDING
4338     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
4339 #endif
4340     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
4341 #ifdef FEAT_VIRTUALEDIT
4342     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
4343 #endif
4344 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
4345     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
4346 #endif
4347 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
4348     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
4349 #endif
4350 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4351     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
4352 #endif
4353 #ifdef FEAT_CMDWIN
4354     /* set cedit_key */
4355     (void)check_cedit();
4356 #endif
4357 }
4358 
4359 /*
4360  * Check for string options that are NULL (normally only termcap options).
4361  */
4362     void
4363 check_options()
4364 {
4365     int		opt_idx;
4366 
4367     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
4368 	if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
4369 	    check_string_option((char_u **)get_varp(&(options[opt_idx])));
4370 }
4371 
4372 /*
4373  * Check string options in a buffer for NULL value.
4374  */
4375     void
4376 check_buf_options(buf)
4377     buf_T	*buf;
4378 {
4379 #if defined(FEAT_QUICKFIX)
4380     check_string_option(&buf->b_p_bh);
4381     check_string_option(&buf->b_p_bt);
4382 #endif
4383 #ifdef FEAT_MBYTE
4384     check_string_option(&buf->b_p_fenc);
4385 #endif
4386     check_string_option(&buf->b_p_ff);
4387 #ifdef FEAT_FIND_ID
4388     check_string_option(&buf->b_p_def);
4389     check_string_option(&buf->b_p_inc);
4390 # ifdef FEAT_EVAL
4391     check_string_option(&buf->b_p_inex);
4392 # endif
4393 #endif
4394 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
4395     check_string_option(&buf->b_p_inde);
4396     check_string_option(&buf->b_p_indk);
4397 #endif
4398 #ifdef FEAT_CRYPT
4399     check_string_option(&buf->b_p_key);
4400 #endif
4401     check_string_option(&buf->b_p_kp);
4402     check_string_option(&buf->b_p_mps);
4403     check_string_option(&buf->b_p_fo);
4404     check_string_option(&buf->b_p_isk);
4405 #ifdef FEAT_COMMENTS
4406     check_string_option(&buf->b_p_com);
4407 #endif
4408 #ifdef FEAT_FOLDING
4409     check_string_option(&buf->b_p_cms);
4410 #endif
4411     check_string_option(&buf->b_p_nf);
4412 #ifdef FEAT_TEXTOBJ
4413     check_string_option(&buf->b_p_qe);
4414 #endif
4415 #ifdef FEAT_SYN_HL
4416     check_string_option(&buf->b_p_syn);
4417 #endif
4418 #ifdef FEAT_SEARCHPATH
4419     check_string_option(&buf->b_p_sua);
4420 #endif
4421 #ifdef FEAT_CINDENT
4422     check_string_option(&buf->b_p_cink);
4423     check_string_option(&buf->b_p_cino);
4424 #endif
4425 #ifdef FEAT_AUTOCMD
4426     check_string_option(&buf->b_p_ft);
4427 #endif
4428 #ifdef FEAT_OSFILETYPE
4429     check_string_option(&buf->b_p_oft);
4430 #endif
4431 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
4432     check_string_option(&buf->b_p_cinw);
4433 #endif
4434 #ifdef FEAT_INS_EXPAND
4435     check_string_option(&buf->b_p_cpt);
4436 #endif
4437 #ifdef FEAT_COMPL_FUNC
4438     check_string_option(&buf->b_p_cfu);
4439 #endif
4440 #ifdef FEAT_KEYMAP
4441     check_string_option(&buf->b_p_keymap);
4442 #endif
4443 #ifdef FEAT_QUICKFIX
4444     check_string_option(&buf->b_p_gp);
4445     check_string_option(&buf->b_p_mp);
4446     check_string_option(&buf->b_p_efm);
4447 #endif
4448     check_string_option(&buf->b_p_ep);
4449     check_string_option(&buf->b_p_path);
4450     check_string_option(&buf->b_p_tags);
4451 #ifdef FEAT_INS_EXPAND
4452     check_string_option(&buf->b_p_dict);
4453     check_string_option(&buf->b_p_tsr);
4454 #endif
4455 }
4456 
4457 /*
4458  * Free the string allocated for an option.
4459  * Checks for the string being empty_option. This may happen if we're out of
4460  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
4461  * check_options().
4462  * Does NOT check for P_ALLOCED flag!
4463  */
4464     void
4465 free_string_option(p)
4466     char_u	*p;
4467 {
4468     if (p != empty_option)
4469 	vim_free(p);
4470 }
4471 
4472     void
4473 clear_string_option(pp)
4474     char_u	**pp;
4475 {
4476     if (*pp != empty_option)
4477 	vim_free(*pp);
4478     *pp = empty_option;
4479 }
4480 
4481     static void
4482 check_string_option(pp)
4483     char_u	**pp;
4484 {
4485     if (*pp == NULL)
4486 	*pp = empty_option;
4487 }
4488 
4489 /*
4490  * Mark a terminal option as allocated, found by a pointer into term_strings[].
4491  */
4492     void
4493 set_term_option_alloced(p)
4494     char_u **p;
4495 {
4496     int		opt_idx;
4497 
4498     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
4499 	if (options[opt_idx].var == (char_u *)p)
4500 	{
4501 	    options[opt_idx].flags |= P_ALLOCED;
4502 	    return;
4503 	}
4504     return; /* cannot happen: didn't find it! */
4505 }
4506 
4507 /*
4508  * Set a string option to a new value (without checking the effect).
4509  * The string is copied into allocated memory.
4510  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
4511  */
4512     void
4513 set_string_option_direct(name, opt_idx, val, opt_flags)
4514     char_u	*name;
4515     int		opt_idx;
4516     char_u	*val;
4517     int		opt_flags;	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
4518 {
4519     char_u	*s;
4520     char_u	**varp;
4521     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
4522 
4523     if (opt_idx == -1)		/* use name */
4524     {
4525 	opt_idx = findoption(name);
4526 	if (opt_idx == -1)	/* not found (should not happen) */
4527 	    return;
4528     }
4529 
4530     if (options[opt_idx].var == NULL)	/* can't set hidden option */
4531 	return;
4532 
4533     s = vim_strsave(val);
4534     if (s != NULL)
4535     {
4536 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4537 					       both ? OPT_LOCAL : opt_flags);
4538 	if ((opt_flags & OPT_FREE) && (options[opt_idx].flags & P_ALLOCED))
4539 	    free_string_option(*varp);
4540 	*varp = s;
4541 
4542 	/* For buffer/window local option may also set the global value. */
4543 	if (both)
4544 	    set_string_option_global(opt_idx, varp);
4545 
4546 	options[opt_idx].flags |= P_ALLOCED;
4547 
4548 	/* When setting both values of a global option with a local value,
4549 	 * make the local value empty, so that the global value is used. */
4550 	if ((int)options[opt_idx].indir >= PV_BOTH && both)
4551 	{
4552 	    free_string_option(*varp);
4553 	    *varp = empty_option;
4554 	}
4555     }
4556 }
4557 
4558 /*
4559  * Set global value for string option when it's a local option.
4560  */
4561     static void
4562 set_string_option_global(opt_idx, varp)
4563     int		opt_idx;	/* option index */
4564     char_u	**varp;		/* pointer to option variable */
4565 {
4566     char_u	**p, *s;
4567 
4568     /* the global value is always allocated */
4569     if (options[opt_idx].var == VAR_WIN)
4570 	p = (char_u **)GLOBAL_WO(varp);
4571     else
4572 	p = (char_u **)options[opt_idx].var;
4573     if (options[opt_idx].indir != PV_NONE
4574 	    && p != varp
4575 	    && (s = vim_strsave(*varp)) != NULL)
4576     {
4577 	free_string_option(*p);
4578 	*p = s;
4579     }
4580 }
4581 
4582 /*
4583  * Set a string option to a new value, and handle the effects.
4584  */
4585     static void
4586 set_string_option(opt_idx, value, opt_flags)
4587     int		opt_idx;
4588     char_u	*value;
4589     int		opt_flags;	/* OPT_LOCAL and/or OPT_GLOBAL */
4590 {
4591     char_u	*s;
4592     char_u	**varp;
4593     char_u	*oldval;
4594 
4595     if (options[opt_idx].var == NULL)	/* don't set hidden option */
4596 	return;
4597 
4598     s = vim_strsave(value);
4599     if (s != NULL)
4600     {
4601 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
4602 		(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4603 		    ? ((int)options[opt_idx].indir >= PV_BOTH
4604 			? OPT_GLOBAL : OPT_LOCAL)
4605 		    : opt_flags);
4606 	oldval = *varp;
4607 	*varp = s;
4608 	options[opt_idx].flags |= P_WAS_SET;
4609 	(void)did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
4610 								   opt_flags);
4611     }
4612 }
4613 
4614 /*
4615  * Handle string options that need some action to perform when changed.
4616  * Returns NULL for success, or an error message for an error.
4617  */
4618     static char_u *
4619 did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
4620 								    opt_flags)
4621     int		opt_idx;		/* index in options[] table */
4622     char_u	**varp;			/* pointer to the option variable */
4623     int		new_value_alloced;	/* new value was allocated */
4624     char_u	*oldval;		/* previous value of the option */
4625     char_u	*errbuf;		/* buffer for errors, or NULL */
4626     int		opt_flags;		/* OPT_LOCAL and/or OPT_GLOBAL */
4627 {
4628     char_u	*errmsg = NULL;
4629     char_u	*s, *p;
4630     int		did_chartab = FALSE;
4631     char_u	**gvarp;
4632 
4633     /* Get the global option to compare with, otherwise we would have to check
4634      * two values for all local options. */
4635     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
4636 
4637     /* Disallow changing some options from secure mode */
4638     if ((secure
4639 #ifdef HAVE_SANDBOX
4640 		|| sandbox != 0
4641 #endif
4642 		) && (options[opt_idx].flags & P_SECURE))
4643     {
4644 	errmsg = e_secure;
4645     }
4646 
4647     /* 'term' */
4648     else if (varp == &T_NAME)
4649     {
4650 	if (T_NAME[0] == NUL)
4651 	    errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
4652 #ifdef FEAT_GUI
4653 	if (gui.in_use)
4654 	    errmsg = (char_u *)N_("E530: Cannot change term in GUI");
4655 	else if (term_is_gui(T_NAME))
4656 	    errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
4657 #endif
4658 	else if (set_termname(T_NAME) == FAIL)
4659 	    errmsg = (char_u *)N_("E522: Not found in termcap");
4660 	else
4661 	    /* Screen colors may have changed. */
4662 	    redraw_later_clear();
4663     }
4664 
4665     /* 'backupcopy' */
4666     else if (varp == &p_bkc)
4667     {
4668 	if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
4669 	    errmsg = e_invarg;
4670 	if (((bkc_flags & BKC_AUTO) != 0)
4671 		+ ((bkc_flags & BKC_YES) != 0)
4672 		+ ((bkc_flags & BKC_NO) != 0) != 1)
4673 	{
4674 	    /* Must have exactly one of "auto", "yes"  and "no". */
4675 	    (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
4676 	    errmsg = e_invarg;
4677 	}
4678     }
4679 
4680     /* 'backupext' and 'patchmode' */
4681     else if (varp == &p_bex || varp == &p_pm)
4682     {
4683 	if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
4684 		     *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
4685 	    errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
4686     }
4687 
4688     /*
4689      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
4690      * If the new option is invalid, use old value.  'lisp' option: refill
4691      * chartab[] for '-' char
4692      */
4693     else if (  varp == &p_isi
4694 	    || varp == &(curbuf->b_p_isk)
4695 	    || varp == &p_isp
4696 	    || varp == &p_isf)
4697     {
4698 	if (init_chartab() == FAIL)
4699 	{
4700 	    did_chartab = TRUE;	    /* need to restore it below */
4701 	    errmsg = e_invarg;	    /* error in value */
4702 	}
4703     }
4704 
4705     /* 'helpfile' */
4706     else if (varp == &p_hf)
4707     {
4708 	/* May compute new values for $VIM and $VIMRUNTIME */
4709 	if (didset_vim)
4710 	{
4711 	    vim_setenv((char_u *)"VIM", (char_u *)"");
4712 	    didset_vim = FALSE;
4713 	}
4714 	if (didset_vimruntime)
4715 	{
4716 	    vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
4717 	    didset_vimruntime = FALSE;
4718 	}
4719     }
4720 
4721 #ifdef FEAT_MULTI_LANG
4722     /* 'helplang' */
4723     else if (varp == &p_hlg)
4724     {
4725 	/* Check for "", "ab", "ab,cd", etc. */
4726 	for (s = p_hlg; *s != NUL; s += 3)
4727 	{
4728 	    if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
4729 	    {
4730 		errmsg = e_invarg;
4731 		break;
4732 	    }
4733 	    if (s[2] == NUL)
4734 		break;
4735 	}
4736     }
4737 #endif
4738 
4739     /* 'highlight' */
4740     else if (varp == &p_hl)
4741     {
4742 	if (highlight_changed() == FAIL)
4743 	    errmsg = e_invarg;	/* invalid flags */
4744     }
4745 
4746     /* 'nrformats' */
4747     else if (gvarp == &p_nf)
4748     {
4749 	if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
4750 	    errmsg = e_invarg;
4751     }
4752 
4753 #ifdef FEAT_SESSION
4754     /* 'sessionoptions' */
4755     else if (varp == &p_ssop)
4756     {
4757 	if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
4758 	    errmsg = e_invarg;
4759 	if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
4760 	{
4761 	    /* Don't allow both "sesdir" and "curdir". */
4762 	    (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
4763 	    errmsg = e_invarg;
4764 	}
4765     }
4766     /* 'viewoptions' */
4767     else if (varp == &p_vop)
4768     {
4769 	if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
4770 	    errmsg = e_invarg;
4771     }
4772 #endif
4773 
4774     /* 'scrollopt' */
4775 #ifdef FEAT_SCROLLBIND
4776     else if (varp == &p_sbo)
4777     {
4778 	if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
4779 	    errmsg = e_invarg;
4780     }
4781 #endif
4782 
4783     /* 'ambiwidth' */
4784 #ifdef FEAT_MBYTE
4785     else if (varp == &p_ambw)
4786     {
4787 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
4788 	    errmsg = e_invarg;
4789     }
4790 #endif
4791 
4792     /* 'background' */
4793     else if (varp == &p_bg)
4794     {
4795 	if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
4796 	{
4797 #ifdef FEAT_EVAL
4798 	    int dark = (*p_bg == 'd');
4799 #endif
4800 
4801 	    init_highlight(FALSE, FALSE);
4802 
4803 #ifdef FEAT_EVAL
4804 	    if (dark != (*p_bg == 'd')
4805 			  && get_var_value((char_u *)"g:colors_name") != NULL)
4806 	    {
4807 		/* The color scheme must have set 'background' back to another
4808 		 * value, that's not what we want here.  Disable the color
4809 		 * scheme and set the colors again. */
4810 		do_unlet((char_u *)"g:colors_name");
4811 		free_string_option(p_bg);
4812 		p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
4813 		check_string_option(&p_bg);
4814 		init_highlight(FALSE, FALSE);
4815 	    }
4816 #endif
4817 	}
4818 	else
4819 	    errmsg = e_invarg;
4820     }
4821 
4822     /* 'wildmode' */
4823     else if (varp == &p_wim)
4824     {
4825 	if (check_opt_wim() == FAIL)
4826 	    errmsg = e_invarg;
4827     }
4828 
4829 #ifdef FEAT_WAK
4830     /* 'winaltkeys' */
4831     else if (varp == &p_wak)
4832     {
4833 	if (*p_wak == NUL
4834 		|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
4835 	    errmsg = e_invarg;
4836 # ifdef FEAT_MENU
4837 #  ifdef FEAT_GUI_MOTIF
4838 	else if (gui.in_use)
4839 	    gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4840 #  else
4841 #   ifdef FEAT_GUI_GTK
4842 	else if (gui.in_use)
4843 	    gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
4844 #   endif
4845 #  endif
4846 # endif
4847     }
4848 #endif
4849 
4850 #ifdef FEAT_AUTOCMD
4851     /* 'eventignore' */
4852     else if (varp == &p_ei)
4853     {
4854 	if (check_ei() == FAIL)
4855 	    errmsg = e_invarg;
4856     }
4857 #endif
4858 
4859 #ifdef FEAT_MBYTE
4860     /* 'encoding' and 'fileencoding' */
4861     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
4862     {
4863 	if (gvarp == &p_fenc)
4864 	{
4865 	    if (!curbuf->b_p_ma)
4866 		errmsg = e_modifiable;
4867 	    else if (vim_strchr(*varp, ',') != NULL)
4868 		/* No comma allowed in 'fileencoding'; catches confusing it
4869 		 * with 'fileencodings'. */
4870 		errmsg = e_invarg;
4871 # ifdef FEAT_TITLE
4872 	    else
4873 		/* May show a "+" in the title now. */
4874 		need_maketitle = TRUE;
4875 # endif
4876 	}
4877 	if (errmsg == NULL)
4878 	{
4879 	    /* canonize the value, so that STRCMP() can be used on it */
4880 	    p = enc_canonize(*varp);
4881 	    if (p != NULL)
4882 	    {
4883 		vim_free(*varp);
4884 		*varp = p;
4885 	    }
4886 	    if (varp == &p_enc)
4887 	    {
4888 		errmsg = mb_init();
4889 # ifdef FEAT_TITLE
4890 		need_maketitle = TRUE;
4891 # endif
4892 	    }
4893 	}
4894 
4895 # if defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
4896 	if (errmsg == NULL && varp == &p_tenc && gui.in_use)
4897 	{
4898 	    /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
4899 	    if (STRCMP(p_tenc, "utf-8") != 0)
4900 		errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
4901 	}
4902 # endif
4903 
4904 	if (errmsg == NULL)
4905 	{
4906 # ifdef FEAT_KEYMAP
4907 	    /* When 'keymap' is used and 'encoding' changes, reload the keymap
4908 	     * (with another encoding). */
4909 	    if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
4910 		(void)keymap_init();
4911 # endif
4912 
4913 	    /* When 'termencoding' is not empty and 'encoding' changes or when
4914 	     * 'termencoding' changes, need to setup for keyboard input and
4915 	     * display output conversion. */
4916 	    if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
4917 	    {
4918 		convert_setup(&input_conv, p_tenc, p_enc);
4919 		convert_setup(&output_conv, p_enc, p_tenc);
4920 	    }
4921 	}
4922     }
4923 #endif
4924 
4925 #if defined(FEAT_POSTSCRIPT)
4926     else if (varp == &p_penc)
4927     {
4928 	/* Canonize printencoding if VIM standard one */
4929 	p = enc_canonize(p_penc);
4930 	if (p != NULL)
4931 	{
4932 	    vim_free(p_penc);
4933 	    p_penc = p;
4934 	}
4935 	else
4936 	{
4937 	    /* Ensure lower case and '-' for '_' */
4938 	    for (s = p_penc; *s != NUL; s++)
4939 	    {
4940 		if (*s == '_')
4941 		    *s = '-';
4942 		else
4943 		    *s = TOLOWER_ASC(*s);
4944 	    }
4945 	}
4946     }
4947 #endif
4948 
4949 #if defined(FEAT_XIM) && ( defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) )
4950     else if (varp == &p_imak)
4951     {
4952 	if (gui.in_use && !im_xim_isvalid_imactivate())
4953 	    errmsg = e_invarg;
4954     }
4955 #endif
4956 
4957 #ifdef FEAT_KEYMAP
4958     else if (varp == &curbuf->b_p_keymap)
4959     {
4960 	/* load or unload key mapping tables */
4961 	errmsg = keymap_init();
4962 
4963 	/* When successfully installed a new keymap switch on using it. */
4964 	if (*curbuf->b_p_keymap != NUL && errmsg == NULL)
4965 	{
4966 	    curbuf->b_p_iminsert = B_IMODE_LMAP;
4967 	    if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
4968 		curbuf->b_p_imsearch = B_IMODE_LMAP;
4969 	    set_iminsert_global();
4970 	    set_imsearch_global();
4971 # ifdef FEAT_WINDOWS
4972 	    status_redraw_curbuf();
4973 # endif
4974 	}
4975     }
4976 #endif
4977 
4978     /* 'fileformat' */
4979     else if (gvarp == &p_ff)
4980     {
4981 	if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
4982 	    errmsg = e_modifiable;
4983 	else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
4984 	    errmsg = e_invarg;
4985 	else
4986 	{
4987 	    /* may also change 'textmode' */
4988 	    if (get_fileformat(curbuf) == EOL_DOS)
4989 		curbuf->b_p_tx = TRUE;
4990 	    else
4991 		curbuf->b_p_tx = FALSE;
4992 #ifdef FEAT_TITLE
4993 	    need_maketitle = TRUE;
4994 #endif
4995 	}
4996     }
4997 
4998     /* 'fileformats' */
4999     else if (varp == &p_ffs)
5000     {
5001 	if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
5002 	    errmsg = e_invarg;
5003 	else
5004 	{
5005 	    /* also change 'textauto' */
5006 	    if (*p_ffs == NUL)
5007 		p_ta = FALSE;
5008 	    else
5009 		p_ta = TRUE;
5010 	}
5011     }
5012 
5013 #if defined(FEAT_CRYPT) && defined(FEAT_CMDHIST)
5014     /* 'cryptkey' */
5015     else if (gvarp == &p_key)
5016     {
5017 	/* Make sure the ":set" command doesn't show the new value in the
5018 	 * history. */
5019 	remove_key_from_history();
5020     }
5021 #endif
5022 
5023     /* 'matchpairs' */
5024     else if (gvarp == &p_mps)
5025     {
5026 	/* Check for "x:y,x:y" */
5027 	for (p = *varp; *p != NUL; p += 4)
5028 	{
5029 	    if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
5030 	    {
5031 		errmsg = e_invarg;
5032 		break;
5033 	    }
5034 	    if (p[3] == NUL)
5035 		break;
5036 	}
5037     }
5038 
5039 #ifdef FEAT_COMMENTS
5040     /* 'comments' */
5041     else if (gvarp == &p_com)
5042     {
5043 	for (s = *varp; *s; )
5044 	{
5045 	    while (*s && *s != ':')
5046 	    {
5047 		if (vim_strchr((char_u *)COM_ALL, *s) == NULL
5048 					     && !VIM_ISDIGIT(*s) && *s != '-')
5049 		{
5050 		    errmsg = illegal_char(errbuf, *s);
5051 		    break;
5052 		}
5053 		++s;
5054 	    }
5055 	    if (*s++ == NUL)
5056 		errmsg = (char_u *)N_("E524: Missing colon");
5057 	    else if (*s == ',' || *s == NUL)
5058 		errmsg = (char_u *)N_("E525: Zero length string");
5059 	    if (errmsg != NULL)
5060 		break;
5061 	    while (*s && *s != ',')
5062 	    {
5063 		if (*s == '\\' && s[1] != NUL)
5064 		    ++s;
5065 		++s;
5066 	    }
5067 	    s = skip_to_option_part(s);
5068 	}
5069     }
5070 #endif
5071 
5072     /* 'listchars' */
5073     else if (varp == &p_lcs)
5074     {
5075 	errmsg = set_chars_option(varp);
5076     }
5077 
5078 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5079     /* 'fillchars' */
5080     else if (varp == &p_fcs)
5081     {
5082 	errmsg = set_chars_option(varp);
5083     }
5084 #endif
5085 
5086 #ifdef FEAT_CMDWIN
5087     /* 'cedit' */
5088     else if (varp == &p_cedit)
5089     {
5090 	errmsg = check_cedit();
5091     }
5092 #endif
5093 
5094 #ifdef FEAT_VIMINFO
5095     /* 'viminfo' */
5096     else if (varp == &p_viminfo)
5097     {
5098 	for (s = p_viminfo; *s;)
5099 	{
5100 	    /* Check it's a valid character */
5101 	    if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
5102 	    {
5103 		errmsg = illegal_char(errbuf, *s);
5104 		break;
5105 	    }
5106 	    if (*s == 'n')	/* name is always last one */
5107 	    {
5108 		break;
5109 	    }
5110 	    else if (*s == 'r') /* skip until next ',' */
5111 	    {
5112 		while (*++s && *s != ',')
5113 		    ;
5114 	    }
5115 	    else if (*s == '%' || *s == '!' || *s == 'h' || *s == 'c')
5116 		++s;		/* no extra chars */
5117 	    else		/* must have a number */
5118 	    {
5119 		while (vim_isdigit(*++s))
5120 		    ;
5121 
5122 		if (!VIM_ISDIGIT(*(s - 1)))
5123 		{
5124 		    if (errbuf != NULL)
5125 		    {
5126 			sprintf((char *)errbuf, _("E526: Missing number after <%s>"),
5127 						    transchar_byte(*(s - 1)));
5128 			errmsg = errbuf;
5129 		    }
5130 		    else
5131 			errmsg = (char_u *)"";
5132 		    break;
5133 		}
5134 	    }
5135 	    if (*s == ',')
5136 		++s;
5137 	    else if (*s)
5138 	    {
5139 		if (errbuf != NULL)
5140 		    errmsg = (char_u *)N_("E527: Missing comma");
5141 		else
5142 		    errmsg = (char_u *)"";
5143 		break;
5144 	    }
5145 	}
5146 	if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
5147 	    errmsg = (char_u *)N_("E528: Must specify a ' value");
5148     }
5149 #endif /* FEAT_VIMINFO */
5150 
5151     /* terminal options */
5152     else if (istermoption(&options[opt_idx]) && full_screen)
5153     {
5154 	/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
5155 	if (varp == &T_CCO)
5156 	{
5157 	    t_colors = atoi((char *)T_CCO);
5158 	    if (t_colors <= 1)
5159 	    {
5160 		if (new_value_alloced)
5161 		    vim_free(T_CCO);
5162 		T_CCO = empty_option;
5163 	    }
5164 	    /* We now have a different color setup, initialize it again. */
5165 	    init_highlight(TRUE, FALSE);
5166 	}
5167 	ttest(FALSE);
5168 	if (varp == &T_ME)
5169 	{
5170 	    out_str(T_ME);
5171 	    redraw_later(CLEAR);
5172 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
5173 	    /* Since t_me has been set, this probably means that the user
5174 	     * wants to use this as default colors.  Need to reset default
5175 	     * background/foreground colors. */
5176 	    mch_set_normal_colors();
5177 #endif
5178 	}
5179     }
5180 
5181 #ifdef FEAT_LINEBREAK
5182     /* 'showbreak' */
5183     else if (varp == &p_sbr)
5184     {
5185 	for (s = p_sbr; *s; )
5186 	{
5187 	    if (ptr2cells(s) != 1)
5188 		errmsg = (char_u *)N_("E595: contains unprintable or wide character");
5189 # ifdef FEAT_MBYTE
5190 	    if (has_mbyte)
5191 		s += (*mb_ptr2len_check)(s);
5192 	    else
5193 # endif
5194 		++s;
5195 	}
5196     }
5197 #endif
5198 
5199 #ifdef FEAT_GUI
5200     /* 'guifont' */
5201     else if (varp == &p_guifont)
5202     {
5203 	if (gui.in_use)
5204 	{
5205 	    p = p_guifont;
5206 # if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE)
5207 	    /*
5208 	     * Put up a font dialog and let the user select a new value.
5209 	     * If this is cancelled go back to the old value but don't
5210 	     * give an error message.
5211 	     */
5212 	    if (STRCMP(p, "*") == 0)
5213 	    {
5214 		p = gui_mch_font_dialog(oldval);
5215 
5216 		if (new_value_alloced)
5217 		    free_string_option(p_guifont);
5218 
5219 		p_guifont = (p != NULL) ? p : vim_strsave(oldval);
5220 		new_value_alloced = TRUE;
5221 	    }
5222 # endif
5223 	    if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
5224 	    {
5225 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
5226 		if (STRCMP(p_guifont, "*") == 0)
5227 		{
5228 		    /* Dialog was cancelled: Keep the old value without giving
5229 		     * an error message. */
5230 		    if (new_value_alloced)
5231 			free_string_option(p_guifont);
5232 		    p_guifont = vim_strsave(oldval);
5233 		    new_value_alloced = TRUE;
5234 		}
5235 		else
5236 # endif
5237 		    errmsg = (char_u *)N_("E596: Invalid font(s)");
5238 	    }
5239 	}
5240     }
5241 # ifdef FEAT_XFONTSET
5242     else if (varp == &p_guifontset)
5243     {
5244 	if (STRCMP(p_guifontset, "*") == 0)
5245 	    errmsg = (char_u *)N_("E597: can't select fontset");
5246 	else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
5247 	    errmsg = (char_u *)N_("E598: Invalid fontset");
5248     }
5249 # endif
5250 # ifdef FEAT_MBYTE
5251     else if (varp == &p_guifontwide)
5252     {
5253 	if (STRCMP(p_guifontwide, "*") == 0)
5254 	    errmsg = (char_u *)N_("E533: can't select wide font");
5255 	else if (gui_get_wide_font() == FAIL)
5256 	    errmsg = (char_u *)N_("E534: Invalid wide font");
5257     }
5258 # endif
5259 #endif
5260 
5261 #ifdef CURSOR_SHAPE
5262     /* 'guicursor' */
5263     else if (varp == &p_guicursor)
5264 	errmsg = parse_shape_opt(SHAPE_CURSOR);
5265 #endif
5266 
5267 #ifdef FEAT_MOUSESHAPE
5268     /* 'mouseshape' */
5269     else if (varp == &p_mouseshape)
5270     {
5271 	errmsg = parse_shape_opt(SHAPE_MOUSE);
5272 	update_mouseshape(-1);
5273     }
5274 #endif
5275 
5276 #ifdef FEAT_PRINTER
5277     else if (varp == &p_popt)
5278 	errmsg = parse_list_options(p_popt, printer_opts, OPT_PRINT_NUM_OPTIONS);
5279 #endif
5280 
5281 #ifdef FEAT_LANGMAP
5282     /* 'langmap' */
5283     else if (varp == &p_langmap)
5284 	langmap_set();
5285 #endif
5286 
5287 #ifdef FEAT_LINEBREAK
5288     /* 'breakat' */
5289     else if (varp == &p_breakat)
5290 	fill_breakat_flags();
5291 #endif
5292 
5293 #ifdef FEAT_TITLE
5294     /* 'titlestring' and 'iconstring' */
5295     else if (varp == &p_titlestring || varp == &p_iconstring)
5296     {
5297 # ifdef FEAT_STL_OPT
5298 	int	flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
5299 
5300 	/* NULL => statusline syntax */
5301 	if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
5302 	    stl_syntax |= flagval;
5303 	else
5304 	    stl_syntax &= ~flagval;
5305 # endif
5306 	did_set_title(varp == &p_iconstring);
5307 
5308     }
5309 #endif
5310 
5311 #ifdef FEAT_GUI
5312     /* 'guioptions' */
5313     else if (varp == &p_go)
5314 	gui_init_which_components(oldval);
5315 #endif
5316 
5317 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
5318     /* 'ttymouse' */
5319     else if (varp == &p_ttym)
5320     {
5321 	if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
5322 	    errmsg = e_invarg;
5323 	else
5324 	    check_mouse_termcode();
5325     }
5326 #endif
5327 
5328 #ifdef FEAT_VISUAL
5329     /* 'selection' */
5330     else if (varp == &p_sel)
5331     {
5332 	if (*p_sel == NUL
5333 		|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
5334 	    errmsg = e_invarg;
5335     }
5336 
5337     /* 'selectmode' */
5338     else if (varp == &p_slm)
5339     {
5340 	if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
5341 	    errmsg = e_invarg;
5342     }
5343 #endif
5344 
5345 #ifdef FEAT_BROWSE
5346     /* 'browsedir' */
5347     else if (varp == &p_bsdir)
5348     {
5349 	if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
5350 		&& !mch_isdir(p_bsdir))
5351 	    errmsg = e_invarg;
5352     }
5353 #endif
5354 
5355 #ifdef FEAT_VISUAL
5356     /* 'keymodel' */
5357     else if (varp == &p_km)
5358     {
5359 	if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
5360 	    errmsg = e_invarg;
5361 	else
5362 	{
5363 	    km_stopsel = (vim_strchr(p_km, 'o') != NULL);
5364 	    km_startsel = (vim_strchr(p_km, 'a') != NULL);
5365 	}
5366     }
5367 #endif
5368 
5369     /* 'mousemodel' */
5370     else if (varp == &p_mousem)
5371     {
5372 	if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
5373 	    errmsg = e_invarg;
5374 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
5375 	else if (*p_mousem != *oldval)
5376 	    /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
5377 	     * to create or delete the popup menus. */
5378 	    gui_motif_update_mousemodel(root_menu);
5379 #endif
5380     }
5381 
5382     /* 'switchbuf' */
5383     else if (varp == &p_swb)
5384     {
5385 	if (check_opt_strings(p_swb, p_swb_values, TRUE) != OK)
5386 	    errmsg = e_invarg;
5387     }
5388 
5389     /* 'debug' */
5390     else if (varp == &p_debug)
5391     {
5392 	if (check_opt_strings(p_debug, p_debug_values, FALSE) != OK)
5393 	    errmsg = e_invarg;
5394     }
5395 
5396     /* 'display' */
5397     else if (varp == &p_dy)
5398     {
5399 	if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
5400 	    errmsg = e_invarg;
5401 	else
5402 	    (void)init_chartab();
5403 
5404     }
5405 
5406 #ifdef FEAT_VERTSPLIT
5407     /* 'eadirection' */
5408     else if (varp == &p_ead)
5409     {
5410 	if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
5411 	    errmsg = e_invarg;
5412     }
5413 #endif
5414 
5415 #ifdef FEAT_CLIPBOARD
5416     /* 'clipboard' */
5417     else if (varp == &p_cb)
5418 	errmsg = check_clipboard_option();
5419 #endif
5420 
5421 #ifdef FEAT_AUTOCMD
5422 # ifdef FEAT_SYN_HL
5423     /* When 'syntax' is set, load the syntax of that name */
5424     else if (varp == &(curbuf->b_p_syn))
5425     {
5426 	apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
5427 					     curbuf->b_fname, TRUE, curbuf);
5428     }
5429 # endif
5430 
5431     /* When 'filetype' is set, trigger the FileType autocommands of that name */
5432     else if (varp == &(curbuf->b_p_ft))
5433     {
5434 	did_filetype = TRUE;
5435 	apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
5436 					     curbuf->b_fname, TRUE, curbuf);
5437     }
5438 #endif
5439 
5440 #ifdef FEAT_QUICKFIX
5441     /* When 'bufhidden' is set, check for valid value. */
5442     else if (gvarp == &p_bh)
5443     {
5444 	if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
5445 	    errmsg = e_invarg;
5446     }
5447 
5448     /* When 'buftype' is set, check for valid value. */
5449     else if (gvarp == &p_bt)
5450     {
5451 	if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
5452 	    errmsg = e_invarg;
5453 	else
5454 	{
5455 # ifdef FEAT_WINDOWS
5456 	    if (curwin->w_status_height)
5457 	    {
5458 		curwin->w_redr_status = TRUE;
5459 		redraw_later(VALID);
5460 	    }
5461 # endif
5462 	    curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
5463 	}
5464     }
5465 #endif
5466 
5467 #ifdef FEAT_STL_OPT
5468     /* 'statusline' or 'rulerformat' */
5469     else if (varp == &p_stl || varp == &p_ruf)
5470     {
5471 	int wid;
5472 
5473 	if (varp == &p_ruf)	/* reset ru_wid first */
5474 	    ru_wid = 0;
5475 	s = *varp;
5476 	if (varp == &p_ruf && *s == '%')
5477 	{
5478 	    /* set ru_wid if 'ruf' starts with "%99(" */
5479 	    if (*++s == '-')	/* ignore a '-' */
5480 		s++;
5481 	    wid = getdigits(&s);
5482 	    if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
5483 		ru_wid = wid;
5484 	    else
5485 		errmsg = check_stl_option(p_ruf);
5486 	}
5487 	else
5488 	    errmsg = check_stl_option(s);
5489 	if (varp == &(p_ruf) && errmsg == NULL)
5490 	    comp_col();
5491     }
5492 #endif
5493 
5494 #ifdef FEAT_INS_EXPAND
5495     /* check if it is a valid value for 'complete' -- Acevedo */
5496     else if (gvarp == &p_cpt)
5497     {
5498 	for (s = *varp; *s;)
5499 	{
5500 	    while(*s == ',' || *s == ' ')
5501 		s++;
5502 	    if (!*s)
5503 		break;
5504 	    if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
5505 	    {
5506 		errmsg = illegal_char(errbuf, *s);
5507 		break;
5508 	    }
5509 	    if (*++s != NUL && *s != ',' && *s != ' ')
5510 	    {
5511 		if (s[-1] == 'k' || s[-1] == 's')
5512 		{
5513 		    /* skip optional filename after 'k' and 's' */
5514 		    while (*s && *s != ',' && *s != ' ')
5515 		    {
5516 			if (*s == '\\')
5517 			    ++s;
5518 			++s;
5519 		    }
5520 		}
5521 		else
5522 		{
5523 		    if (errbuf != NULL)
5524 		    {
5525 			sprintf((char *)errbuf,
5526 				     _("E535: Illegal character after <%c>"),
5527 				     *--s);
5528 			errmsg = errbuf;
5529 		    }
5530 		    else
5531 			errmsg = (char_u *)"";
5532 		    break;
5533 		}
5534 	    }
5535 	}
5536     }
5537 #endif /* FEAT_INS_EXPAND */
5538 
5539 
5540 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5541     else if (varp == &p_toolbar)
5542     {
5543 	if (opt_strings_flags(p_toolbar, p_toolbar_values,
5544 			      &toolbar_flags, TRUE) != OK)
5545 	    errmsg = e_invarg;
5546 	else
5547 	{
5548 	    out_flush();
5549 	    gui_mch_show_toolbar((toolbar_flags &
5550 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5551 	}
5552     }
5553 #endif
5554 
5555 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) && defined(HAVE_GTK2)
5556     /* 'toolbariconsize': GTK+ 2 only */
5557     else if (varp == &p_tbis)
5558     {
5559 	if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
5560 	    errmsg = e_invarg;
5561 	else
5562 	{
5563 	    out_flush();
5564 	    gui_mch_show_toolbar((toolbar_flags &
5565 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
5566 	}
5567     }
5568 #endif
5569 
5570     /* 'pastetoggle': translate key codes like in a mapping */
5571     else if (varp == &p_pt)
5572     {
5573 	if (*p_pt)
5574 	{
5575 	    (void)replace_termcodes(p_pt, &p, TRUE, TRUE);
5576 	    if (p != NULL)
5577 	    {
5578 		if (new_value_alloced)
5579 		    free_string_option(p_pt);
5580 		p_pt = p;
5581 		new_value_alloced = TRUE;
5582 	    }
5583 	}
5584     }
5585 
5586     /* 'backspace' */
5587     else if (varp == &p_bs)
5588     {
5589 	if (VIM_ISDIGIT(*p_bs))
5590 	{
5591 	    if (*p_bs >'2' || p_bs[1] != NUL)
5592 		errmsg = e_invarg;
5593 	}
5594 	else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
5595 	    errmsg = e_invarg;
5596     }
5597 
5598     /* 'casemap' */
5599     else if (varp == &p_cmp)
5600     {
5601 	if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
5602 	    errmsg = e_invarg;
5603     }
5604 
5605 #ifdef FEAT_DIFF
5606     /* 'diffopt' */
5607     else if (varp == &p_dip)
5608     {
5609 	if (diffopt_changed() == FAIL)
5610 	    errmsg = e_invarg;
5611     }
5612 #endif
5613 
5614 #ifdef FEAT_FOLDING
5615     /* 'foldmethod' */
5616     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
5617     {
5618 	if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
5619 		|| *curwin->w_p_fdm == NUL)
5620 	    errmsg = e_invarg;
5621 	else
5622 	    foldUpdateAll(curwin);
5623     }
5624 # ifdef FEAT_EVAL
5625     /* 'foldexpr' */
5626     else if (varp == &curwin->w_p_fde)
5627     {
5628 	if (foldmethodIsExpr(curwin))
5629 	    foldUpdateAll(curwin);
5630     }
5631 # endif
5632     /* 'foldmarker' */
5633     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
5634     {
5635 	p = vim_strchr(*varp, ',');
5636 	if (p == NULL)
5637 	    errmsg = (char_u *)N_("E536: comma required");
5638 	else if (p == *varp || p[1] == NUL)
5639 	    errmsg = e_invarg;
5640 	else if (foldmethodIsMarker(curwin))
5641 	    foldUpdateAll(curwin);
5642     }
5643     /* 'commentstring' */
5644     else if (gvarp == &p_cms)
5645     {
5646 	if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
5647 	    errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
5648     }
5649     /* 'foldopen' */
5650     else if (varp == &p_fdo)
5651     {
5652 	if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
5653 	    errmsg = e_invarg;
5654     }
5655     /* 'foldclose' */
5656     else if (varp == &p_fcl)
5657     {
5658 	if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
5659 	    errmsg = e_invarg;
5660     }
5661 #endif
5662 
5663 #ifdef FEAT_VIRTUALEDIT
5664     /* 'virtualedit' */
5665     else if (varp == &p_ve)
5666     {
5667 	if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
5668 	    errmsg = e_invarg;
5669 	else if (STRCMP(p_ve, oldval) != 0)
5670 	{
5671 	    /* Recompute cursor position in case the new 've' setting
5672 	     * changes something. */
5673 	    validate_virtcol();
5674 	    coladvance(curwin->w_virtcol);
5675 	}
5676     }
5677 #endif
5678 
5679 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
5680     else if (varp == &p_csqf)
5681     {
5682 	if (p_csqf != NULL)
5683 	{
5684 	    p = p_csqf;
5685 	    while (*p != NUL)
5686 	    {
5687 		if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
5688 			|| p[1] == NUL
5689 			|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
5690 			|| (p[2] != NUL && p[2] != ','))
5691 		{
5692 		    errmsg = e_invarg;
5693 		    break;
5694 		}
5695 		else if (p[2] == NUL)
5696 		    break;
5697 		else
5698 		    p += 3;
5699 	    }
5700 	}
5701     }
5702 #endif
5703 
5704     /* Options that are a list of flags. */
5705     else
5706     {
5707 	p = NULL;
5708 	if (varp == &p_ww)
5709 	    p = (char_u *)WW_ALL;
5710 	if (varp == &p_shm)
5711 	    p = (char_u *)SHM_ALL;
5712 	else if (varp == &(p_cpo))
5713 	    p = (char_u *)CPO_ALL;
5714 	else if (varp == &(curbuf->b_p_fo))
5715 	    p = (char_u *)FO_ALL;
5716 	else if (varp == &p_mouse)
5717 	{
5718 #ifdef FEAT_MOUSE
5719 	    p = (char_u *)MOUSE_ALL;
5720 #else
5721 	    if (*p_mouse != NUL)
5722 		errmsg = (char_u *)N_("E538: No mouse support");
5723 #endif
5724 	}
5725 #if defined(FEAT_GUI)
5726 	else if (varp == &p_go)
5727 	    p = (char_u *)GO_ALL;
5728 #endif
5729 	if (p != NULL)
5730 	{
5731 	    for (s = *varp; *s; ++s)
5732 		if (vim_strchr(p, *s) == NULL)
5733 		{
5734 		    errmsg = illegal_char(errbuf, *s);
5735 		    break;
5736 		}
5737 	}
5738     }
5739 
5740     /*
5741      * If error detected, restore the previous value.
5742      */
5743     if (errmsg != NULL)
5744     {
5745 	if (new_value_alloced)
5746 	    free_string_option(*varp);
5747 	*varp = oldval;
5748 	/*
5749 	 * When resetting some values, need to act on it.
5750 	 */
5751 	if (did_chartab)
5752 	    (void)init_chartab();
5753 	if (varp == &p_hl)
5754 	    (void)highlight_changed();
5755     }
5756     else
5757     {
5758 #ifdef FEAT_EVAL
5759 	/* Remember where the option was set. */
5760 	options[opt_idx].scriptID = current_SID;
5761 #endif
5762 	/*
5763 	 * Free string options that are in allocated memory.
5764 	 */
5765 	if (options[opt_idx].flags & P_ALLOCED)
5766 	    free_string_option(oldval);
5767 	if (new_value_alloced)
5768 	    options[opt_idx].flags |= P_ALLOCED;
5769 	else
5770 	    options[opt_idx].flags &= ~P_ALLOCED;
5771 
5772 	if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5773 		&& (int)options[opt_idx].indir >= PV_BOTH)
5774 	{
5775 	    /* global option with local value set to use global value; free
5776 	     * the local value and make it empty */
5777 	    p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
5778 	    free_string_option(*(char_u **)p);
5779 	    *(char_u **)p = empty_option;
5780 	}
5781 
5782 	/* May set global value for local option. */
5783 	else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
5784 	    set_string_option_global(opt_idx, varp);
5785     }
5786 
5787 #ifdef FEAT_MOUSE
5788     if (varp == &p_mouse)
5789     {
5790 # ifdef FEAT_MOUSE_TTY
5791 	if (*p_mouse == NUL)
5792 	    mch_setmouse(FALSE);    /* switch mouse off */
5793 	else
5794 # endif
5795 	    setmouse();		    /* in case 'mouse' changed */
5796     }
5797 #endif
5798 
5799     if (curwin->w_curswant != MAXCOL)
5800 	curwin->w_set_curswant = TRUE;  /* in case 'showbreak' changed */
5801     check_redraw(options[opt_idx].flags);
5802 
5803     return errmsg;
5804 }
5805 
5806 /*
5807  * Handle setting 'listchars' or 'fillchars'.
5808  * Returns error message, NULL if it's OK.
5809  */
5810     static char_u *
5811 set_chars_option(varp)
5812     char_u	**varp;
5813 {
5814     int		round, i, len, entries;
5815     char_u	*p, *s;
5816     int		c1, c2 = 0;
5817     struct charstab
5818     {
5819 	int	*cp;
5820 	char	*name;
5821     };
5822 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5823     static struct charstab filltab[] =
5824     {
5825 	{&fill_stl,	"stl"},
5826 	{&fill_stlnc,	"stlnc"},
5827 	{&fill_vert,	"vert"},
5828 	{&fill_fold,	"fold"},
5829 	{&fill_diff,	"diff"},
5830     };
5831 #endif
5832     static struct charstab lcstab[] =
5833     {
5834 	{&lcs_eol,	"eol"},
5835 	{&lcs_ext,	"extends"},
5836 	{&lcs_nbsp,	"nbsp"},
5837 	{&lcs_prec,	"precedes"},
5838 	{&lcs_tab2,	"tab"},
5839 	{&lcs_trail,	"trail"},
5840     };
5841     struct charstab *tab;
5842 
5843 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5844     if (varp == &p_lcs)
5845 #endif
5846     {
5847 	tab = lcstab;
5848 	entries = sizeof(lcstab) / sizeof(struct charstab);
5849     }
5850 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5851     else
5852     {
5853 	tab = filltab;
5854 	entries = sizeof(filltab) / sizeof(struct charstab);
5855     }
5856 #endif
5857 
5858     /* first round: check for valid value, second round: assign values */
5859     for (round = 0; round <= 1; ++round)
5860     {
5861 	if (round)
5862 	{
5863 	    /* After checking that the value is valid: set defaults: space for
5864 	     * 'fillchars', NUL for 'listchars' */
5865 	    for (i = 0; i < entries; ++i)
5866 		*(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
5867 	    if (varp == &p_lcs)
5868 		lcs_tab1 = NUL;
5869 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5870 	    else
5871 		fill_diff = '-';
5872 #endif
5873 	}
5874 	p = *varp;
5875 	while (*p)
5876 	{
5877 	    for (i = 0; i < entries; ++i)
5878 	    {
5879 		len = (int)STRLEN(tab[i].name);
5880 		if (STRNCMP(p, tab[i].name, len) == 0
5881 			&& p[len] == ':'
5882 			&& p[len + 1] != NUL)
5883 		{
5884 		    s = p + len + 1;
5885 #ifdef FEAT_MBYTE
5886 		    c1 = mb_ptr2char_adv(&s);
5887 #else
5888 		    c1 = *s++;
5889 #endif
5890 		    if (tab[i].cp == &lcs_tab2)
5891 		    {
5892 			if (*s == NUL)
5893 			    continue;
5894 #ifdef FEAT_MBYTE
5895 			c2 = mb_ptr2char_adv(&s);
5896 #else
5897 			c2 = *s++;
5898 #endif
5899 		    }
5900 		    if (*s == ',' || *s == NUL)
5901 		    {
5902 			if (round)
5903 			{
5904 			    if (tab[i].cp == &lcs_tab2)
5905 			    {
5906 				lcs_tab1 = c1;
5907 				lcs_tab2 = c2;
5908 			    }
5909 			    else
5910 				*(tab[i].cp) = c1;
5911 
5912 			}
5913 			p = s;
5914 			break;
5915 		    }
5916 		}
5917 	    }
5918 
5919 	    if (i == entries)
5920 		return e_invarg;
5921 	    if (*p == ',')
5922 		++p;
5923 	}
5924     }
5925 
5926     return NULL;	/* no error */
5927 }
5928 
5929 #ifdef FEAT_STL_OPT
5930 /*
5931  * Check validity of options with the 'statusline' format.
5932  * Return error message or NULL.
5933  */
5934     char_u *
5935 check_stl_option(s)
5936     char_u	*s;
5937 {
5938     int		itemcnt = 0;
5939     int		groupdepth = 0;
5940     static char_u   errbuf[80];
5941 
5942     while (*s && itemcnt < STL_MAX_ITEM)
5943     {
5944 	/* Check for valid keys after % sequences */
5945 	while (*s && *s != '%')
5946 	    s++;
5947 	if (!*s)
5948 	    break;
5949 	s++;
5950 	if (*s != '%' && *s != ')')
5951 	    ++itemcnt;
5952 	if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
5953 	{
5954 	    s++;
5955 	    continue;
5956 	}
5957 	if (*s == ')')
5958 	{
5959 	    s++;
5960 	    if (--groupdepth < 0)
5961 		break;
5962 	    continue;
5963 	}
5964 	if (*s == '-')
5965 	    s++;
5966 	while (VIM_ISDIGIT(*s))
5967 	    s++;
5968 	if (*s == STL_HIGHLIGHT)
5969 	    continue;
5970 	if (*s == '.')
5971 	{
5972 	    s++;
5973 	    while (*s && VIM_ISDIGIT(*s))
5974 		s++;
5975 	}
5976 	if (*s == '(')
5977 	{
5978 	    groupdepth++;
5979 	    continue;
5980 	}
5981 	if (vim_strchr(STL_ALL, *s) == NULL)
5982 	{
5983 	    return illegal_char(errbuf, *s);
5984 	}
5985 	if (*s == '{')
5986 	{
5987 	    s++;
5988 	    while (*s != '}' && *s)
5989 		s++;
5990 	    if (*s != '}')
5991 		return (char_u *)N_("E540: Unclosed expression sequence");
5992 	}
5993     }
5994     if (itemcnt >= STL_MAX_ITEM)
5995 	return (char_u *)N_("E541: too many items");
5996     if (groupdepth != 0)
5997 	return (char_u *)N_("E542: unbalanced groups");
5998     return NULL;
5999 }
6000 #endif
6001 
6002 #ifdef FEAT_CLIPBOARD
6003 /*
6004  * Extract the items in the 'clipboard' option and set global values.
6005  */
6006     static char_u *
6007 check_clipboard_option()
6008 {
6009     int		new_unnamed = FALSE;
6010     int		new_autoselect = FALSE;
6011     int		new_autoselectml = FALSE;
6012     regprog_T	*new_exclude_prog = NULL;
6013     char_u	*errmsg = NULL;
6014     char_u	*p;
6015 
6016     for (p = p_cb; *p != NUL; )
6017     {
6018 	if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
6019 	{
6020 	    new_unnamed = TRUE;
6021 	    p += 7;
6022 	}
6023 	else if (STRNCMP(p, "autoselect", 10) == 0
6024 					&& (p[10] == ',' || p[10] == NUL))
6025 	{
6026 	    new_autoselect = TRUE;
6027 	    p += 10;
6028 	}
6029 	else if (STRNCMP(p, "autoselectml", 12) == 0
6030 					&& (p[12] == ',' || p[12] == NUL))
6031 	{
6032 	    new_autoselectml = TRUE;
6033 	    p += 12;
6034 	}
6035 	else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
6036 	{
6037 	    p += 8;
6038 	    new_exclude_prog = vim_regcomp(p, RE_MAGIC);
6039 	    if (new_exclude_prog == NULL)
6040 		errmsg = e_invarg;
6041 	    break;
6042 	}
6043 	else
6044 	{
6045 	    errmsg = e_invarg;
6046 	    break;
6047 	}
6048 	if (*p == ',')
6049 	    ++p;
6050     }
6051     if (errmsg == NULL)
6052     {
6053 	clip_unnamed = new_unnamed;
6054 	clip_autoselect = new_autoselect;
6055 	clip_autoselectml = new_autoselectml;
6056 	vim_free(clip_exclude_prog);
6057 	clip_exclude_prog = new_exclude_prog;
6058     }
6059     else
6060 	vim_free(new_exclude_prog);
6061 
6062     return errmsg;
6063 }
6064 #endif
6065 
6066 /*
6067  * Set the value of a boolean option, and take care of side effects.
6068  * Returns NULL for success, or an error message for an error.
6069  */
6070     static char_u *
6071 set_bool_option(opt_idx, varp, value, opt_flags)
6072     int		opt_idx;		/* index in options[] table */
6073     char_u	*varp;			/* pointer to the option variable */
6074     int		value;			/* new value */
6075     int		opt_flags;		/* OPT_LOCAL and/or OPT_GLOBAL */
6076 {
6077     int		old_value = *(int *)varp;
6078 
6079 #ifdef FEAT_GUI
6080     need_mouse_correct = TRUE;
6081 #endif
6082 
6083     /* Disallow changing some options from secure mode */
6084     if ((secure
6085 #ifdef HAVE_SANDBOX
6086 		|| sandbox != 0
6087 #endif
6088 		) && (options[opt_idx].flags & P_SECURE))
6089 	return e_secure;
6090 
6091     *(int *)varp = value;	    /* set the new value */
6092 #ifdef FEAT_EVAL
6093     /* Remember where the option was set. */
6094     options[opt_idx].scriptID = current_SID;
6095 #endif
6096 
6097     /* May set global value for local option. */
6098     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6099 	*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
6100 
6101     /*
6102      * Handle side effects of changing a bool option.
6103      */
6104 
6105     /* 'compatible' */
6106     if ((int *)varp == &p_cp)
6107     {
6108 	compatible_set();
6109     }
6110 
6111     /* when 'readonly' is reset globally, also reset readonlymode */
6112     else if ((int *)varp == &curbuf->b_p_ro)
6113     {
6114 	if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
6115 	    readonlymode = FALSE;
6116 #ifdef FEAT_TITLE
6117 	need_maketitle = TRUE;
6118 #endif
6119     }
6120 
6121 #ifdef FEAT_TITLE
6122     /* when 'modifiable' is changed, redraw the window title */
6123     else if ((int *)varp == &curbuf->b_p_ma)
6124 	need_maketitle = TRUE;
6125     /* when 'endofline' is changed, redraw the window title */
6126     else if ((int *)varp == &curbuf->b_p_eol)
6127 	need_maketitle = TRUE;
6128 #endif
6129 
6130     /* when 'bin' is set also set some other options */
6131     else if ((int *)varp == &curbuf->b_p_bin)
6132     {
6133 	set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
6134 #ifdef FEAT_TITLE
6135 	need_maketitle = TRUE;
6136 #endif
6137     }
6138 
6139 #ifdef FEAT_AUTOCMD
6140     /* when 'buflisted' changes, trigger autocommands */
6141     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
6142     {
6143 	apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
6144 						    NULL, NULL, TRUE, curbuf);
6145     }
6146 #endif
6147 
6148     /* when 'swf' is set, create swapfile, when reset remove swapfile */
6149     else if ((int *)varp == &curbuf->b_p_swf)
6150     {
6151 	if (curbuf->b_p_swf && p_uc)
6152 	    ml_open_file(curbuf);		/* create the swap file */
6153 	else
6154 	    mf_close_file(curbuf, TRUE);	/* remove the swap file */
6155     }
6156 
6157     /* when 'terse' is set change 'shortmess' */
6158     else if ((int *)varp == &p_terse)
6159     {
6160 	char_u	*p;
6161 
6162 	p = vim_strchr(p_shm, SHM_SEARCH);
6163 
6164 	/* insert 's' in p_shm */
6165 	if (p_terse && p == NULL)
6166 	{
6167 	    STRCPY(IObuff, p_shm);
6168 	    STRCAT(IObuff, "s");
6169 	    set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE);
6170 	}
6171 	/* remove 's' from p_shm */
6172 	else if (!p_terse && p != NULL)
6173 	    mch_memmove(p, p + 1, STRLEN(p));
6174     }
6175 
6176     /* when 'paste' is set or reset also change other options */
6177     else if ((int *)varp == &p_paste)
6178     {
6179 	paste_option_changed();
6180     }
6181 
6182     /* when 'insertmode' is set from an autocommand need to do work here */
6183     else if ((int *)varp == &p_im)
6184     {
6185 	if (p_im)
6186 	{
6187 	    if ((State & INSERT) == 0)
6188 		need_start_insertmode = TRUE;
6189 	    stop_insert_mode = FALSE;
6190 	}
6191 	else
6192 	{
6193 	    need_start_insertmode = FALSE;
6194 	    stop_insert_mode = TRUE;
6195 	    if (p_smd && restart_edit != 0)
6196 		clear_cmdline = TRUE;	/* remove "(insert)" */
6197 	    restart_edit = 0;
6198 	}
6199     }
6200 
6201     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
6202     else if ((int *)varp == &p_ic && p_hls)
6203     {
6204 	redraw_all_later(NOT_VALID);
6205     }
6206 
6207 #ifdef FEAT_SEARCH_EXTRA
6208     /* when 'hlsearch' is set or reset: reset no_hlsearch */
6209     else if ((int *)varp == &p_hls)
6210     {
6211 	no_hlsearch = FALSE;
6212     }
6213 #endif
6214 
6215 #ifdef FEAT_SCROLLBIND
6216     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
6217      * at the end of normal_cmd() */
6218     else if ((int *)varp == &curwin->w_p_scb)
6219     {
6220 	if (curwin->w_p_scb)
6221 	    do_check_scrollbind(FALSE);
6222     }
6223 #endif
6224 
6225 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
6226     /* There can be only one window with 'previewwindow' set. */
6227     else if ((int *)varp == &curwin->w_p_pvw)
6228     {
6229 	if (curwin->w_p_pvw)
6230 	{
6231 	    win_T	*win;
6232 
6233 	    for (win = firstwin; win != NULL; win = win->w_next)
6234 		if (win->w_p_pvw && win != curwin)
6235 		{
6236 		    curwin->w_p_pvw = FALSE;
6237 		    return (char_u *)N_("E590: A preview window already exists");
6238 		}
6239 	}
6240     }
6241 #endif
6242 
6243     /* when 'textmode' is set or reset also change 'fileformat' */
6244     else if ((int *)varp == &curbuf->b_p_tx)
6245     {
6246 	set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
6247     }
6248 
6249     /* when 'textauto' is set or reset also change 'fileformats' */
6250     else if ((int *)varp == &p_ta)
6251     {
6252 	set_string_option_direct((char_u *)"ffs", -1,
6253 				 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
6254 							OPT_FREE | opt_flags);
6255     }
6256 
6257     /*
6258      * When 'lisp' option changes include/exclude '-' in
6259      * keyword characters.
6260      */
6261 #ifdef FEAT_LISP
6262     else if (varp == (char_u *)&(curbuf->b_p_lisp))
6263     {
6264 	(void)buf_init_chartab(curbuf, FALSE);	    /* ignore errors */
6265     }
6266 #endif
6267 
6268 #ifdef FEAT_TITLE
6269     /* when 'title' changed, may need to change the title; same for 'icon' */
6270     else if ((int *)varp == &p_title)
6271     {
6272 	did_set_title(FALSE);
6273     }
6274 
6275     else if ((int *)varp == &p_icon)
6276     {
6277 	did_set_title(TRUE);
6278     }
6279 #endif
6280 
6281     else if ((int *)varp == &curbuf->b_changed)
6282     {
6283 	if (!value)
6284 	    save_file_ff(curbuf);	/* Buffer is unchanged */
6285 #ifdef FEAT_TITLE
6286 	need_maketitle = TRUE;
6287 #endif
6288 #ifdef FEAT_AUTOCMD
6289 	modified_was_set = value;
6290 #endif
6291     }
6292 
6293 #ifdef BACKSLASH_IN_FILENAME
6294     else if ((int *)varp == &p_ssl)
6295     {
6296 	if (p_ssl)
6297 	{
6298 	    psepc = '/';
6299 	    psepcN = '\\';
6300 	    pseps[0] = '/';
6301 	    psepsN[0] = '\\';
6302 	}
6303 	else
6304 	{
6305 	    psepc = '\\';
6306 	    psepcN = '/';
6307 	    pseps[0] = '\\';
6308 	    psepsN[0] = '/';
6309 	}
6310 
6311 	/* need to adjust the file name arguments and buffer names. */
6312 	buflist_slash_adjust();
6313 	alist_slash_adjust();
6314 # ifdef FEAT_EVAL
6315 	scriptnames_slash_adjust();
6316 # endif
6317     }
6318 #endif
6319 
6320     /* If 'wrap' is set, set w_leftcol to zero. */
6321     else if ((int *)varp == &curwin->w_p_wrap)
6322     {
6323 	if (curwin->w_p_wrap)
6324 	    curwin->w_leftcol = 0;
6325     }
6326 
6327 #ifdef FEAT_WINDOWS
6328     else if ((int *)varp == &p_ea)
6329     {
6330 	if (p_ea && !old_value)
6331 	    win_equal(curwin, FALSE, 0);
6332     }
6333 #endif
6334 
6335     else if ((int *)varp == &p_wiv)
6336     {
6337 	/*
6338 	 * When 'weirdinvert' changed, set/reset 't_xs'.
6339 	 * Then set 'weirdinvert' according to value of 't_xs'.
6340 	 */
6341 	if (p_wiv && !old_value)
6342 	    T_XS = (char_u *)"y";
6343 	else if (!p_wiv && old_value)
6344 	    T_XS = empty_option;
6345 	p_wiv = (*T_XS != NUL);
6346     }
6347 
6348 #if defined(FEAT_BEVAL) && (defined(FEAT_SUN_WORKSHOP) \
6349 	|| defined(FEAT_NETBEANS_INTG))
6350     else if ((int *)varp == &p_beval)
6351     {
6352 	extern BalloonEval	*balloonEval;
6353 
6354 	if (p_beval == TRUE)
6355 	    gui_mch_enable_beval_area(balloonEval);
6356 	else
6357 	    gui_mch_disable_beval_area(balloonEval);
6358     }
6359 
6360     else if ((int *)varp == &p_acd)
6361     {
6362 	if (p_acd && curbuf->b_ffname != NULL
6363 				     && vim_chdirfile(curbuf->b_ffname) == OK)
6364 	    shorten_fnames(TRUE);
6365     }
6366 #endif
6367 
6368 #ifdef FEAT_DIFF
6369     /* 'diff' */
6370     else if ((int *)varp == &curwin->w_p_diff)
6371     {
6372 	win_T	*wp;
6373 
6374 	if (!curwin->w_p_diff)
6375 	{
6376 	    /* When there is no window showing a diff for this buffer, remove
6377 	     * it from the diffs. */
6378 	    for (wp = firstwin; wp != NULL; wp = wp->w_next)
6379 		if (wp->w_buffer == curwin->w_buffer && wp->w_p_diff)
6380 		    break;
6381 	    if (wp == NULL)
6382 		diff_buf_delete(curwin->w_buffer);
6383 	}
6384 	else
6385 	    diff_buf_add(curwin->w_buffer);
6386 #ifdef FEAT_FOLDING
6387 	if (foldmethodIsDiff(curwin))
6388 	    foldUpdateAll(curwin);
6389 #endif
6390     }
6391 #endif
6392 
6393 #ifdef USE_IM_CONTROL
6394     /* 'imdisable' */
6395     else if ((int *)varp == &p_imdisable)
6396     {
6397 	/* Only de-activate it here, it will be enabled when changing mode. */
6398 	if (p_imdisable)
6399 	    im_set_active(FALSE);
6400     }
6401 #endif
6402 
6403 #ifdef FEAT_FKMAP
6404     else if ((int *)varp == &p_altkeymap)
6405     {
6406 	if (old_value != p_altkeymap)
6407 	{
6408 	    if (!p_altkeymap)
6409 	    {
6410 		p_hkmap = p_fkmap;
6411 		p_fkmap = 0;
6412 	    }
6413 	    else
6414 	    {
6415 		p_fkmap = p_hkmap;
6416 		p_hkmap = 0;
6417 	    }
6418 	    (void)init_chartab();
6419 	}
6420     }
6421 
6422     /*
6423      * In case some second language keymapping options have changed, check
6424      * and correct the setting in a consistent way.
6425      */
6426 
6427     /*
6428      * If hkmap or fkmap are set, reset Arabic keymapping.
6429      */
6430     if ((p_hkmap || p_fkmap) && p_altkeymap)
6431     {
6432 	p_altkeymap = p_fkmap;
6433 # ifdef FEAT_ARABIC
6434 	curwin->w_p_arab = FALSE;
6435 # endif
6436 	(void)init_chartab();
6437     }
6438 
6439     /*
6440      * If hkmap set, reset Farsi keymapping.
6441      */
6442     if (p_hkmap && p_altkeymap)
6443     {
6444 	p_altkeymap = 0;
6445 	p_fkmap = 0;
6446 # ifdef FEAT_ARABIC
6447 	curwin->w_p_arab = FALSE;
6448 # endif
6449 	(void)init_chartab();
6450     }
6451 
6452     /*
6453      * If fkmap set, reset Hebrew keymapping.
6454      */
6455     if (p_fkmap && !p_altkeymap)
6456     {
6457 	p_altkeymap = 1;
6458 	p_hkmap = 0;
6459 # ifdef FEAT_ARABIC
6460 	curwin->w_p_arab = FALSE;
6461 # endif
6462 	(void)init_chartab();
6463     }
6464 #endif
6465 
6466 #ifdef FEAT_ARABIC
6467     if ((int *)varp == &curwin->w_p_arab)
6468     {
6469 	if (curwin->w_p_arab)
6470 	{
6471 	    /*
6472 	     * 'arabic' is set, handle various sub-settings.
6473 	     */
6474 	    if (!p_tbidi)
6475 	    {
6476 		/* set rightleft mode */
6477 		if (!curwin->w_p_rl)
6478 		{
6479 		    curwin->w_p_rl = TRUE;
6480 		    changed_window_setting();
6481 		}
6482 
6483 		/* Enable Arabic shaping (major part of what Arabic requires) */
6484 		if (!p_arshape)
6485 		{
6486 		    p_arshape = TRUE;
6487 		    redraw_later_clear();
6488 		}
6489 	    }
6490 
6491 	    /* Arabic requires a utf-8 encoding, inform the user if its not
6492 	     * set. */
6493 	    if (STRCMP(p_enc, "utf-8") != 0)
6494 		MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"),
6495 			hl_attr(HLF_W));
6496 
6497 # ifdef FEAT_MBYTE
6498 	    /* set 'delcombine' */
6499 	    p_deco = TRUE;
6500 # endif
6501 
6502 # ifdef FEAT_KEYMAP
6503 	    /* Force-set the necessary keymap for arabic */
6504 	    set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
6505 								   OPT_LOCAL);
6506 # endif
6507 # ifdef FEAT_FKMAP
6508 	    p_altkeymap = 0;
6509 	    p_hkmap = 0;
6510 	    p_fkmap = 0;
6511 	    (void)init_chartab();
6512 # endif
6513 	}
6514 	else
6515 	{
6516 	    /*
6517 	     * 'arabic' is reset, handle various sub-settings.
6518 	     */
6519 	    if (!p_tbidi)
6520 	    {
6521 		/* reset rightleft mode */
6522 		if (curwin->w_p_rl)
6523 		{
6524 		    curwin->w_p_rl = FALSE;
6525 		    changed_window_setting();
6526 		}
6527 
6528 		/* 'arabicshape' isn't reset, it is a global option and
6529 		 * another window may still need it "on". */
6530 	    }
6531 
6532 	    /* 'delcombine' isn't reset, it is a global option and another
6533 	     * window may still want it "on". */
6534 
6535 # ifdef FEAT_KEYMAP
6536 	    /* Revert to the default keymap */
6537 	    curbuf->b_p_iminsert = B_IMODE_NONE;
6538 	    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6539 # endif
6540 	}
6541     }
6542 #endif
6543 
6544     /*
6545      * End of handling side effects for bool options.
6546      */
6547 
6548     options[opt_idx].flags |= P_WAS_SET;
6549 
6550     comp_col();			    /* in case 'ruler' or 'showcmd' changed */
6551     if (curwin->w_curswant != MAXCOL)
6552 	curwin->w_set_curswant = TRUE;  /* in case 'list' changed */
6553     check_redraw(options[opt_idx].flags);
6554 
6555     return NULL;
6556 }
6557 
6558 /*
6559  * Set the value of a number option, and take care of side effects.
6560  * Returns NULL for success, or an error message for an error.
6561  */
6562     static char_u *
6563 set_num_option(opt_idx, varp, value, errbuf, opt_flags)
6564     int		opt_idx;		/* index in options[] table */
6565     char_u	*varp;			/* pointer to the option variable */
6566     long	value;			/* new value */
6567     char_u	*errbuf;		/* buffer for error messages */
6568     int		opt_flags;		/* OPT_LOCAL, OPT_GLOBAL and
6569 					   OPT_MODELINE */
6570 {
6571     char_u	*errmsg = NULL;
6572     long	old_value = *(long *)varp;
6573     long	old_Rows = Rows;	/* remember old Rows */
6574     long	old_Columns = Columns;	/* remember old Columns */
6575     long	*pp = (long *)varp;
6576 
6577 #ifdef FEAT_GUI
6578     need_mouse_correct = TRUE;
6579 #endif
6580 
6581     *pp = value;
6582 #ifdef FEAT_EVAL
6583     /* Remember where the option was set. */
6584     options[opt_idx].scriptID = current_SID;
6585 #endif
6586 
6587     if (curbuf->b_p_sw <= 0)
6588     {
6589 	errmsg = e_positive;
6590 	curbuf->b_p_sw = curbuf->b_p_ts;
6591     }
6592 
6593     /*
6594      * Number options that need some action when changed
6595      */
6596 #ifdef FEAT_WINDOWS
6597     if (pp == &p_wh || pp == &p_hh)
6598     {
6599 	if (p_wh < 1)
6600 	{
6601 	    errmsg = e_positive;
6602 	    p_wh = 1;
6603 	}
6604 	if (p_wmh > p_wh)
6605 	{
6606 	    errmsg = e_winheight;
6607 	    p_wh = p_wmh;
6608 	}
6609 	if (p_hh < 0)
6610 	{
6611 	    errmsg = e_positive;
6612 	    p_hh = 0;
6613 	}
6614 
6615 	/* Change window height NOW */
6616 	if (lastwin != firstwin)
6617 	{
6618 	    if (pp == &p_wh && curwin->w_height < p_wh)
6619 		win_setheight((int)p_wh);
6620 	    if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
6621 		win_setheight((int)p_hh);
6622 	}
6623     }
6624 
6625     /* 'winminheight' */
6626     else if (pp == &p_wmh)
6627     {
6628 	if (p_wmh < 0)
6629 	{
6630 	    errmsg = e_positive;
6631 	    p_wmh = 0;
6632 	}
6633 	if (p_wmh > p_wh)
6634 	{
6635 	    errmsg = e_winheight;
6636 	    p_wmh = p_wh;
6637 	}
6638 	win_setminheight();
6639     }
6640 
6641 # ifdef FEAT_VERTSPLIT
6642     else if (pp == &p_wiw)
6643     {
6644 	if (p_wiw < 1)
6645 	{
6646 	    errmsg = e_positive;
6647 	    p_wiw = 1;
6648 	}
6649 	if (p_wmw > p_wiw)
6650 	{
6651 	    errmsg = e_winwidth;
6652 	    p_wiw = p_wmw;
6653 	}
6654 
6655 	/* Change window width NOW */
6656 	if (lastwin != firstwin && curwin->w_width < p_wiw)
6657 	    win_setwidth((int)p_wiw);
6658     }
6659 
6660     /* 'winminwidth' */
6661     else if (pp == &p_wmw)
6662     {
6663 	if (p_wmw < 0)
6664 	{
6665 	    errmsg = e_positive;
6666 	    p_wmw = 0;
6667 	}
6668 	if (p_wmw > p_wiw)
6669 	{
6670 	    errmsg = e_winwidth;
6671 	    p_wmw = p_wiw;
6672 	}
6673 	win_setminheight();
6674     }
6675 # endif
6676 
6677 #endif
6678 
6679 #ifdef FEAT_WINDOWS
6680     /* (re)set last window status line */
6681     else if (pp == &p_ls)
6682     {
6683 	last_status(FALSE);
6684     }
6685 #endif
6686 
6687 #ifdef FEAT_GUI
6688     else if (pp == &p_linespace)
6689     {
6690 	if (gui.in_use && gui_mch_adjust_charsize() == OK)
6691 	    gui_set_shellsize(FALSE, FALSE);
6692     }
6693 #endif
6694 
6695 #ifdef FEAT_FOLDING
6696     /* 'foldlevel' */
6697     else if (pp == &curwin->w_p_fdl)
6698     {
6699 	if (curwin->w_p_fdl < 0)
6700 	    curwin->w_p_fdl = 0;
6701 	newFoldLevel();
6702     }
6703 
6704     /* 'foldminlevel' */
6705     else if (pp == &curwin->w_p_fml)
6706     {
6707 	foldUpdateAll(curwin);
6708     }
6709 
6710     /* 'foldnestmax' */
6711     else if (pp == &curwin->w_p_fdn)
6712     {
6713 	if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
6714 	    foldUpdateAll(curwin);
6715     }
6716 
6717     /* 'foldcolumn' */
6718     else if (pp == &curwin->w_p_fdc)
6719     {
6720 	if (curwin->w_p_fdc < 0)
6721 	{
6722 	    errmsg = e_positive;
6723 	    curwin->w_p_fdc = 0;
6724 	}
6725 	else if (curwin->w_p_fdc > 12)
6726 	{
6727 	    errmsg = e_invarg;
6728 	    curwin->w_p_fdc = 12;
6729 	}
6730     }
6731 
6732     /* 'shiftwidth' or 'tabstop' */
6733     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
6734     {
6735 	if (foldmethodIsIndent(curwin))
6736 	    foldUpdateAll(curwin);
6737     }
6738 #endif /* FEAT_FOLDING */
6739 
6740     else if (pp == &curbuf->b_p_iminsert)
6741     {
6742 	if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
6743 	{
6744 	    errmsg = e_invarg;
6745 	    curbuf->b_p_iminsert = B_IMODE_NONE;
6746 	}
6747 	p_iminsert = curbuf->b_p_iminsert;
6748 	if (termcap_active)	/* don't do this in the alternate screen */
6749 	    showmode();
6750 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
6751 	/* Show/unshow value of 'keymap' in status lines. */
6752 	status_redraw_curbuf();
6753 #endif
6754     }
6755 
6756     else if (pp == &curbuf->b_p_imsearch)
6757     {
6758 	if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
6759 	{
6760 	    errmsg = e_invarg;
6761 	    curbuf->b_p_imsearch = B_IMODE_NONE;
6762 	}
6763 	p_imsearch = curbuf->b_p_imsearch;
6764     }
6765 
6766 #ifdef FEAT_TITLE
6767     /* if 'titlelen' has changed, redraw the title */
6768     else if (pp == &p_titlelen)
6769     {
6770 	if (p_titlelen < 0)
6771 	{
6772 	    errmsg = e_positive;
6773 	    p_titlelen = 85;
6774 	}
6775 	if (starting != NO_SCREEN && old_value != p_titlelen)
6776 	    need_maketitle = TRUE;
6777     }
6778 #endif
6779 
6780     /* if p_ch changed value, change the command line height */
6781     else if (pp == &p_ch)
6782     {
6783 	if (p_ch < 1)
6784 	{
6785 	    errmsg = e_positive;
6786 	    p_ch = 1;
6787 	}
6788 
6789 	/* Only compute the new window layout when startup has been
6790 	 * completed. Otherwise the frame sizes may be wrong. */
6791 	if (p_ch != old_value && full_screen
6792 #ifdef FEAT_GUI
6793 		&& !gui.starting
6794 #endif
6795 	   )
6796 	    command_height(old_value);
6797     }
6798 
6799     /* when 'updatecount' changes from zero to non-zero, open swap files */
6800     else if (pp == &p_uc)
6801     {
6802 	if (p_uc < 0)
6803 	{
6804 	    errmsg = e_positive;
6805 	    p_uc = 100;
6806 	}
6807 	if (p_uc && !old_value)
6808 	    ml_open_files();
6809     }
6810 
6811     /* sync undo before 'undolevels' changes */
6812     else if (pp == &p_ul)
6813     {
6814 	/* use the old value, otherwise u_sync() may not work properly */
6815 	p_ul = old_value;
6816 	u_sync();
6817 	p_ul = value;
6818     }
6819 
6820 #ifdef FEAT_LINEBREAK
6821     /* 'numberwidth' must be positive */
6822     else if (pp == &curwin->w_p_nuw)
6823     {
6824 	if (curwin->w_p_nuw < 1)
6825 	{
6826 	    errmsg = e_positive;
6827 	    curwin->w_p_nuw = 1;
6828 	}
6829 	if (curwin->w_p_nuw > 10)
6830 	{
6831 	    errmsg = e_invarg;
6832 	    curwin->w_p_nuw = 10;
6833 	}
6834 	curwin->w_nrwidth_line_count = 0;
6835     }
6836 #endif
6837 
6838     /*
6839      * Check the bounds for numeric options here
6840      */
6841     if (Rows < min_rows() && full_screen)
6842     {
6843 	if (errbuf != NULL)
6844 	{
6845 	    sprintf((char *)errbuf, _("E593: Need at least %d lines"),
6846 								  min_rows());
6847 	    errmsg = errbuf;
6848 	}
6849 	Rows = min_rows();
6850     }
6851     if (Columns < MIN_COLUMNS && full_screen)
6852     {
6853 	if (errbuf != NULL)
6854 	{
6855 	    sprintf((char *)errbuf, _("E594: Need at least %d columns"),
6856 								 MIN_COLUMNS);
6857 	    errmsg = errbuf;
6858 	}
6859 	Columns = MIN_COLUMNS;
6860     }
6861 
6862 #ifdef DJGPP
6863     /* avoid a crash by checking for a too large value of 'columns' */
6864     if (old_Columns != Columns && full_screen && term_console)
6865 	mch_check_columns();
6866 #endif
6867 
6868     /*
6869      * If the screen (shell) height has been changed, assume it is the
6870      * physical screenheight.
6871      */
6872     if (old_Rows != Rows || old_Columns != Columns)
6873     {
6874 	/* Changing the screen size is not allowed while updating the screen. */
6875 	if (updating_screen)
6876 	    *pp = old_value;
6877 	else if (full_screen
6878 #ifdef FEAT_GUI
6879 		&& !gui.starting
6880 #endif
6881 	    )
6882 	    set_shellsize((int)Columns, (int)Rows, TRUE);
6883 	else
6884 	{
6885 	    /* Postpone the resizing; check the size and cmdline position for
6886 	     * messages. */
6887 	    check_shellsize();
6888 	    if (cmdline_row > Rows - p_ch && Rows > p_ch)
6889 		cmdline_row = Rows - p_ch;
6890 	}
6891     }
6892 
6893     if (curbuf->b_p_sts < 0)
6894     {
6895 	errmsg = e_positive;
6896 	curbuf->b_p_sts = 0;
6897     }
6898     if (curbuf->b_p_ts <= 0)
6899     {
6900 	errmsg = e_positive;
6901 	curbuf->b_p_ts = 8;
6902     }
6903     if (curbuf->b_p_tw < 0)
6904     {
6905 	errmsg = e_positive;
6906 	curbuf->b_p_tw = 0;
6907     }
6908     if (p_tm < 0)
6909     {
6910 	errmsg = e_positive;
6911 	p_tm = 0;
6912     }
6913     if ((curwin->w_p_scr <= 0
6914 		|| (curwin->w_p_scr > curwin->w_height
6915 		    && curwin->w_height > 0))
6916 	    && full_screen)
6917     {
6918 	if (pp == &(curwin->w_p_scr))
6919 	{
6920 	    if (curwin->w_p_scr != 0)
6921 		errmsg = e_scroll;
6922 	    win_comp_scroll(curwin);
6923 	}
6924 	/* If 'scroll' became invalid because of a side effect silently adjust
6925 	 * it. */
6926 	else if (curwin->w_p_scr <= 0)
6927 	    curwin->w_p_scr = 1;
6928 	else /* curwin->w_p_scr > curwin->w_height */
6929 	    curwin->w_p_scr = curwin->w_height;
6930     }
6931     if (p_report < 0)
6932     {
6933 	errmsg = e_positive;
6934 	p_report = 1;
6935     }
6936     if ((p_sj < 0 || p_sj >= Rows) && full_screen)
6937     {
6938 	if (Rows != old_Rows)	/* Rows changed, just adjust p_sj */
6939 	    p_sj = Rows / 2;
6940 	else
6941 	{
6942 	    errmsg = e_scroll;
6943 	    p_sj = 1;
6944 	}
6945     }
6946     if (p_so < 0 && full_screen)
6947     {
6948 	errmsg = e_scroll;
6949 	p_so = 0;
6950     }
6951     if (p_siso < 0 && full_screen)
6952     {
6953 	errmsg = e_positive;
6954 	p_siso = 0;
6955     }
6956 #ifdef FEAT_CMDWIN
6957     if (p_cwh < 1)
6958     {
6959 	errmsg = e_positive;
6960 	p_cwh = 1;
6961     }
6962 #endif
6963     if (p_ut < 0)
6964     {
6965 	errmsg = e_positive;
6966 	p_ut = 2000;
6967     }
6968     if (p_ss < 0)
6969     {
6970 	errmsg = e_positive;
6971 	p_ss = 0;
6972     }
6973 
6974     /* May set global value for local option. */
6975     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6976 	*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
6977 
6978     options[opt_idx].flags |= P_WAS_SET;
6979 
6980     comp_col();			    /* in case 'columns' or 'ls' changed */
6981     if (curwin->w_curswant != MAXCOL)
6982 	curwin->w_set_curswant = TRUE;  /* in case 'tabstop' changed */
6983     check_redraw(options[opt_idx].flags);
6984 
6985     return errmsg;
6986 }
6987 
6988 /*
6989  * Called after an option changed: check if something needs to be redrawn.
6990  */
6991     static void
6992 check_redraw(flags)
6993     long_u	flags;
6994 {
6995     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
6996     int		clear = (flags & P_RCLR) == P_RCLR;
6997     int		all = ((flags & P_RALL) == P_RALL || clear);
6998 
6999 #ifdef FEAT_WINDOWS
7000     if ((flags & P_RSTAT) || all)	/* mark all status lines dirty */
7001 	status_redraw_all();
7002 #endif
7003 
7004     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
7005 	changed_window_setting();
7006     if (flags & P_RBUF)
7007 	redraw_curbuf_later(NOT_VALID);
7008     if (clear)
7009 	redraw_all_later(CLEAR);
7010     else if (all)
7011 	redraw_all_later(NOT_VALID);
7012 }
7013 
7014 /*
7015  * Find index for option 'arg'.
7016  * Return -1 if not found.
7017  */
7018     static int
7019 findoption(arg)
7020     char_u *arg;
7021 {
7022     int		    opt_idx;
7023     char	    *s, *p;
7024     static short    quick_tab[27] = {0, 0};	/* quick access table */
7025     int		    is_term_opt;
7026 
7027     /*
7028      * For first call: Initialize the quick-access table.
7029      * It contains the index for the first option that starts with a certain
7030      * letter.  There are 26 letters, plus the first "t_" option.
7031      */
7032     if (quick_tab[1] == 0)
7033     {
7034 	p = options[0].fullname;
7035 	for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7036 	{
7037 	    if (s[0] != p[0])
7038 	    {
7039 		if (s[0] == 't' && s[1] == '_')
7040 		    quick_tab[26] = opt_idx;
7041 		else
7042 		    quick_tab[CharOrdLow(s[0])] = opt_idx;
7043 	    }
7044 	    p = s;
7045 	}
7046     }
7047 
7048     /*
7049      * Check for name starting with an illegal character.
7050      */
7051 #ifdef EBCDIC
7052     if (!islower(arg[0]))
7053 #else
7054     if (arg[0] < 'a' || arg[0] > 'z')
7055 #endif
7056 	return -1;
7057 
7058     is_term_opt = (arg[0] == 't' && arg[1] == '_');
7059     if (is_term_opt)
7060 	opt_idx = quick_tab[26];
7061     else
7062 	opt_idx = quick_tab[CharOrdLow(arg[0])];
7063     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
7064     {
7065 	if (STRCMP(arg, s) == 0)		    /* match full name */
7066 	    break;
7067     }
7068     if (s == NULL && !is_term_opt)
7069     {
7070 	opt_idx = quick_tab[CharOrdLow(arg[0])];
7071 	for ( ; options[opt_idx].fullname != NULL; opt_idx++)
7072 	{
7073 	    s = options[opt_idx].shortname;
7074 	    if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
7075 		break;
7076 	    s = NULL;
7077 	}
7078     }
7079     if (s == NULL)
7080 	opt_idx = -1;
7081     return opt_idx;
7082 }
7083 
7084 #if defined(FEAT_EVAL) || defined(FEAT_TCL)
7085 /*
7086  * Get the value for an option.
7087  *
7088  * Returns:
7089  * Number or Toggle option: 1, *numval gets value.
7090  *	     String option: 0, *stringval gets allocated string.
7091  * Hidden Number or Toggle option: -1.
7092  *	     hidden String option: -2.
7093  *		   unknown option: -3.
7094  */
7095     int
7096 get_option_value(name, numval, stringval, opt_flags)
7097     char_u	*name;
7098     long	*numval;
7099     char_u	**stringval;	    /* NULL when only checking existance */
7100     int		opt_flags;
7101 {
7102     int		opt_idx;
7103     char_u	*varp;
7104 
7105     opt_idx = findoption(name);
7106     if (opt_idx < 0)		    /* unknown option */
7107 	return -3;
7108 
7109     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
7110 
7111     if (options[opt_idx].flags & P_STRING)
7112     {
7113 	if (varp == NULL)		    /* hidden option */
7114 	    return -2;
7115 	if (stringval != NULL)
7116 	{
7117 #ifdef FEAT_CRYPT
7118 	    /* never return the value of the crypt key */
7119 	    if ((char_u **)varp == &curbuf->b_p_key)
7120 		*stringval = vim_strsave((char_u *)"*****");
7121 	    else
7122 #endif
7123 		*stringval = vim_strsave(*(char_u **)(varp));
7124 	}
7125 	return 0;
7126     }
7127 
7128     if (varp == NULL)		    /* hidden option */
7129 	return -1;
7130     if (options[opt_idx].flags & P_NUM)
7131 	*numval = *(long *)varp;
7132     else
7133     {
7134 	/* Special case: 'modified' is b_changed, but we also want to consider
7135 	 * it set when 'ff' or 'fenc' changed. */
7136 	if ((int *)varp == &curbuf->b_changed)
7137 	    *numval = curbufIsChanged();
7138 	else
7139 	    *numval = *(int *)varp;
7140     }
7141     return 1;
7142 }
7143 #endif
7144 
7145 /*
7146  * Set the value of option "name".
7147  * Use "string" for string options, use "number" for other options.
7148  */
7149     void
7150 set_option_value(name, number, string, opt_flags)
7151     char_u	*name;
7152     long	number;
7153     char_u	*string;
7154     int		opt_flags;	/* OPT_LOCAL or 0 (both) */
7155 {
7156     int		opt_idx;
7157     char_u	*varp;
7158     int		flags;
7159 
7160     opt_idx = findoption(name);
7161     if (opt_idx == -1)
7162 	EMSG2(_("E355: Unknown option: %s"), name);
7163     else
7164     {
7165 	flags = options[opt_idx].flags;
7166 #ifdef HAVE_SANDBOX
7167 	/* Disallow changing some options in the sandbox */
7168 	if (sandbox > 0 && (flags & P_SECURE))
7169 	    EMSG(_(e_sandbox));
7170 	else
7171 #endif
7172 	  if (flags & P_STRING)
7173 	    set_string_option(opt_idx, string, opt_flags);
7174 	else
7175 	{
7176 	    varp = get_varp(&options[opt_idx]);
7177 	    if (varp != NULL)	/* hidden option is not changed */
7178 	    {
7179 		if (flags & P_NUM)
7180 		    (void)set_num_option(opt_idx, varp, number, NULL, opt_flags);
7181 		else
7182 		    (void)set_bool_option(opt_idx, varp, (int)number, opt_flags);
7183 	    }
7184 	}
7185     }
7186 }
7187 
7188 /*
7189  * Get the terminal code for a terminal option.
7190  * Returns NULL when not found.
7191  */
7192     char_u *
7193 get_term_code(tname)
7194     char_u	*tname;
7195 {
7196     int	    opt_idx;
7197     char_u  *varp;
7198 
7199     if (tname[0] != 't' || tname[1] != '_' ||
7200 	    tname[2] == NUL || tname[3] == NUL)
7201 	return NULL;
7202     if ((opt_idx = findoption(tname)) >= 0)
7203     {
7204 	varp = get_varp(&(options[opt_idx]));
7205 	if (varp != NULL)
7206 	    varp = *(char_u **)(varp);
7207 	return varp;
7208     }
7209     return find_termcode(tname + 2);
7210 }
7211 
7212     char_u *
7213 get_highlight_default()
7214 {
7215     int i;
7216 
7217     i = findoption((char_u *)"hl");
7218     if (i >= 0)
7219 	return options[i].def_val[VI_DEFAULT];
7220     return (char_u *)NULL;
7221 }
7222 
7223 /*
7224  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
7225  */
7226     static int
7227 find_key_option(arg)
7228     char_u *arg;
7229 {
7230     int		key;
7231     int		modifiers;
7232 
7233     /*
7234      * Don't use get_special_key_code() for t_xx, we don't want it to call
7235      * add_termcap_entry().
7236      */
7237     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
7238 	key = TERMCAP2KEY(arg[2], arg[3]);
7239     else
7240     {
7241 	--arg;			    /* put arg at the '<' */
7242 	modifiers = 0;
7243 	key = find_special_key(&arg, &modifiers, TRUE);
7244 	if (modifiers)		    /* can't handle modifiers here */
7245 	    key = 0;
7246     }
7247     return key;
7248 }
7249 
7250 /*
7251  * if 'all' == 0: show changed options
7252  * if 'all' == 1: show all normal options
7253  * if 'all' == 2: show all terminal options
7254  */
7255     static void
7256 showoptions(all, opt_flags)
7257     int		all;
7258     int		opt_flags;	/* OPT_LOCAL and/or OPT_GLOBAL */
7259 {
7260     struct vimoption	*p;
7261     int			col;
7262     int			isterm;
7263     char_u		*varp;
7264     struct vimoption	**items;
7265     int			item_count;
7266     int			run;
7267     int			row, rows;
7268     int			cols;
7269     int			i;
7270     int			len;
7271 
7272 #define INC 20
7273 #define GAP 3
7274 
7275     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
7276 								PARAM_COUNT));
7277     if (items == NULL)
7278 	return;
7279 
7280     /* Highlight title */
7281     if (all == 2)
7282 	MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
7283     else if (opt_flags & OPT_GLOBAL)
7284 	MSG_PUTS_TITLE(_("\n--- Global option values ---"));
7285     else if (opt_flags & OPT_LOCAL)
7286 	MSG_PUTS_TITLE(_("\n--- Local option values ---"));
7287     else
7288 	MSG_PUTS_TITLE(_("\n--- Options ---"));
7289 
7290     /*
7291      * do the loop two times:
7292      * 1. display the short items
7293      * 2. display the long items (only strings and numbers)
7294      */
7295     for (run = 1; run <= 2 && !got_int; ++run)
7296     {
7297 	/*
7298 	 * collect the items in items[]
7299 	 */
7300 	item_count = 0;
7301 	for (p = &options[0]; p->fullname != NULL; p++)
7302 	{
7303 	    varp = NULL;
7304 	    isterm = istermoption(p);
7305 	    if (opt_flags != 0)
7306 	    {
7307 		if (p->indir != PV_NONE && !isterm)
7308 		    varp = get_varp_scope(p, opt_flags);
7309 	    }
7310 	    else
7311 		varp = get_varp(p);
7312 	    if (varp != NULL
7313 		    && ((all == 2 && isterm)
7314 			|| (all == 1 && !isterm)
7315 			|| (all == 0 && !optval_default(p, varp))))
7316 	    {
7317 		if (p->flags & P_BOOL)
7318 		    len = 1;		/* a toggle option fits always */
7319 		else
7320 		{
7321 		    option_value2string(p, opt_flags);
7322 		    len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
7323 		}
7324 		if ((len <= INC - GAP && run == 1) ||
7325 						(len > INC - GAP && run == 2))
7326 		    items[item_count++] = p;
7327 	    }
7328 	}
7329 
7330 	/*
7331 	 * display the items
7332 	 */
7333 	if (run == 1)
7334 	{
7335 	    cols = (Columns + GAP - 3) / INC;
7336 	    if (cols == 0)
7337 		cols = 1;
7338 	    rows = (item_count + cols - 1) / cols;
7339 	}
7340 	else	/* run == 2 */
7341 	    rows = item_count;
7342 	for (row = 0; row < rows && !got_int; ++row)
7343 	{
7344 	    msg_putchar('\n');			/* go to next line */
7345 	    if (got_int)			/* 'q' typed in more */
7346 		break;
7347 	    col = 0;
7348 	    for (i = row; i < item_count; i += rows)
7349 	    {
7350 		msg_col = col;			/* make columns */
7351 		showoneopt(items[i], opt_flags);
7352 		col += INC;
7353 	    }
7354 	    out_flush();
7355 	    ui_breakcheck();
7356 	}
7357     }
7358     vim_free(items);
7359 }
7360 
7361 /*
7362  * Return TRUE if option "p" has its default value.
7363  */
7364     static int
7365 optval_default(p, varp)
7366     struct vimoption	*p;
7367     char_u		*varp;
7368 {
7369     int		dvi;
7370 
7371     if (varp == NULL)
7372 	return TRUE;	    /* hidden option is always at default */
7373     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
7374     if (p->flags & P_NUM)
7375 	return (*(long *)varp == (long)p->def_val[dvi]);
7376     if (p->flags & P_BOOL)
7377 			/* the cast to long is required for Manx C */
7378 	return (*(int *)varp == (int)(long)p->def_val[dvi]);
7379     /* P_STRING */
7380     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
7381 }
7382 
7383 /*
7384  * showoneopt: show the value of one option
7385  * must not be called with a hidden option!
7386  */
7387     static void
7388 showoneopt(p, opt_flags)
7389     struct vimoption	*p;
7390     int			opt_flags;	/* OPT_LOCAL or OPT_GLOBAL */
7391 {
7392     char_u		*varp;
7393 
7394     varp = get_varp_scope(p, opt_flags);
7395 
7396     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
7397     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
7398 					? !curbufIsChanged() : !*(int *)varp))
7399 	MSG_PUTS("no");
7400     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
7401 	MSG_PUTS("--");
7402     else
7403 	MSG_PUTS("  ");
7404     MSG_PUTS(p->fullname);
7405     if (!(p->flags & P_BOOL))
7406     {
7407 	msg_putchar('=');
7408 	/* put value string in NameBuff */
7409 	option_value2string(p, opt_flags);
7410 	msg_outtrans(NameBuff);
7411     }
7412 }
7413 
7414 /*
7415  * Write modified options as ":set" commands to a file.
7416  *
7417  * There are three values for "opt_flags":
7418  * OPT_GLOBAL:		   Write global option values and fresh values of
7419  *			   buffer-local options (used for start of a session
7420  *			   file).
7421  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
7422  *			   curwin (used for a vimrc file).
7423  * OPT_LOCAL:		   Write buffer-local option values for curbuf, fresh
7424  *			   and local values for window-local options of
7425  *			   curwin.  Local values are also written when at the
7426  *			   default value, because a modeline or autocommand
7427  *			   may have set them when doing ":edit file" and the
7428  *			   user has set them back at the default or fresh
7429  *			   value.
7430  *			   When "local_only" is TRUE, don't write fresh
7431  *			   values, only local values (for ":mkview").
7432  * (fresh value = value used for a new buffer or window for a local option).
7433  *
7434  * Return FAIL on error, OK otherwise.
7435  */
7436     int
7437 makeset(fd, opt_flags, local_only)
7438     FILE	*fd;
7439     int		opt_flags;
7440     int		local_only;
7441 {
7442     struct vimoption	*p;
7443     char_u		*varp;			/* currently used value */
7444     char_u		*varp_fresh;		/* local value */
7445     char_u		*varp_local = NULL;	/* fresh value */
7446     char		*cmd;
7447     int			round;
7448 
7449     /*
7450      * The options that don't have a default (terminal name, columns, lines)
7451      * are never written.  Terminal options are also not written.
7452      */
7453     for (p = &options[0]; !istermoption(p); p++)
7454 	if (!(p->flags & P_NO_MKRC) && !istermoption(p))
7455 	{
7456 	    /* skip global option when only doing locals */
7457 	    if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
7458 		continue;
7459 
7460 	    /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
7461 	     * file, they are always buffer-specific. */
7462 	    if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
7463 		continue;
7464 
7465 	    /* Global values are only written when not at the default value. */
7466 	    varp = get_varp_scope(p, opt_flags);
7467 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
7468 		continue;
7469 
7470 	    round = 2;
7471 	    if (p->indir != PV_NONE)
7472 	    {
7473 		if (p->var == VAR_WIN)
7474 		{
7475 		    /* skip window-local option when only doing globals */
7476 		    if (!(opt_flags & OPT_LOCAL))
7477 			continue;
7478 		    /* When fresh value of window-local option is not at the
7479 		     * default, need to write it too. */
7480 		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
7481 		    {
7482 			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
7483 			if (!optval_default(p, varp_fresh))
7484 			{
7485 			    round = 1;
7486 			    varp_local = varp;
7487 			    varp = varp_fresh;
7488 			}
7489 		    }
7490 		}
7491 	    }
7492 
7493 	    /* Round 1: fresh value for window-local options.
7494 	     * Round 2: other values */
7495 	    for ( ; round <= 2; varp = varp_local, ++round)
7496 	    {
7497 		if (round == 1 || (opt_flags & OPT_GLOBAL))
7498 		    cmd = "set";
7499 		else
7500 		    cmd = "setlocal";
7501 
7502 		if (p->flags & P_BOOL)
7503 		{
7504 		    if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
7505 			return FAIL;
7506 		}
7507 		else if (p->flags & P_NUM)
7508 		{
7509 		    if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
7510 			return FAIL;
7511 		}
7512 		else    /* P_STRING */
7513 		{
7514 		    /* Don't set 'syntax' and 'filetype' again if the value is
7515 		     * already right, avoids reloading the syntax file. */
7516 		    if (p->indir == PV_SYN || p->indir == PV_FT)
7517 		    {
7518 			if (fprintf(fd, "if &%s != '%s'", p->fullname,
7519 						       *(char_u **)(varp)) < 0
7520 				|| put_eol(fd) < 0)
7521 			    return FAIL;
7522 		    }
7523 		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
7524 					  (p->flags & P_EXPAND) != 0) == FAIL)
7525 			return FAIL;
7526 		    if (p->indir == PV_SYN || p->indir == PV_FT)
7527 		    {
7528 			if (put_line(fd, "endif") == FAIL)
7529 			    return FAIL;
7530 		    }
7531 		}
7532 	    }
7533 	}
7534     return OK;
7535 }
7536 
7537 #if defined(FEAT_FOLDING) || defined(PROTO)
7538 /*
7539  * Generate set commands for the local fold options only.  Used when
7540  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
7541  */
7542     int
7543 makefoldset(fd)
7544     FILE	*fd;
7545 {
7546     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
7547 # ifdef FEAT_EVAL
7548 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
7549 								       == FAIL
7550 # endif
7551 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
7552 								       == FAIL
7553 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
7554 								       == FAIL
7555 	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
7556 	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
7557 	    || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
7558 	    || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
7559 	    )
7560 	return FAIL;
7561 
7562     return OK;
7563 }
7564 #endif
7565 
7566     static int
7567 put_setstring(fd, cmd, name, valuep, expand)
7568     FILE	*fd;
7569     char	*cmd;
7570     char	*name;
7571     char_u	**valuep;
7572     int		expand;
7573 {
7574     char_u	*s;
7575     char_u	buf[MAXPATHL];
7576 
7577     if (fprintf(fd, "%s %s=", cmd, name) < 0)
7578 	return FAIL;
7579     if (*valuep != NULL)
7580     {
7581 	/* Output 'pastetoggle' as key names.  For other
7582 	 * options some characters have to be escaped with
7583 	 * CTRL-V or backslash */
7584 	if (valuep == &p_pt)
7585 	{
7586 	    s = *valuep;
7587 	    while (*s != NUL)
7588 		if (fputs((char *)str2special(&s, FALSE), fd) < 0)
7589 		    return FAIL;
7590 	}
7591 	else if (expand)
7592 	{
7593 	    home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
7594 	    if (put_escstr(fd, buf, 2) == FAIL)
7595 		return FAIL;
7596 	}
7597 	else if (put_escstr(fd, *valuep, 2) == FAIL)
7598 	    return FAIL;
7599     }
7600     if (put_eol(fd) < 0)
7601 	return FAIL;
7602     return OK;
7603 }
7604 
7605     static int
7606 put_setnum(fd, cmd, name, valuep)
7607     FILE	*fd;
7608     char	*cmd;
7609     char	*name;
7610     long	*valuep;
7611 {
7612     long	wc;
7613 
7614     if (fprintf(fd, "%s %s=", cmd, name) < 0)
7615 	return FAIL;
7616     if (wc_use_keyname((char_u *)valuep, &wc))
7617     {
7618 	/* print 'wildchar' and 'wildcharm' as a key name */
7619 	if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
7620 	    return FAIL;
7621     }
7622     else if (fprintf(fd, "%ld", *valuep) < 0)
7623 	return FAIL;
7624     if (put_eol(fd) < 0)
7625 	return FAIL;
7626     return OK;
7627 }
7628 
7629     static int
7630 put_setbool(fd, cmd, name, value)
7631     FILE	*fd;
7632     char	*cmd;
7633     char	*name;
7634     int		value;
7635 {
7636     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
7637 	    || put_eol(fd) < 0)
7638 	return FAIL;
7639     return OK;
7640 }
7641 
7642 /*
7643  * Clear all the terminal options.
7644  * If the option has been allocated, free the memory.
7645  * Terminal options are never hidden or indirect.
7646  */
7647     void
7648 clear_termoptions()
7649 {
7650     struct vimoption   *p;
7651 
7652     /*
7653      * Reset a few things before clearing the old options. This may cause
7654      * outputting a few things that the terminal doesn't understand, but the
7655      * screen will be cleared later, so this is OK.
7656      */
7657 #ifdef FEAT_MOUSE_TTY
7658     mch_setmouse(FALSE);	    /* switch mouse off */
7659 #endif
7660 #ifdef FEAT_TITLE
7661     mch_restore_title(3);	    /* restore window titles */
7662 #endif
7663 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
7664     /* When starting the GUI close the display opened for the clipboard.
7665      * After restoring the title, because that will need the display. */
7666     if (gui.starting)
7667 	clear_xterm_clip();
7668 #endif
7669 #ifdef WIN3264
7670     /*
7671      * Check if this is allowed now.
7672      */
7673     if (can_end_termcap_mode(FALSE) == TRUE)
7674 #endif
7675 	stoptermcap();			/* stop termcap mode */
7676 
7677     for (p = &options[0]; p->fullname != NULL; p++)
7678 	if (istermoption(p))
7679 	{
7680 	    if (p->flags & P_ALLOCED)
7681 		free_string_option(*(char_u **)(p->var));
7682 	    if (p->flags & P_DEF_ALLOCED)
7683 		free_string_option(p->def_val[VI_DEFAULT]);
7684 	    *(char_u **)(p->var) = empty_option;
7685 	    p->def_val[VI_DEFAULT] = empty_option;
7686 	    p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
7687 	}
7688     clear_termcodes();
7689 }
7690 
7691 /*
7692  * Set the terminal option defaults to the current value.
7693  * Used after setting the terminal name.
7694  */
7695     void
7696 set_term_defaults()
7697 {
7698     struct vimoption   *p;
7699 
7700     for (p = &options[0]; p->fullname != NULL; p++)
7701     {
7702 	if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
7703 	{
7704 	    if (p->flags & P_DEF_ALLOCED)
7705 	    {
7706 		free_string_option(p->def_val[VI_DEFAULT]);
7707 		p->flags &= ~P_DEF_ALLOCED;
7708 	    }
7709 	    p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
7710 	    if (p->flags & P_ALLOCED)
7711 	    {
7712 		p->flags |= P_DEF_ALLOCED;
7713 		p->flags &= ~P_ALLOCED;	 /* don't free the value now */
7714 	    }
7715 	}
7716     }
7717 }
7718 
7719 /*
7720  * return TRUE if 'p' starts with 't_'
7721  */
7722     static int
7723 istermoption(p)
7724     struct vimoption *p;
7725 {
7726     return (p->fullname[0] == 't' && p->fullname[1] == '_');
7727 }
7728 
7729 /*
7730  * Compute columns for ruler and shown command. 'sc_col' is also used to
7731  * decide what the maximum length of a message on the status line can be.
7732  * If there is a status line for the last window, 'sc_col' is independent
7733  * of 'ru_col'.
7734  */
7735 
7736 #define COL_RULER 17	    /* columns needed by standard ruler */
7737 
7738     void
7739 comp_col()
7740 {
7741 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
7742     int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
7743 
7744     sc_col = 0;
7745     ru_col = 0;
7746     if (p_ru)
7747     {
7748 #ifdef FEAT_STL_OPT
7749 	ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
7750 #else
7751 	ru_col = COL_RULER + 1;
7752 #endif
7753 	/* no last status line, adjust sc_col */
7754 	if (!last_has_status)
7755 	    sc_col = ru_col;
7756     }
7757     if (p_sc)
7758     {
7759 	sc_col += SHOWCMD_COLS;
7760 	if (!p_ru || last_has_status)	    /* no need for separating space */
7761 	    ++sc_col;
7762     }
7763     sc_col = Columns - sc_col;
7764     ru_col = Columns - ru_col;
7765     if (sc_col <= 0)		/* screen too narrow, will become a mess */
7766 	sc_col = 1;
7767     if (ru_col <= 0)
7768 	ru_col = 1;
7769 #else
7770     sc_col = Columns;
7771     ru_col = Columns;
7772 #endif
7773 }
7774 
7775 /*
7776  * Get pointer to option variable, depending on local or global scope.
7777  */
7778     static char_u *
7779 get_varp_scope(p, opt_flags)
7780     struct vimoption	*p;
7781     int			opt_flags;
7782 {
7783     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
7784     {
7785 	if (p->var == VAR_WIN)
7786 	    return (char_u *)GLOBAL_WO(get_varp(p));
7787 	return p->var;
7788     }
7789     if ((opt_flags & OPT_LOCAL) && (int)p->indir >= PV_BOTH)
7790     {
7791 	switch ((int)p->indir)
7792 	{
7793 #ifdef FEAT_QUICKFIX
7794 	    case OPT_BOTH(PV_GP):   return (char_u *)&(curbuf->b_p_gp);
7795 	    case OPT_BOTH(PV_MP):   return (char_u *)&(curbuf->b_p_mp);
7796 	    case OPT_BOTH(PV_EFM):  return (char_u *)&(curbuf->b_p_efm);
7797 #endif
7798 	    case OPT_BOTH(PV_EP):   return (char_u *)&(curbuf->b_p_ep);
7799 	    case OPT_BOTH(PV_KP):   return (char_u *)&(curbuf->b_p_kp);
7800 	    case OPT_BOTH(PV_PATH): return (char_u *)&(curbuf->b_p_path);
7801 	    case OPT_BOTH(PV_AR):   return (char_u *)&(curbuf->b_p_ar);
7802 	    case OPT_BOTH(PV_TAGS): return (char_u *)&(curbuf->b_p_tags);
7803 #ifdef FEAT_FIND_ID
7804 	    case OPT_BOTH(PV_DEF):  return (char_u *)&(curbuf->b_p_def);
7805 	    case OPT_BOTH(PV_INC):  return (char_u *)&(curbuf->b_p_inc);
7806 #endif
7807 #ifdef FEAT_INS_EXPAND
7808 	    case OPT_BOTH(PV_DICT): return (char_u *)&(curbuf->b_p_dict);
7809 	    case OPT_BOTH(PV_TSR):  return (char_u *)&(curbuf->b_p_tsr);
7810 #endif
7811 	}
7812 	return NULL; /* "cannot happen" */
7813     }
7814     return get_varp(p);
7815 }
7816 
7817 /*
7818  * Get pointer to option variable.
7819  */
7820     static char_u *
7821 get_varp(p)
7822     struct vimoption	*p;
7823 {
7824     /* hidden option, always return NULL */
7825     if (p->var == NULL)
7826 	return NULL;
7827 
7828     switch ((int)p->indir)
7829     {
7830 	case PV_NONE:	return p->var;
7831 
7832 	/* global option with local value: use local value if it's been set */
7833 	case OPT_BOTH(PV_EP):	return *curbuf->b_p_ep != NUL
7834 				    ? (char_u *)&curbuf->b_p_ep : p->var;
7835 	case OPT_BOTH(PV_KP):	return *curbuf->b_p_kp != NUL
7836 				    ? (char_u *)&curbuf->b_p_kp : p->var;
7837 	case OPT_BOTH(PV_PATH):	return *curbuf->b_p_path != NUL
7838 				    ? (char_u *)&(curbuf->b_p_path) : p->var;
7839 	case OPT_BOTH(PV_AR):	return curbuf->b_p_ar >= 0
7840 				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
7841 	case OPT_BOTH(PV_TAGS):	return *curbuf->b_p_tags != NUL
7842 				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
7843 #ifdef FEAT_FIND_ID
7844 	case OPT_BOTH(PV_DEF):	return *curbuf->b_p_def != NUL
7845 				    ? (char_u *)&(curbuf->b_p_def) : p->var;
7846 	case OPT_BOTH(PV_INC):	return *curbuf->b_p_inc != NUL
7847 				    ? (char_u *)&(curbuf->b_p_inc) : p->var;
7848 #endif
7849 #ifdef FEAT_INS_EXPAND
7850 	case OPT_BOTH(PV_DICT):	return *curbuf->b_p_dict != NUL
7851 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
7852 	case OPT_BOTH(PV_TSR):	return *curbuf->b_p_tsr != NUL
7853 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
7854 #endif
7855 #ifdef FEAT_QUICKFIX
7856 	case OPT_BOTH(PV_GP):	return *curbuf->b_p_gp != NUL
7857 				    ? (char_u *)&(curbuf->b_p_gp) : p->var;
7858 	case OPT_BOTH(PV_MP):	return *curbuf->b_p_mp != NUL
7859 				    ? (char_u *)&(curbuf->b_p_mp) : p->var;
7860 	case OPT_BOTH(PV_EFM):	return *curbuf->b_p_efm != NUL
7861 				    ? (char_u *)&(curbuf->b_p_efm) : p->var;
7862 #endif
7863 
7864 #ifdef FEAT_ARABIC
7865 	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
7866 #endif
7867 	case PV_LIST:	return (char_u *)&(curwin->w_p_list);
7868 #ifdef FEAT_DIFF
7869 	case PV_DIFF:	return (char_u *)&(curwin->w_p_diff);
7870 #endif
7871 #ifdef FEAT_FOLDING
7872 	case PV_FDC:	return (char_u *)&(curwin->w_p_fdc);
7873 	case PV_FEN:	return (char_u *)&(curwin->w_p_fen);
7874 	case PV_FDI:	return (char_u *)&(curwin->w_p_fdi);
7875 	case PV_FDL:	return (char_u *)&(curwin->w_p_fdl);
7876 	case PV_FDM:	return (char_u *)&(curwin->w_p_fdm);
7877 	case PV_FML:	return (char_u *)&(curwin->w_p_fml);
7878 	case PV_FDN:	return (char_u *)&(curwin->w_p_fdn);
7879 # ifdef FEAT_EVAL
7880 	case PV_FDE:	return (char_u *)&(curwin->w_p_fde);
7881 	case PV_FDT:	return (char_u *)&(curwin->w_p_fdt);
7882 # endif
7883 	case PV_FMR:	return (char_u *)&(curwin->w_p_fmr);
7884 #endif
7885 	case PV_NU:	return (char_u *)&(curwin->w_p_nu);
7886 #ifdef FEAT_LINEBREAK
7887 	case PV_NUW:	return (char_u *)&(curwin->w_p_nuw);
7888 #endif
7889 #if defined(FEAT_WINDOWS)
7890 	case PV_WFH:	return (char_u *)&(curwin->w_p_wfh);
7891 #endif
7892 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7893 	case PV_PVW:	return (char_u *)&(curwin->w_p_pvw);
7894 #endif
7895 #ifdef FEAT_RIGHTLEFT
7896 	case PV_RL:	return (char_u *)&(curwin->w_p_rl);
7897 	case PV_RLC:	return (char_u *)&(curwin->w_p_rlc);
7898 #endif
7899 	case PV_SCROLL:	return (char_u *)&(curwin->w_p_scr);
7900 	case PV_WRAP:	return (char_u *)&(curwin->w_p_wrap);
7901 #ifdef FEAT_LINEBREAK
7902 	case PV_LBR:	return (char_u *)&(curwin->w_p_lbr);
7903 #endif
7904 #ifdef FEAT_SCROLLBIND
7905 	case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
7906 #endif
7907 
7908 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
7909 	case PV_BIN:	return (char_u *)&(curbuf->b_p_bin);
7910 #ifdef FEAT_MBYTE
7911 	case PV_BOMB:	return (char_u *)&(curbuf->b_p_bomb);
7912 #endif
7913 #if defined(FEAT_QUICKFIX)
7914 	case PV_BH:	return (char_u *)&(curbuf->b_p_bh);
7915 	case PV_BT:	return (char_u *)&(curbuf->b_p_bt);
7916 #endif
7917 	case PV_BL:	return (char_u *)&(curbuf->b_p_bl);
7918 	case PV_CI:	return (char_u *)&(curbuf->b_p_ci);
7919 #ifdef FEAT_CINDENT
7920 	case PV_CIN:	return (char_u *)&(curbuf->b_p_cin);
7921 	case PV_CINK:	return (char_u *)&(curbuf->b_p_cink);
7922 	case PV_CINO:	return (char_u *)&(curbuf->b_p_cino);
7923 #endif
7924 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
7925 	case PV_CINW:	return (char_u *)&(curbuf->b_p_cinw);
7926 #endif
7927 #ifdef FEAT_COMMENTS
7928 	case PV_COM:	return (char_u *)&(curbuf->b_p_com);
7929 #endif
7930 #ifdef FEAT_FOLDING
7931 	case PV_CMS:	return (char_u *)&(curbuf->b_p_cms);
7932 #endif
7933 #ifdef FEAT_INS_EXPAND
7934 	case PV_CPT:	return (char_u *)&(curbuf->b_p_cpt);
7935 #endif
7936 #ifdef FEAT_COMPL_FUNC
7937 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
7938 #endif
7939 	case PV_EOL:	return (char_u *)&(curbuf->b_p_eol);
7940 	case PV_ET:	return (char_u *)&(curbuf->b_p_et);
7941 #ifdef FEAT_MBYTE
7942 	case PV_FENC:	return (char_u *)&(curbuf->b_p_fenc);
7943 #endif
7944 	case PV_FF:	return (char_u *)&(curbuf->b_p_ff);
7945 #ifdef FEAT_AUTOCMD
7946 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
7947 #endif
7948 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
7949 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
7950 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
7951 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
7952 	case PV_ISK:	return (char_u *)&(curbuf->b_p_isk);
7953 #ifdef FEAT_FIND_ID
7954 # ifdef FEAT_EVAL
7955 	case PV_INEX:	return (char_u *)&(curbuf->b_p_inex);
7956 # endif
7957 #endif
7958 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
7959 	case PV_INDE:	return (char_u *)&(curbuf->b_p_inde);
7960 	case PV_INDK:	return (char_u *)&(curbuf->b_p_indk);
7961 #endif
7962 #ifdef FEAT_CRYPT
7963 	case PV_KEY:	return (char_u *)&(curbuf->b_p_key);
7964 #endif
7965 #ifdef FEAT_LISP
7966 	case PV_LISP:	return (char_u *)&(curbuf->b_p_lisp);
7967 #endif
7968 	case PV_ML:	return (char_u *)&(curbuf->b_p_ml);
7969 	case PV_MPS:	return (char_u *)&(curbuf->b_p_mps);
7970 	case PV_MA:	return (char_u *)&(curbuf->b_p_ma);
7971 	case PV_MOD:	return (char_u *)&(curbuf->b_changed);
7972 	case PV_NF:	return (char_u *)&(curbuf->b_p_nf);
7973 #ifdef FEAT_OSFILETYPE
7974 	case PV_OFT:	return (char_u *)&(curbuf->b_p_oft);
7975 #endif
7976 	case PV_PI:	return (char_u *)&(curbuf->b_p_pi);
7977 #ifdef FEAT_TEXTOBJ
7978 	case PV_QE:	return (char_u *)&(curbuf->b_p_qe);
7979 #endif
7980 	case PV_RO:	return (char_u *)&(curbuf->b_p_ro);
7981 #ifdef FEAT_SMARTINDENT
7982 	case PV_SI:	return (char_u *)&(curbuf->b_p_si);
7983 #endif
7984 #ifndef SHORT_FNAME
7985 	case PV_SN:	return (char_u *)&(curbuf->b_p_sn);
7986 #endif
7987 	case PV_STS:	return (char_u *)&(curbuf->b_p_sts);
7988 #ifdef FEAT_SEARCHPATH
7989 	case PV_SUA:	return (char_u *)&(curbuf->b_p_sua);
7990 #endif
7991 	case PV_SWF:	return (char_u *)&(curbuf->b_p_swf);
7992 #ifdef FEAT_SYN_HL
7993 	case PV_SYN:	return (char_u *)&(curbuf->b_p_syn);
7994 #endif
7995 	case PV_SW:	return (char_u *)&(curbuf->b_p_sw);
7996 	case PV_TS:	return (char_u *)&(curbuf->b_p_ts);
7997 	case PV_TW:	return (char_u *)&(curbuf->b_p_tw);
7998 	case PV_TX:	return (char_u *)&(curbuf->b_p_tx);
7999 	case PV_WM:	return (char_u *)&(curbuf->b_p_wm);
8000 #ifdef FEAT_KEYMAP
8001 	case PV_KMAP:	return (char_u *)&(curbuf->b_p_keymap);
8002 #endif
8003 	default:	EMSG(_("E356: get_varp ERROR"));
8004     }
8005     /* always return a valid pointer to avoid a crash! */
8006     return (char_u *)&(curbuf->b_p_wm);
8007 }
8008 
8009 /*
8010  * Get the value of 'equalprg', either the buffer-local one or the global one.
8011  */
8012     char_u *
8013 get_equalprg()
8014 {
8015     if (*curbuf->b_p_ep == NUL)
8016 	return p_ep;
8017     return curbuf->b_p_ep;
8018 }
8019 
8020 #if defined(FEAT_WINDOWS) || defined(PROTO)
8021 /*
8022  * Copy options from one window to another.
8023  * Used when splitting a window.
8024  */
8025     void
8026 win_copy_options(wp_from, wp_to)
8027     win_T	*wp_from;
8028     win_T	*wp_to;
8029 {
8030     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
8031     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
8032 # ifdef FEAT_RIGHTLEFT
8033 #  ifdef FEAT_FKMAP
8034     /* Is this right? */
8035     wp_to->w_farsi = wp_from->w_farsi;
8036 #  endif
8037 # endif
8038 }
8039 #endif
8040 
8041 /*
8042  * Copy the options from one winopt_T to another.
8043  * Doesn't free the old option values in "to", use clear_winopt() for that.
8044  * The 'scroll' option is not copied, because it depends on the window height.
8045  * The 'previewwindow' option is reset, there can be only one preview window.
8046  */
8047     void
8048 copy_winopt(from, to)
8049     winopt_T	*from;
8050     winopt_T	*to;
8051 {
8052 #ifdef FEAT_ARABIC
8053     to->wo_arab = from->wo_arab;
8054 #endif
8055     to->wo_list = from->wo_list;
8056     to->wo_nu = from->wo_nu;
8057 #ifdef FEAT_LINEBREAK
8058     to->wo_nuw = from->wo_nuw;
8059 #endif
8060 #ifdef FEAT_RIGHTLEFT
8061     to->wo_rl  = from->wo_rl;
8062     to->wo_rlc = vim_strsave(from->wo_rlc);
8063 #endif
8064     to->wo_wrap = from->wo_wrap;
8065 #ifdef FEAT_LINEBREAK
8066     to->wo_lbr = from->wo_lbr;
8067 #endif
8068 #ifdef FEAT_SCROLLBIND
8069     to->wo_scb = from->wo_scb;
8070 #endif
8071 #ifdef FEAT_DIFF
8072     to->wo_diff = from->wo_diff;
8073 #endif
8074 #ifdef FEAT_FOLDING
8075     to->wo_fdc = from->wo_fdc;
8076     to->wo_fen = from->wo_fen;
8077     to->wo_fdi = vim_strsave(from->wo_fdi);
8078     to->wo_fml = from->wo_fml;
8079     to->wo_fdl = from->wo_fdl;
8080     to->wo_fdm = vim_strsave(from->wo_fdm);
8081     to->wo_fdn = from->wo_fdn;
8082 # ifdef FEAT_EVAL
8083     to->wo_fde = vim_strsave(from->wo_fde);
8084     to->wo_fdt = vim_strsave(from->wo_fdt);
8085 # endif
8086     to->wo_fmr = vim_strsave(from->wo_fmr);
8087 #endif
8088     check_winopt(to);		/* don't want NULL pointers */
8089 }
8090 
8091 /*
8092  * Check string options in a window for a NULL value.
8093  */
8094     void
8095 check_win_options(win)
8096     win_T	*win;
8097 {
8098     check_winopt(&win->w_onebuf_opt);
8099     check_winopt(&win->w_allbuf_opt);
8100 }
8101 
8102 /*
8103  * Check for NULL pointers in a winopt_T and replace them with empty_option.
8104  */
8105 /*ARGSUSED*/
8106     void
8107 check_winopt(wop)
8108     winopt_T	*wop;
8109 {
8110 #ifdef FEAT_FOLDING
8111     check_string_option(&wop->wo_fdi);
8112     check_string_option(&wop->wo_fdm);
8113 # ifdef FEAT_EVAL
8114     check_string_option(&wop->wo_fde);
8115     check_string_option(&wop->wo_fdt);
8116 # endif
8117     check_string_option(&wop->wo_fmr);
8118 #endif
8119 #ifdef FEAT_RIGHTLEFT
8120     check_string_option(&wop->wo_rlc);
8121 #endif
8122 }
8123 
8124 /*
8125  * Free the allocated memory inside a winopt_T.
8126  */
8127 /*ARGSUSED*/
8128     void
8129 clear_winopt(wop)
8130     winopt_T	*wop;
8131 {
8132 #ifdef FEAT_FOLDING
8133     clear_string_option(&wop->wo_fdi);
8134     clear_string_option(&wop->wo_fdm);
8135 # ifdef FEAT_EVAL
8136     clear_string_option(&wop->wo_fde);
8137     clear_string_option(&wop->wo_fdt);
8138 # endif
8139     clear_string_option(&wop->wo_fmr);
8140 #endif
8141 #ifdef FEAT_RIGHTLEFT
8142     clear_string_option(&wop->wo_rlc);
8143 #endif
8144 }
8145 
8146 /*
8147  * Copy global option values to local options for one buffer.
8148  * Used when creating a new buffer and sometimes when entering a buffer.
8149  * flags:
8150  * BCO_ENTER	We will enter the buf buffer.
8151  * BCO_ALWAYS	Always copy the options, but only set b_p_initialized when
8152  *		appropriate.
8153  * BCO_NOHELP	Don't copy the values to a help buffer.
8154  */
8155     void
8156 buf_copy_options(buf, flags)
8157     buf_T	*buf;
8158     int		flags;
8159 {
8160     int		should_copy = TRUE;
8161     char_u	*save_p_isk = NULL;	    /* init for GCC */
8162     int		dont_do_help;
8163     int		did_isk = FALSE;
8164 
8165     /*
8166      * Don't do anything of the buffer is invalid.
8167      */
8168     if (buf == NULL || !buf_valid(buf))
8169 	return;
8170 
8171     /*
8172      * Skip this when the option defaults have not been set yet.  Happens when
8173      * main() allocates the first buffer.
8174      */
8175     if (p_cpo != NULL)
8176     {
8177 	/*
8178 	 * Always copy when entering and 'cpo' contains 'S'.
8179 	 * Don't copy when already initialized.
8180 	 * Don't copy when 'cpo' contains 's' and not entering.
8181 	 * 'S'	BCO_ENTER  initialized	's'  should_copy
8182 	 * yes	  yes	       X	 X	TRUE
8183 	 * yes	  no	      yes	 X	FALSE
8184 	 * no	   X	      yes	 X	FALSE
8185 	 *  X	  no	      no	yes	FALSE
8186 	 *  X	  no	      no	no	TRUE
8187 	 * no	  yes	      no	 X	TRUE
8188 	 */
8189 	if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
8190 		&& (buf->b_p_initialized
8191 		    || (!(flags & BCO_ENTER)
8192 			&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
8193 	    should_copy = FALSE;
8194 
8195 	if (should_copy || (flags & BCO_ALWAYS))
8196 	{
8197 	    /* Don't copy the options specific to a help buffer when
8198 	     * BCO_NOHELP is given or the options were initialized already
8199 	     * (jumping back to a help file with CTRL-T or CTRL-O) */
8200 	    dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
8201 						       || buf->b_p_initialized;
8202 	    if (dont_do_help)		/* don't free b_p_isk */
8203 	    {
8204 		save_p_isk = buf->b_p_isk;
8205 		buf->b_p_isk = NULL;
8206 	    }
8207 	    /*
8208 	     * Always free the allocated strings.
8209 	     * If not already initialized, set 'readonly' and copy 'fileformat'.
8210 	     */
8211 	    if (!buf->b_p_initialized)
8212 	    {
8213 		free_buf_options(buf, TRUE);
8214 		buf->b_p_ro = FALSE;		/* don't copy readonly */
8215 		buf->b_p_tx = p_tx;
8216 #ifdef FEAT_MBYTE
8217 		buf->b_p_fenc = vim_strsave(p_fenc);
8218 #endif
8219 		buf->b_p_ff = vim_strsave(p_ff);
8220 #if defined(FEAT_QUICKFIX)
8221 		buf->b_p_bh = empty_option;
8222 		buf->b_p_bt = empty_option;
8223 #endif
8224 	    }
8225 	    else
8226 		free_buf_options(buf, FALSE);
8227 
8228 	    buf->b_p_ai = p_ai;
8229 	    buf->b_p_ai_nopaste = p_ai_nopaste;
8230 	    buf->b_p_sw = p_sw;
8231 	    buf->b_p_tw = p_tw;
8232 	    buf->b_p_tw_nopaste = p_tw_nopaste;
8233 	    buf->b_p_tw_nobin = p_tw_nobin;
8234 	    buf->b_p_wm = p_wm;
8235 	    buf->b_p_wm_nopaste = p_wm_nopaste;
8236 	    buf->b_p_wm_nobin = p_wm_nobin;
8237 	    buf->b_p_bin = p_bin;
8238 	    buf->b_p_et = p_et;
8239 	    buf->b_p_et_nobin = p_et_nobin;
8240 	    buf->b_p_ml = p_ml;
8241 	    buf->b_p_ml_nobin = p_ml_nobin;
8242 	    buf->b_p_inf = p_inf;
8243 	    buf->b_p_swf = p_swf;
8244 #ifdef FEAT_INS_EXPAND
8245 	    buf->b_p_cpt = vim_strsave(p_cpt);
8246 #endif
8247 #ifdef FEAT_COMPL_FUNC
8248 	    buf->b_p_cfu = vim_strsave(p_cfu);
8249 #endif
8250 	    buf->b_p_sts = p_sts;
8251 	    buf->b_p_sts_nopaste = p_sts_nopaste;
8252 #ifndef SHORT_FNAME
8253 	    buf->b_p_sn = p_sn;
8254 #endif
8255 #ifdef FEAT_COMMENTS
8256 	    buf->b_p_com = vim_strsave(p_com);
8257 #endif
8258 #ifdef FEAT_FOLDING
8259 	    buf->b_p_cms = vim_strsave(p_cms);
8260 #endif
8261 	    buf->b_p_fo = vim_strsave(p_fo);
8262 	    buf->b_p_nf = vim_strsave(p_nf);
8263 	    buf->b_p_mps = vim_strsave(p_mps);
8264 #ifdef FEAT_SMARTINDENT
8265 	    buf->b_p_si = p_si;
8266 #endif
8267 	    buf->b_p_ci = p_ci;
8268 #ifdef FEAT_CINDENT
8269 	    buf->b_p_cin = p_cin;
8270 	    buf->b_p_cink = vim_strsave(p_cink);
8271 	    buf->b_p_cino = vim_strsave(p_cino);
8272 #endif
8273 #ifdef FEAT_AUTOCMD
8274 	    /* Don't copy 'filetype', it must be detected */
8275 	    buf->b_p_ft = empty_option;
8276 #endif
8277 #ifdef FEAT_OSFILETYPE
8278 	    buf->b_p_oft = vim_strsave(p_oft);
8279 #endif
8280 	    buf->b_p_pi = p_pi;
8281 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
8282 	    buf->b_p_cinw = vim_strsave(p_cinw);
8283 #endif
8284 #ifdef FEAT_LISP
8285 	    buf->b_p_lisp = p_lisp;
8286 #endif
8287 #ifdef FEAT_SYN_HL
8288 	    /* Don't copy 'syntax', it must be set */
8289 	    buf->b_p_syn = empty_option;
8290 #endif
8291 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
8292 	    buf->b_p_inde = vim_strsave(p_inde);
8293 	    buf->b_p_indk = vim_strsave(p_indk);
8294 #endif
8295 #ifdef FEAT_CRYPT
8296 	    buf->b_p_key = vim_strsave(p_key);
8297 #endif
8298 #ifdef FEAT_SEARCHPATH
8299 	    buf->b_p_sua = vim_strsave(p_sua);
8300 #endif
8301 #ifdef FEAT_KEYMAP
8302 	    buf->b_p_keymap = vim_strsave(p_keymap);
8303 	    buf->b_kmap_state |= KEYMAP_INIT;
8304 #endif
8305 	    /* This isn't really an option, but copying the langmap and IME
8306 	     * state from the current buffer is better than resetting it. */
8307 	    buf->b_p_iminsert = p_iminsert;
8308 	    buf->b_p_imsearch = p_imsearch;
8309 
8310 	    /* options that are normally global but also have a local value
8311 	     * are not copied, start using the global value */
8312 	    buf->b_p_ar = -1;
8313 #ifdef FEAT_QUICKFIX
8314 	    buf->b_p_gp = empty_option;
8315 	    buf->b_p_mp = empty_option;
8316 	    buf->b_p_efm = empty_option;
8317 #endif
8318 	    buf->b_p_ep = empty_option;
8319 	    buf->b_p_kp = empty_option;
8320 	    buf->b_p_path = empty_option;
8321 	    buf->b_p_tags = empty_option;
8322 #ifdef FEAT_FIND_ID
8323 	    buf->b_p_def = empty_option;
8324 	    buf->b_p_inc = empty_option;
8325 # ifdef FEAT_EVAL
8326 	    buf->b_p_inex = vim_strsave(p_inex);
8327 # endif
8328 #endif
8329 #ifdef FEAT_INS_EXPAND
8330 	    buf->b_p_dict = empty_option;
8331 	    buf->b_p_tsr = empty_option;
8332 #endif
8333 #ifdef FEAT_TEXTOBJ
8334 	    buf->b_p_qe = vim_strsave(p_qe);
8335 #endif
8336 
8337 	    /*
8338 	     * Don't copy the options set by ex_help(), use the saved values,
8339 	     * when going from a help buffer to a non-help buffer.
8340 	     * Don't touch these at all when BCO_NOHELP is used and going from
8341 	     * or to a help buffer.
8342 	     */
8343 	    if (dont_do_help)
8344 		buf->b_p_isk = save_p_isk;
8345 	    else
8346 	    {
8347 		buf->b_p_isk = vim_strsave(p_isk);
8348 		did_isk = TRUE;
8349 		buf->b_p_ts = p_ts;
8350 		buf->b_help = FALSE;
8351 #ifdef FEAT_QUICKFIX
8352 		if (buf->b_p_bt[0] == 'h')
8353 		    clear_string_option(&buf->b_p_bt);
8354 #endif
8355 		buf->b_p_ma = p_ma;
8356 	    }
8357 	}
8358 
8359 	/*
8360 	 * When the options should be copied (ignoring BCO_ALWAYS), set the
8361 	 * flag that indicates that the options have been initialized.
8362 	 */
8363 	if (should_copy)
8364 	    buf->b_p_initialized = TRUE;
8365     }
8366 
8367     check_buf_options(buf);	    /* make sure we don't have NULLs */
8368     if (did_isk)
8369 	(void)buf_init_chartab(buf, FALSE);
8370 }
8371 
8372 /*
8373  * Reset the 'modifiable' option and its default value.
8374  */
8375     void
8376 reset_modifiable()
8377 {
8378     int		opt_idx;
8379 
8380     curbuf->b_p_ma = FALSE;
8381     p_ma = FALSE;
8382     opt_idx = findoption((char_u *)"ma");
8383     options[opt_idx].def_val[VI_DEFAULT] = FALSE;
8384 }
8385 
8386 /*
8387  * Set the global value for 'iminsert' to the local value.
8388  */
8389     void
8390 set_iminsert_global()
8391 {
8392     p_iminsert = curbuf->b_p_iminsert;
8393 }
8394 
8395 /*
8396  * Set the global value for 'imsearch' to the local value.
8397  */
8398     void
8399 set_imsearch_global()
8400 {
8401     p_imsearch = curbuf->b_p_imsearch;
8402 }
8403 
8404 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
8405 static int expand_option_idx = -1;
8406 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
8407 static int expand_option_flags = 0;
8408 
8409     void
8410 set_context_in_set_cmd(xp, arg, opt_flags)
8411     expand_T	*xp;
8412     char_u	*arg;
8413     int		opt_flags;	/* OPT_GLOBAL and/or OPT_LOCAL */
8414 {
8415     int		nextchar;
8416     long_u	flags = 0;	/* init for GCC */
8417     int		opt_idx = 0;	/* init for GCC */
8418     char_u	*p;
8419     char_u	*s;
8420     int		is_term_option = FALSE;
8421     int		key;
8422 
8423     expand_option_flags = opt_flags;
8424 
8425     xp->xp_context = EXPAND_SETTINGS;
8426     if (*arg == NUL)
8427     {
8428 	xp->xp_pattern = arg;
8429 	return;
8430     }
8431     p = arg + STRLEN(arg) - 1;
8432     if (*p == ' ' && *(p - 1) != '\\')
8433     {
8434 	xp->xp_pattern = p + 1;
8435 	return;
8436     }
8437     while (p > arg)
8438     {
8439 	s = p;
8440 	/* count number of backslashes before ' ' or ',' */
8441 	if (*p == ' ' || *p == ',')
8442 	{
8443 	    while (s > arg && *(s - 1) == '\\')
8444 		--s;
8445 	}
8446 	/* break at a space with an even number of backslashes */
8447 	if (*p == ' ' && ((p - s) & 1) == 0)
8448 	{
8449 	    ++p;
8450 	    break;
8451 	}
8452 	--p;
8453     }
8454     if (STRNCMP(p, "no", 2) == 0)
8455     {
8456 	xp->xp_context = EXPAND_BOOL_SETTINGS;
8457 	p += 2;
8458     }
8459     if (STRNCMP(p, "inv", 3) == 0)
8460     {
8461 	xp->xp_context = EXPAND_BOOL_SETTINGS;
8462 	p += 3;
8463     }
8464     xp->xp_pattern = arg = p;
8465     if (*arg == '<')
8466     {
8467 	while (*p != '>')
8468 	    if (*p++ == NUL)	    /* expand terminal option name */
8469 		return;
8470 	key = get_special_key_code(arg + 1);
8471 	if (key == 0)		    /* unknown name */
8472 	{
8473 	    xp->xp_context = EXPAND_NOTHING;
8474 	    return;
8475 	}
8476 	nextchar = *++p;
8477 	is_term_option = TRUE;
8478 	expand_option_name[2] = KEY2TERMCAP0(key);
8479 	expand_option_name[3] = KEY2TERMCAP1(key);
8480     }
8481     else
8482     {
8483 	if (p[0] == 't' && p[1] == '_')
8484 	{
8485 	    p += 2;
8486 	    if (*p != NUL)
8487 		++p;
8488 	    if (*p == NUL)
8489 		return;		/* expand option name */
8490 	    nextchar = *++p;
8491 	    is_term_option = TRUE;
8492 	    expand_option_name[2] = p[-2];
8493 	    expand_option_name[3] = p[-1];
8494 	}
8495 	else
8496 	{
8497 		/* Allow * wildcard */
8498 	    while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
8499 		p++;
8500 	    if (*p == NUL)
8501 		return;
8502 	    nextchar = *p;
8503 	    *p = NUL;
8504 	    opt_idx = findoption(arg);
8505 	    *p = nextchar;
8506 	    if (opt_idx == -1 || options[opt_idx].var == NULL)
8507 	    {
8508 		xp->xp_context = EXPAND_NOTHING;
8509 		return;
8510 	    }
8511 	    flags = options[opt_idx].flags;
8512 	    if (flags & P_BOOL)
8513 	    {
8514 		xp->xp_context = EXPAND_NOTHING;
8515 		return;
8516 	    }
8517 	}
8518     }
8519     /* handle "-=" and "+=" */
8520     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
8521     {
8522 	++p;
8523 	nextchar = '=';
8524     }
8525     if ((nextchar != '=' && nextchar != ':')
8526 				    || xp->xp_context == EXPAND_BOOL_SETTINGS)
8527     {
8528 	xp->xp_context = EXPAND_UNSUCCESSFUL;
8529 	return;
8530     }
8531     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
8532     {
8533 	xp->xp_context = EXPAND_OLD_SETTING;
8534 	if (is_term_option)
8535 	    expand_option_idx = -1;
8536 	else
8537 	    expand_option_idx = opt_idx;
8538 	xp->xp_pattern = p + 1;
8539 	return;
8540     }
8541     xp->xp_context = EXPAND_NOTHING;
8542     if (is_term_option || (flags & P_NUM))
8543 	return;
8544 
8545     xp->xp_pattern = p + 1;
8546 
8547     if (flags & P_EXPAND)
8548     {
8549 	p = options[opt_idx].var;
8550 	if (p == (char_u *)&p_bdir
8551 		|| p == (char_u *)&p_dir
8552 		|| p == (char_u *)&p_path
8553 		|| p == (char_u *)&p_rtp
8554 #ifdef FEAT_SEARCHPATH
8555 		|| p == (char_u *)&p_cdpath
8556 #endif
8557 #ifdef FEAT_SESSION
8558 		|| p == (char_u *)&p_vdir
8559 #endif
8560 		)
8561 	{
8562 	    xp->xp_context = EXPAND_DIRECTORIES;
8563 	    if (p == (char_u *)&p_path
8564 #ifdef FEAT_SEARCHPATH
8565 		    || p == (char_u *)&p_cdpath
8566 #endif
8567 		   )
8568 		xp->xp_backslash = XP_BS_THREE;
8569 	    else
8570 		xp->xp_backslash = XP_BS_ONE;
8571 	}
8572 	else
8573 	{
8574 	    xp->xp_context = EXPAND_FILES;
8575 	    /* for 'tags' need three backslashes for a space */
8576 	    if (p == (char_u *)&p_tags)
8577 		xp->xp_backslash = XP_BS_THREE;
8578 	    else
8579 		xp->xp_backslash = XP_BS_ONE;
8580 	}
8581     }
8582 
8583     /* For an option that is a list of file names, find the start of the
8584      * last file name. */
8585     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
8586     {
8587 	/* count number of backslashes before ' ' or ',' */
8588 	if (*p == ' ' || *p == ',')
8589 	{
8590 	    s = p;
8591 	    while (s > xp->xp_pattern && *(s - 1) == '\\')
8592 		--s;
8593 	    if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
8594 		    || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
8595 	    {
8596 		xp->xp_pattern = p + 1;
8597 		break;
8598 	    }
8599 	}
8600     }
8601 
8602     return;
8603 }
8604 
8605     int
8606 ExpandSettings(xp, regmatch, num_file, file)
8607     expand_T	*xp;
8608     regmatch_T	*regmatch;
8609     int		*num_file;
8610     char_u	***file;
8611 {
8612     int		num_normal = 0;	    /* Nr of matching non-term-code settings */
8613     int		num_term = 0;	    /* Nr of matching terminal code settings */
8614     int		opt_idx;
8615     int		match;
8616     int		count = 0;
8617     char_u	*str;
8618     int		loop;
8619     int		is_term_opt;
8620     char_u	name_buf[MAX_KEY_NAME_LEN];
8621     static char *(names[]) = {"all", "termcap"};
8622     int		ic = regmatch->rm_ic;	/* remember the ignore-case flag */
8623 
8624     /* do this loop twice:
8625      * loop == 0: count the number of matching options
8626      * loop == 1: copy the matching options into allocated memory
8627      */
8628     for (loop = 0; loop <= 1; ++loop)
8629     {
8630 	regmatch->rm_ic = ic;
8631 	if (xp->xp_context != EXPAND_BOOL_SETTINGS)
8632 	{
8633 	    for (match = 0; match < sizeof(names) / sizeof(char *); ++match)
8634 		if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
8635 		{
8636 		    if (loop == 0)
8637 			num_normal++;
8638 		    else
8639 			(*file)[count++] = vim_strsave((char_u *)names[match]);
8640 		}
8641 	}
8642 	for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
8643 								    opt_idx++)
8644 	{
8645 	    if (options[opt_idx].var == NULL)
8646 		continue;
8647 	    if (xp->xp_context == EXPAND_BOOL_SETTINGS
8648 	      && !(options[opt_idx].flags & P_BOOL))
8649 		continue;
8650 	    is_term_opt = istermoption(&options[opt_idx]);
8651 	    if (is_term_opt && num_normal > 0)
8652 		continue;
8653 	    match = FALSE;
8654 	    if (vim_regexec(regmatch, str, (colnr_T)0)
8655 		    || (options[opt_idx].shortname != NULL
8656 			&& vim_regexec(regmatch,
8657 			   (char_u *)options[opt_idx].shortname, (colnr_T)0)))
8658 		match = TRUE;
8659 	    else if (is_term_opt)
8660 	    {
8661 		name_buf[0] = '<';
8662 		name_buf[1] = 't';
8663 		name_buf[2] = '_';
8664 		name_buf[3] = str[2];
8665 		name_buf[4] = str[3];
8666 		name_buf[5] = '>';
8667 		name_buf[6] = NUL;
8668 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8669 		{
8670 		    match = TRUE;
8671 		    str = name_buf;
8672 		}
8673 	    }
8674 	    if (match)
8675 	    {
8676 		if (loop == 0)
8677 		{
8678 		    if (is_term_opt)
8679 			num_term++;
8680 		    else
8681 			num_normal++;
8682 		}
8683 		else
8684 		    (*file)[count++] = vim_strsave(str);
8685 	    }
8686 	}
8687 	/*
8688 	 * Check terminal key codes, these are not in the option table
8689 	 */
8690 	if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
8691 	{
8692 	    for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
8693 	    {
8694 		if (!isprint(str[0]) || !isprint(str[1]))
8695 		    continue;
8696 
8697 		name_buf[0] = 't';
8698 		name_buf[1] = '_';
8699 		name_buf[2] = str[0];
8700 		name_buf[3] = str[1];
8701 		name_buf[4] = NUL;
8702 
8703 		match = FALSE;
8704 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8705 		    match = TRUE;
8706 		else
8707 		{
8708 		    name_buf[0] = '<';
8709 		    name_buf[1] = 't';
8710 		    name_buf[2] = '_';
8711 		    name_buf[3] = str[0];
8712 		    name_buf[4] = str[1];
8713 		    name_buf[5] = '>';
8714 		    name_buf[6] = NUL;
8715 
8716 		    if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8717 			match = TRUE;
8718 		}
8719 		if (match)
8720 		{
8721 		    if (loop == 0)
8722 			num_term++;
8723 		    else
8724 			(*file)[count++] = vim_strsave(name_buf);
8725 		}
8726 	    }
8727 
8728 	    /*
8729 	     * Check special key names.
8730 	     */
8731 	    regmatch->rm_ic = TRUE;		/* ignore case here */
8732 	    for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
8733 	    {
8734 		name_buf[0] = '<';
8735 		STRCPY(name_buf + 1, str);
8736 		STRCAT(name_buf, ">");
8737 
8738 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
8739 		{
8740 		    if (loop == 0)
8741 			num_term++;
8742 		    else
8743 			(*file)[count++] = vim_strsave(name_buf);
8744 		}
8745 	    }
8746 	}
8747 	if (loop == 0)
8748 	{
8749 	    if (num_normal > 0)
8750 		*num_file = num_normal;
8751 	    else if (num_term > 0)
8752 		*num_file = num_term;
8753 	    else
8754 		return OK;
8755 	    *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
8756 	    if (*file == NULL)
8757 	    {
8758 		*file = (char_u **)"";
8759 		return FAIL;
8760 	    }
8761 	}
8762     }
8763     return OK;
8764 }
8765 
8766     int
8767 ExpandOldSetting(num_file, file)
8768     int	    *num_file;
8769     char_u  ***file;
8770 {
8771     char_u  *var = NULL;	/* init for GCC */
8772     char_u  *buf;
8773 
8774     *num_file = 0;
8775     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
8776     if (*file == NULL)
8777 	return FAIL;
8778 
8779     /*
8780      * For a terminal key code expand_option_idx is < 0.
8781      */
8782     if (expand_option_idx < 0)
8783     {
8784 	var = find_termcode(expand_option_name + 2);
8785 	if (var == NULL)
8786 	    expand_option_idx = findoption(expand_option_name);
8787     }
8788 
8789     if (expand_option_idx >= 0)
8790     {
8791 	/* put string of option value in NameBuff */
8792 	option_value2string(&options[expand_option_idx], expand_option_flags);
8793 	var = NameBuff;
8794     }
8795     else if (var == NULL)
8796 	var = (char_u *)"";
8797 
8798     /* A backslash is required before some characters.  This is the reverse of
8799      * what happens in do_set(). */
8800     buf = vim_strsave_escaped(var, escape_chars);
8801 
8802     if (buf == NULL)
8803     {
8804 	vim_free(*file);
8805 	*file = NULL;
8806 	return FAIL;
8807     }
8808 
8809 #ifdef BACKSLASH_IN_FILENAME
8810     /* For MS-Windows et al. we don't double backslashes at the start and
8811      * before a file name character. */
8812     for (var = buf; *var != NUL; )
8813     {
8814 	if (var[0] == '\\' && var[1] == '\\'
8815 		&& expand_option_idx >= 0
8816 		&& (options[expand_option_idx].flags & P_EXPAND)
8817 		&& vim_isfilec(var[2])
8818 		&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
8819 	    mch_memmove(var, var + 1, STRLEN(var));
8820 #ifdef FEAT_MBYTE
8821 	else if (has_mbyte)
8822 	    var += (*mb_ptr2len_check)(var) - 1;
8823 #endif
8824 	++var;
8825     }
8826 #endif
8827 
8828     *file[0] = buf;
8829     *num_file = 1;
8830     return OK;
8831 }
8832 #endif
8833 
8834 /*
8835  * Get the value for the numeric or string option *opp in a nice format into
8836  * NameBuff[].  Must not be called with a hidden option!
8837  */
8838     static void
8839 option_value2string(opp, opt_flags)
8840     struct vimoption	*opp;
8841     int			opt_flags;	/* OPT_GLOBAL and/or OPT_LOCAL */
8842 {
8843     char_u	*varp;
8844 
8845     varp = get_varp_scope(opp, opt_flags);
8846 
8847     if (opp->flags & P_NUM)
8848     {
8849 	long wc = 0;
8850 
8851 	if (wc_use_keyname(varp, &wc))
8852 	    STRCPY(NameBuff, get_special_key_name((int)wc, 0));
8853 	else if (wc != 0)
8854 	    STRCPY(NameBuff, transchar((int)wc));
8855 	else
8856 	    sprintf((char *)NameBuff, "%ld", *(long *)varp);
8857     }
8858     else    /* P_STRING */
8859     {
8860 	varp = *(char_u **)(varp);
8861 	if (varp == NULL)		    /* just in case */
8862 	    NameBuff[0] = NUL;
8863 #ifdef FEAT_CRYPT
8864 	/* don't show the actual value of 'key', only that it's set */
8865 	if (opp->var == (char_u *)&p_key && *varp)
8866 	    STRCPY(NameBuff, "*****");
8867 #endif
8868 	else if (opp->flags & P_EXPAND)
8869 	    home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
8870 	/* Translate 'pastetoggle' into special key names */
8871 	else if ((char_u **)opp->var == &p_pt)
8872 	    str2specialbuf(p_pt, NameBuff, MAXPATHL);
8873 	else
8874 	    STRNCPY(NameBuff, varp, MAXPATHL);
8875     }
8876 }
8877 
8878 /*
8879  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
8880  * printed as a keyname.
8881  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
8882  */
8883     static int
8884 wc_use_keyname(varp, wcp)
8885     char_u	*varp;
8886     long	*wcp;
8887 {
8888     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
8889     {
8890 	*wcp = *(long *)varp;
8891 	if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
8892 	    return TRUE;
8893     }
8894     return FALSE;
8895 }
8896 
8897 #ifdef FEAT_LANGMAP
8898 /*
8899  * Any character has an equivalent character.  This is used for keyboards that
8900  * have a special language mode that sends characters above 128 (although
8901  * other characters can be translated too).
8902  */
8903 
8904 /*
8905  * char_u langmap_mapchar[256];
8906  * Normally maps each of the 128 upper chars to an <128 ascii char; used to
8907  * "translate" native lang chars in normal mode or some cases of
8908  * insert mode without having to tediously switch lang mode back&forth.
8909  */
8910 
8911     static void
8912 langmap_init()
8913 {
8914     int i;
8915 
8916     for (i = 0; i < 256; i++)		/* we init with a-one-to one map */
8917 	langmap_mapchar[i] = i;
8918 }
8919 
8920 /*
8921  * Called when langmap option is set; the language map can be
8922  * changed at any time!
8923  */
8924     static void
8925 langmap_set()
8926 {
8927     char_u  *p;
8928     char_u  *p2;
8929     int	    from, to;
8930 
8931     langmap_init();			    /* back to one-to-one map first */
8932 
8933     for (p = p_langmap; p[0] != NUL; )
8934     {
8935 	for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; ++p2)
8936 	{
8937 	    if (p2[0] == '\\' && p2[1] != NUL)
8938 		++p2;
8939 #ifdef FEAT_MBYTE
8940 	    p2 += (*mb_ptr2len_check)(p2) - 1;
8941 #endif
8942 	}
8943 	if (p2[0] == ';')
8944 	    ++p2;	    /* abcd;ABCD form, p2 points to A */
8945 	else
8946 	    p2 = NULL;	    /* aAbBcCdD form, p2 is NULL */
8947 	while (p[0])
8948 	{
8949 	    if (p[0] == '\\' && p[1] != NUL)
8950 		++p;
8951 #ifdef FEAT_MBYTE
8952 	    from = (*mb_ptr2char)(p);
8953 #else
8954 	    from = p[0];
8955 #endif
8956 	    if (p2 == NULL)
8957 	    {
8958 #ifdef FEAT_MBYTE
8959 		p += (*mb_ptr2len_check)(p);
8960 #else
8961 		++p;
8962 #endif
8963 		if (p[0] == '\\')
8964 		    ++p;
8965 #ifdef FEAT_MBYTE
8966 		to = (*mb_ptr2char)(p);
8967 #else
8968 		to = p[0];
8969 #endif
8970 	    }
8971 	    else
8972 	    {
8973 		if (p2[0] == '\\')
8974 		    ++p2;
8975 #ifdef FEAT_MBYTE
8976 		to = (*mb_ptr2char)(p2);
8977 #else
8978 		to = p2[0];
8979 #endif
8980 	    }
8981 	    if (to == NUL)
8982 	    {
8983 		EMSG2(_("E357: 'langmap': Matching character missing for %s"),
8984 							     transchar(from));
8985 		return;
8986 	    }
8987 	    langmap_mapchar[from & 255] = to;
8988 
8989 	    /* Advance to next pair */
8990 #ifdef FEAT_MBYTE
8991 	    p += (*mb_ptr2len_check)(p);
8992 #else
8993 	    ++p;
8994 #endif
8995 	    if (p2 == NULL)
8996 	    {
8997 		if (p[0] == ',')
8998 		{
8999 		    ++p;
9000 		    break;
9001 		}
9002 	    }
9003 	    else
9004 	    {
9005 #ifdef FEAT_MBYTE
9006 		p2 += (*mb_ptr2len_check)(p2);
9007 #else
9008 		++p2;
9009 #endif
9010 		if (*p == ';')
9011 		{
9012 		    p = p2;
9013 		    if (p[0] != NUL)
9014 		    {
9015 			if (p[0] != ',')
9016 			{
9017 			    EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
9018 			    return;
9019 			}
9020 			++p;
9021 		    }
9022 		    break;
9023 		}
9024 	    }
9025 	}
9026     }
9027 }
9028 #endif
9029 
9030 /*
9031  * Return TRUE if format option 'x' is in effect.
9032  * Take care of no formatting when 'paste' is set.
9033  */
9034     int
9035 has_format_option(x)
9036     int		x;
9037 {
9038     if (p_paste)
9039 	return FALSE;
9040     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
9041 }
9042 
9043 /*
9044  * Return TRUE if "x" is present in 'shortmess' option, or
9045  * 'shortmess' contains 'a' and "x" is present in SHM_A.
9046  */
9047     int
9048 shortmess(x)
9049     int	    x;
9050 {
9051     return (   vim_strchr(p_shm, x) != NULL
9052 	    || (vim_strchr(p_shm, 'a') != NULL
9053 		&& vim_strchr((char_u *)SHM_A, x) != NULL));
9054 }
9055 
9056 /*
9057  * paste_option_changed() - Called after p_paste was set or reset.
9058  */
9059     static void
9060 paste_option_changed()
9061 {
9062     static int	old_p_paste = FALSE;
9063     static int	save_sm = 0;
9064 #ifdef FEAT_CMDL_INFO
9065     static int	save_ru = 0;
9066 #endif
9067 #ifdef FEAT_RIGHTLEFT
9068     static int	save_ri = 0;
9069     static int	save_hkmap = 0;
9070 #endif
9071     buf_T	*buf;
9072 
9073     if (p_paste)
9074     {
9075 	/*
9076 	 * Paste switched from off to on.
9077 	 * Save the current values, so they can be restored later.
9078 	 */
9079 	if (!old_p_paste)
9080 	{
9081 	    /* save options for each buffer */
9082 	    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9083 	    {
9084 		buf->b_p_tw_nopaste = buf->b_p_tw;
9085 		buf->b_p_wm_nopaste = buf->b_p_wm;
9086 		buf->b_p_sts_nopaste = buf->b_p_sts;
9087 		buf->b_p_ai_nopaste = buf->b_p_ai;
9088 	    }
9089 
9090 	    /* save global options */
9091 	    save_sm = p_sm;
9092 #ifdef FEAT_CMDL_INFO
9093 	    save_ru = p_ru;
9094 #endif
9095 #ifdef FEAT_RIGHTLEFT
9096 	    save_ri = p_ri;
9097 	    save_hkmap = p_hkmap;
9098 #endif
9099 	    /* save global values for local buffer options */
9100 	    p_tw_nopaste = p_tw;
9101 	    p_wm_nopaste = p_wm;
9102 	    p_sts_nopaste = p_sts;
9103 	    p_ai_nopaste = p_ai;
9104 	}
9105 
9106 	/*
9107 	 * Always set the option values, also when 'paste' is set when it is
9108 	 * already on.
9109 	 */
9110 	/* set options for each buffer */
9111 	for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9112 	{
9113 	    buf->b_p_tw = 0;	    /* textwidth is 0 */
9114 	    buf->b_p_wm = 0;	    /* wrapmargin is 0 */
9115 	    buf->b_p_sts = 0;	    /* softtabstop is 0 */
9116 	    buf->b_p_ai = 0;	    /* no auto-indent */
9117 	}
9118 
9119 	/* set global options */
9120 	p_sm = 0;		    /* no showmatch */
9121 #ifdef FEAT_CMDL_INFO
9122 # ifdef FEAT_WINDOWS
9123 	if (p_ru)
9124 	    status_redraw_all();    /* redraw to remove the ruler */
9125 # endif
9126 	p_ru = 0;		    /* no ruler */
9127 #endif
9128 #ifdef FEAT_RIGHTLEFT
9129 	p_ri = 0;		    /* no reverse insert */
9130 	p_hkmap = 0;		    /* no Hebrew keyboard */
9131 #endif
9132 	/* set global values for local buffer options */
9133 	p_tw = 0;
9134 	p_wm = 0;
9135 	p_sts = 0;
9136 	p_ai = 0;
9137     }
9138 
9139     /*
9140      * Paste switched from on to off: Restore saved values.
9141      */
9142     else if (old_p_paste)
9143     {
9144 	/* restore options for each buffer */
9145 	for (buf = firstbuf; buf != NULL; buf = buf->b_next)
9146 	{
9147 	    buf->b_p_tw = buf->b_p_tw_nopaste;
9148 	    buf->b_p_wm = buf->b_p_wm_nopaste;
9149 	    buf->b_p_sts = buf->b_p_sts_nopaste;
9150 	    buf->b_p_ai = buf->b_p_ai_nopaste;
9151 	}
9152 
9153 	/* restore global options */
9154 	p_sm = save_sm;
9155 #ifdef FEAT_CMDL_INFO
9156 # ifdef FEAT_WINDOWS
9157 	if (p_ru != save_ru)
9158 	    status_redraw_all();    /* redraw to draw the ruler */
9159 # endif
9160 	p_ru = save_ru;
9161 #endif
9162 #ifdef FEAT_RIGHTLEFT
9163 	p_ri = save_ri;
9164 	p_hkmap = save_hkmap;
9165 #endif
9166 	/* set global values for local buffer options */
9167 	p_tw = p_tw_nopaste;
9168 	p_wm = p_wm_nopaste;
9169 	p_sts = p_sts_nopaste;
9170 	p_ai = p_ai_nopaste;
9171     }
9172 
9173     old_p_paste = p_paste;
9174 }
9175 
9176 /*
9177  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
9178  *
9179  * Reset 'compatible' and set the values for options that didn't get set yet
9180  * to the Vim defaults.
9181  * Don't do this if the 'compatible' option has been set or reset before.
9182  */
9183     void
9184 vimrc_found()
9185 {
9186     int	    opt_idx;
9187 
9188     if (!option_was_set((char_u *)"cp"))
9189     {
9190 	p_cp = FALSE;
9191 	for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9192 	    if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
9193 		set_option_default(opt_idx, OPT_FREE, FALSE);
9194 	didset_options();
9195     }
9196 }
9197 
9198 /*
9199  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
9200  */
9201     void
9202 change_compatible(on)
9203     int	    on;
9204 {
9205     if (p_cp != on)
9206     {
9207 	p_cp = on;
9208 	compatible_set();
9209     }
9210     options[findoption((char_u *)"cp")].flags |= P_WAS_SET;
9211 }
9212 
9213 /*
9214  * Return TRUE when option "name" has been set.
9215  */
9216     int
9217 option_was_set(name)
9218     char_u	*name;
9219 {
9220     int idx;
9221 
9222     idx = findoption(name);
9223     if (idx < 0)	/* unknown option */
9224 	return FALSE;
9225     if (options[idx].flags & P_WAS_SET)
9226 	return TRUE;
9227     return FALSE;
9228 }
9229 
9230 /*
9231  * compatible_set() - Called when 'compatible' has been set or unset.
9232  *
9233  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
9234  * flag) to a Vi compatible value.
9235  * When 'compatible' is unset: Set all options that have a different default
9236  * for Vim (without the P_VI_DEF flag) to that default.
9237  */
9238     static void
9239 compatible_set()
9240 {
9241     int	    opt_idx;
9242 
9243     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
9244 	if (	   ((options[opt_idx].flags & P_VIM) && p_cp)
9245 		|| (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
9246 	    set_option_default(opt_idx, OPT_FREE, p_cp);
9247     didset_options();
9248 }
9249 
9250 #ifdef FEAT_LINEBREAK
9251 
9252 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9253    /* Borland C++ screws up loop optimisation here (negri) */
9254 #  pragma option -O-l
9255 # endif
9256 
9257 /*
9258  * fill_breakat_flags() -- called when 'breakat' changes value.
9259  */
9260     static void
9261 fill_breakat_flags()
9262 {
9263     char_u	*c;
9264     int		i;
9265 
9266     for (i = 0; i < 256; i++)
9267 	breakat_flags[i] = FALSE;
9268 
9269     if (p_breakat != NULL)
9270 	for (c = p_breakat; *c; c++)
9271 	    breakat_flags[*c] = TRUE;
9272 }
9273 
9274 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
9275 #  pragma option -O.l
9276 # endif
9277 
9278 #endif
9279 
9280 /*
9281  * Check an option that can be a range of string values.
9282  *
9283  * Return OK for correct value, FAIL otherwise.
9284  * Empty is always OK.
9285  */
9286     static int
9287 check_opt_strings(val, values, list)
9288     char_u	*val;
9289     char	**values;
9290     int		list;	    /* when TRUE: accept a list of values */
9291 {
9292     return opt_strings_flags(val, values, NULL, list);
9293 }
9294 
9295 /*
9296  * Handle an option that can be a range of string values.
9297  * Set a flag in "*flagp" for each string present.
9298  *
9299  * Return OK for correct value, FAIL otherwise.
9300  * Empty is always OK.
9301  */
9302     static int
9303 opt_strings_flags(val, values, flagp, list)
9304     char_u	*val;		/* new value */
9305     char	**values;	/* array of valid string values */
9306     unsigned	*flagp;
9307     int		list;		/* when TRUE: accept a list of values */
9308 {
9309     int		i;
9310     int		len;
9311     unsigned	new_flags = 0;
9312 
9313     while (*val)
9314     {
9315 	for (i = 0; ; ++i)
9316 	{
9317 	    if (values[i] == NULL)	/* val not found in values[] */
9318 		return FAIL;
9319 
9320 	    len = (int)STRLEN(values[i]);
9321 	    if (STRNCMP(values[i], val, len) == 0
9322 		    && ((list && val[len] == ',') || val[len] == NUL))
9323 	    {
9324 		val += len + (val[len] == ',');
9325 		new_flags |= (1 << i);
9326 		break;		/* check next item in val list */
9327 	    }
9328 	}
9329     }
9330     if (flagp != NULL)
9331 	*flagp = new_flags;
9332 
9333     return OK;
9334 }
9335 
9336 /*
9337  * Read the 'wildmode' option, fill wim_flags[].
9338  */
9339     static int
9340 check_opt_wim()
9341 {
9342     char_u	new_wim_flags[4];
9343     char_u	*p;
9344     int		i;
9345     int		idx = 0;
9346 
9347     for (i = 0; i < 4; ++i)
9348 	new_wim_flags[i] = 0;
9349 
9350     for (p = p_wim; *p; ++p)
9351     {
9352 	for (i = 0; ASCII_ISALPHA(p[i]); ++i)
9353 	    ;
9354 	if (p[i] != NUL && p[i] != ',' && p[i] != ':')
9355 	    return FAIL;
9356 	if (i == 7 && STRNCMP(p, "longest", 7) == 0)
9357 	    new_wim_flags[idx] |= WIM_LONGEST;
9358 	else if (i == 4 && STRNCMP(p, "full", 4) == 0)
9359 	    new_wim_flags[idx] |= WIM_FULL;
9360 	else if (i == 4 && STRNCMP(p, "list", 4) == 0)
9361 	    new_wim_flags[idx] |= WIM_LIST;
9362 	else
9363 	    return FAIL;
9364 	p += i;
9365 	if (*p == NUL)
9366 	    break;
9367 	if (*p == ',')
9368 	{
9369 	    if (idx == 3)
9370 		return FAIL;
9371 	    ++idx;
9372 	}
9373     }
9374 
9375     /* fill remaining entries with last flag */
9376     while (idx < 3)
9377     {
9378 	new_wim_flags[idx + 1] = new_wim_flags[idx];
9379 	++idx;
9380     }
9381 
9382     /* only when there are no errors, wim_flags[] is changed */
9383     for (i = 0; i < 4; ++i)
9384 	wim_flags[i] = new_wim_flags[i];
9385     return OK;
9386 }
9387 
9388 /*
9389  * Check if backspacing over something is allowed.
9390  */
9391     int
9392 can_bs(what)
9393     int		what;	    /* BS_INDENT, BS_EOL or BS_START */
9394 {
9395     switch (*p_bs)
9396     {
9397 	case '2':	return TRUE;
9398 	case '1':	return (what != BS_START);
9399 	case '0':	return FALSE;
9400     }
9401     return vim_strchr(p_bs, what) != NULL;
9402 }
9403 
9404 /*
9405  * Save the current values of 'fileformat' and 'fileencoding', so that we know
9406  * the file must be considered changed when the value is different.
9407  */
9408     void
9409 save_file_ff(buf)
9410     buf_T	*buf;
9411 {
9412     buf->b_start_ffc = *buf->b_p_ff;
9413     buf->b_start_eol = buf->b_p_eol;
9414 #ifdef FEAT_MBYTE
9415     /* Only use free/alloc when necessary, they take time. */
9416     if (buf->b_start_fenc == NULL
9417 			     || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
9418     {
9419 	vim_free(buf->b_start_fenc);
9420 	buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
9421     }
9422 #endif
9423 }
9424 
9425 /*
9426  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
9427  * from when editing started (save_file_ff() called).
9428  * Also when 'endofline' was changed and 'binary' is set.
9429  * Don't consider a new, empty buffer to be changed.
9430  */
9431     int
9432 file_ff_differs(buf)
9433     buf_T	*buf;
9434 {
9435     if ((buf->b_flags & BF_NEW)
9436 	    && buf->b_ml.ml_line_count == 1
9437 	    && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
9438 	return FALSE;
9439     if (buf->b_start_ffc != *buf->b_p_ff)
9440 	return TRUE;
9441     if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
9442 	return TRUE;
9443 #ifdef FEAT_MBYTE
9444     if (buf->b_start_fenc == NULL)
9445 	return (*buf->b_p_fenc != NUL);
9446     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
9447 #else
9448     return FALSE;
9449 #endif
9450 }
9451 
9452 /*
9453  * return OK if "p" is a valid fileformat name, FAIL otherwise.
9454  */
9455     int
9456 check_ff_value(p)
9457     char_u	*p;
9458 {
9459     return check_opt_strings(p, p_ff_values, FALSE);
9460 }
9461