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