xref: /vim-8.2.3635/src/option.c (revision fb094e14)
1 /* vi:set ts=8 sts=4 sw=4 noet:
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/quickref.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_WIN is added: window-local option
42  * PV_BUF is added: buffer-local option
43  * PV_BOTH is added: global option which also has a local value.
44  */
45 #define PV_BOTH 0x1000
46 #define PV_WIN  0x2000
47 #define PV_BUF  0x4000
48 #define PV_MASK 0x0fff
49 #define OPT_WIN(x)  (idopt_T)(PV_WIN + (int)(x))
50 #define OPT_BUF(x)  (idopt_T)(PV_BUF + (int)(x))
51 #define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52 
53 /*
54  * Definition of the PV_ values for buffer-local options.
55  * The BV_ values are defined in option.h.
56  */
57 #define PV_AI		OPT_BUF(BV_AI)
58 #define PV_AR		OPT_BOTH(OPT_BUF(BV_AR))
59 #define PV_BKC		OPT_BOTH(OPT_BUF(BV_BKC))
60 #define PV_BH		OPT_BUF(BV_BH)
61 #define PV_BT		OPT_BUF(BV_BT)
62 #ifdef FEAT_QUICKFIX
63 # define PV_EFM		OPT_BOTH(OPT_BUF(BV_EFM))
64 # define PV_GP		OPT_BOTH(OPT_BUF(BV_GP))
65 # define PV_MP		OPT_BOTH(OPT_BUF(BV_MP))
66 #endif
67 #define PV_BIN		OPT_BUF(BV_BIN)
68 #define PV_BL		OPT_BUF(BV_BL)
69 #ifdef FEAT_MBYTE
70 # define PV_BOMB	OPT_BUF(BV_BOMB)
71 #endif
72 #define PV_CI		OPT_BUF(BV_CI)
73 #ifdef FEAT_CINDENT
74 # define PV_CIN		OPT_BUF(BV_CIN)
75 # define PV_CINK	OPT_BUF(BV_CINK)
76 # define PV_CINO	OPT_BUF(BV_CINO)
77 #endif
78 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79 # define PV_CINW	OPT_BUF(BV_CINW)
80 #endif
81 #define PV_CM		OPT_BOTH(OPT_BUF(BV_CM))
82 #ifdef FEAT_FOLDING
83 # define PV_CMS		OPT_BUF(BV_CMS)
84 #endif
85 #ifdef FEAT_COMMENTS
86 # define PV_COM		OPT_BUF(BV_COM)
87 #endif
88 #ifdef FEAT_INS_EXPAND
89 # define PV_CPT		OPT_BUF(BV_CPT)
90 # define PV_DICT	OPT_BOTH(OPT_BUF(BV_DICT))
91 # define PV_TSR		OPT_BOTH(OPT_BUF(BV_TSR))
92 #endif
93 #ifdef FEAT_COMPL_FUNC
94 # define PV_CFU		OPT_BUF(BV_CFU)
95 #endif
96 #ifdef FEAT_FIND_ID
97 # define PV_DEF		OPT_BOTH(OPT_BUF(BV_DEF))
98 # define PV_INC		OPT_BOTH(OPT_BUF(BV_INC))
99 #endif
100 #define PV_EOL		OPT_BUF(BV_EOL)
101 #define PV_FIXEOL	OPT_BUF(BV_FIXEOL)
102 #define PV_EP		OPT_BOTH(OPT_BUF(BV_EP))
103 #define PV_ET		OPT_BUF(BV_ET)
104 #ifdef FEAT_MBYTE
105 # define PV_FENC	OPT_BUF(BV_FENC)
106 #endif
107 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108 # define PV_BEXPR	OPT_BOTH(OPT_BUF(BV_BEXPR))
109 #endif
110 #define PV_FP		OPT_BOTH(OPT_BUF(BV_FP))
111 #ifdef FEAT_EVAL
112 # define PV_FEX		OPT_BUF(BV_FEX)
113 #endif
114 #define PV_FF		OPT_BUF(BV_FF)
115 #define PV_FLP		OPT_BUF(BV_FLP)
116 #define PV_FO		OPT_BUF(BV_FO)
117 #ifdef FEAT_AUTOCMD
118 # define PV_FT		OPT_BUF(BV_FT)
119 #endif
120 #define PV_IMI		OPT_BUF(BV_IMI)
121 #define PV_IMS		OPT_BUF(BV_IMS)
122 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123 # define PV_INDE	OPT_BUF(BV_INDE)
124 # define PV_INDK	OPT_BUF(BV_INDK)
125 #endif
126 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127 # define PV_INEX	OPT_BUF(BV_INEX)
128 #endif
129 #define PV_INF		OPT_BUF(BV_INF)
130 #define PV_ISK		OPT_BUF(BV_ISK)
131 #ifdef FEAT_CRYPT
132 # define PV_KEY		OPT_BUF(BV_KEY)
133 #endif
134 #ifdef FEAT_KEYMAP
135 # define PV_KMAP	OPT_BUF(BV_KMAP)
136 #endif
137 #define PV_KP		OPT_BOTH(OPT_BUF(BV_KP))
138 #ifdef FEAT_LISP
139 # define PV_LISP	OPT_BUF(BV_LISP)
140 # define PV_LW		OPT_BOTH(OPT_BUF(BV_LW))
141 #endif
142 #ifdef FEAT_MBYTE
143 # define PV_MENC	OPT_BOTH(OPT_BUF(BV_MENC))
144 #endif
145 #define PV_MA		OPT_BUF(BV_MA)
146 #define PV_ML		OPT_BUF(BV_ML)
147 #define PV_MOD		OPT_BUF(BV_MOD)
148 #define PV_MPS		OPT_BUF(BV_MPS)
149 #define PV_NF		OPT_BUF(BV_NF)
150 #ifdef FEAT_COMPL_FUNC
151 # define PV_OFU		OPT_BUF(BV_OFU)
152 #endif
153 #define PV_PATH		OPT_BOTH(OPT_BUF(BV_PATH))
154 #define PV_PI		OPT_BUF(BV_PI)
155 #ifdef FEAT_TEXTOBJ
156 # define PV_QE		OPT_BUF(BV_QE)
157 #endif
158 #define PV_RO		OPT_BUF(BV_RO)
159 #ifdef FEAT_SMARTINDENT
160 # define PV_SI		OPT_BUF(BV_SI)
161 #endif
162 #define PV_SN		OPT_BUF(BV_SN)
163 #ifdef FEAT_SYN_HL
164 # define PV_SMC		OPT_BUF(BV_SMC)
165 # define PV_SYN		OPT_BUF(BV_SYN)
166 #endif
167 #ifdef FEAT_SPELL
168 # define PV_SPC		OPT_BUF(BV_SPC)
169 # define PV_SPF		OPT_BUF(BV_SPF)
170 # define PV_SPL		OPT_BUF(BV_SPL)
171 #endif
172 #define PV_STS		OPT_BUF(BV_STS)
173 #ifdef FEAT_SEARCHPATH
174 # define PV_SUA		OPT_BUF(BV_SUA)
175 #endif
176 #define PV_SW		OPT_BUF(BV_SW)
177 #define PV_SWF		OPT_BUF(BV_SWF)
178 #define PV_TAGS		OPT_BOTH(OPT_BUF(BV_TAGS))
179 #define PV_TC		OPT_BOTH(OPT_BUF(BV_TC))
180 #define PV_TS		OPT_BUF(BV_TS)
181 #define PV_TW		OPT_BUF(BV_TW)
182 #define PV_TX		OPT_BUF(BV_TX)
183 #ifdef FEAT_PERSISTENT_UNDO
184 # define PV_UDF		OPT_BUF(BV_UDF)
185 #endif
186 #define PV_WM		OPT_BUF(BV_WM)
187 
188 /*
189  * Definition of the PV_ values for window-local options.
190  * The WV_ values are defined in option.h.
191  */
192 #define PV_LIST		OPT_WIN(WV_LIST)
193 #ifdef FEAT_ARABIC
194 # define PV_ARAB	OPT_WIN(WV_ARAB)
195 #endif
196 #ifdef FEAT_LINEBREAK
197 # define PV_BRI		OPT_WIN(WV_BRI)
198 # define PV_BRIOPT	OPT_WIN(WV_BRIOPT)
199 #endif
200 #ifdef FEAT_DIFF
201 # define PV_DIFF	OPT_WIN(WV_DIFF)
202 #endif
203 #ifdef FEAT_FOLDING
204 # define PV_FDC		OPT_WIN(WV_FDC)
205 # define PV_FEN		OPT_WIN(WV_FEN)
206 # define PV_FDI		OPT_WIN(WV_FDI)
207 # define PV_FDL		OPT_WIN(WV_FDL)
208 # define PV_FDM		OPT_WIN(WV_FDM)
209 # define PV_FML		OPT_WIN(WV_FML)
210 # define PV_FDN		OPT_WIN(WV_FDN)
211 # ifdef FEAT_EVAL
212 #  define PV_FDE	OPT_WIN(WV_FDE)
213 #  define PV_FDT	OPT_WIN(WV_FDT)
214 # endif
215 # define PV_FMR		OPT_WIN(WV_FMR)
216 #endif
217 #ifdef FEAT_LINEBREAK
218 # define PV_LBR		OPT_WIN(WV_LBR)
219 #endif
220 #define PV_NU		OPT_WIN(WV_NU)
221 #define PV_RNU		OPT_WIN(WV_RNU)
222 #ifdef FEAT_LINEBREAK
223 # define PV_NUW		OPT_WIN(WV_NUW)
224 #endif
225 #if defined(FEAT_QUICKFIX)
226 # define PV_PVW		OPT_WIN(WV_PVW)
227 #endif
228 #ifdef FEAT_RIGHTLEFT
229 # define PV_RL		OPT_WIN(WV_RL)
230 # define PV_RLC		OPT_WIN(WV_RLC)
231 #endif
232 #ifdef FEAT_SCROLLBIND
233 # define PV_SCBIND	OPT_WIN(WV_SCBIND)
234 #endif
235 #define PV_SCROLL	OPT_WIN(WV_SCROLL)
236 #ifdef FEAT_SPELL
237 # define PV_SPELL	OPT_WIN(WV_SPELL)
238 #endif
239 #ifdef FEAT_SYN_HL
240 # define PV_CUC		OPT_WIN(WV_CUC)
241 # define PV_CUL		OPT_WIN(WV_CUL)
242 # define PV_CC		OPT_WIN(WV_CC)
243 #endif
244 #ifdef FEAT_STL_OPT
245 # define PV_STL		OPT_BOTH(OPT_WIN(WV_STL))
246 #endif
247 #define PV_UL		OPT_BOTH(OPT_BUF(BV_UL))
248 # define PV_WFH		OPT_WIN(WV_WFH)
249 # define PV_WFW		OPT_WIN(WV_WFW)
250 #define PV_WRAP		OPT_WIN(WV_WRAP)
251 #ifdef FEAT_CURSORBIND
252 # define PV_CRBIND	OPT_WIN(WV_CRBIND)
253 #endif
254 #ifdef FEAT_CONCEAL
255 # define PV_COCU	OPT_WIN(WV_COCU)
256 # define PV_COLE	OPT_WIN(WV_COLE)
257 #endif
258 #ifdef FEAT_TERMINAL
259 # define PV_TK		OPT_WIN(WV_TK)
260 # define PV_TMS		OPT_WIN(WV_TMS)
261 #endif
262 #ifdef FEAT_SIGNS
263 # define PV_SCL		OPT_WIN(WV_SCL)
264 #endif
265 
266 /* WV_ and BV_ values get typecasted to this for the "indir" field */
267 typedef enum
268 {
269     PV_NONE = 0,
270     PV_MAXVAL = 0xffff    /* to avoid warnings for value out of range */
271 } idopt_T;
272 
273 /*
274  * Options local to a window have a value local to a buffer and global to all
275  * buffers.  Indicate this by setting "var" to VAR_WIN.
276  */
277 #define VAR_WIN ((char_u *)-1)
278 
279 /*
280  * These are the global values for options which are also local to a buffer.
281  * Only to be used in option.c!
282  */
283 static int	p_ai;
284 static int	p_bin;
285 #ifdef FEAT_MBYTE
286 static int	p_bomb;
287 #endif
288 static char_u	*p_bh;
289 static char_u	*p_bt;
290 static int	p_bl;
291 static int	p_ci;
292 #ifdef FEAT_CINDENT
293 static int	p_cin;
294 static char_u	*p_cink;
295 static char_u	*p_cino;
296 #endif
297 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298 static char_u	*p_cinw;
299 #endif
300 #ifdef FEAT_COMMENTS
301 static char_u	*p_com;
302 #endif
303 #ifdef FEAT_FOLDING
304 static char_u	*p_cms;
305 #endif
306 #ifdef FEAT_INS_EXPAND
307 static char_u	*p_cpt;
308 #endif
309 #ifdef FEAT_COMPL_FUNC
310 static char_u	*p_cfu;
311 static char_u	*p_ofu;
312 #endif
313 static int	p_eol;
314 static int	p_fixeol;
315 static int	p_et;
316 #ifdef FEAT_MBYTE
317 static char_u	*p_fenc;
318 #endif
319 static char_u	*p_ff;
320 static char_u	*p_fo;
321 static char_u	*p_flp;
322 #ifdef FEAT_AUTOCMD
323 static char_u	*p_ft;
324 #endif
325 static long	p_iminsert;
326 static long	p_imsearch;
327 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328 static char_u	*p_inex;
329 #endif
330 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331 static char_u	*p_inde;
332 static char_u	*p_indk;
333 #endif
334 #if defined(FEAT_EVAL)
335 static char_u	*p_fex;
336 #endif
337 static int	p_inf;
338 static char_u	*p_isk;
339 #ifdef FEAT_CRYPT
340 static char_u	*p_key;
341 #endif
342 #ifdef FEAT_LISP
343 static int	p_lisp;
344 #endif
345 static int	p_ml;
346 static int	p_ma;
347 static int	p_mod;
348 static char_u	*p_mps;
349 static char_u	*p_nf;
350 static int	p_pi;
351 #ifdef FEAT_TEXTOBJ
352 static char_u	*p_qe;
353 #endif
354 static int	p_ro;
355 #ifdef FEAT_SMARTINDENT
356 static int	p_si;
357 #endif
358 static int	p_sn;
359 static long	p_sts;
360 #if defined(FEAT_SEARCHPATH)
361 static char_u	*p_sua;
362 #endif
363 static long	p_sw;
364 static int	p_swf;
365 #ifdef FEAT_SYN_HL
366 static long	p_smc;
367 static char_u	*p_syn;
368 #endif
369 #ifdef FEAT_SPELL
370 static char_u	*p_spc;
371 static char_u	*p_spf;
372 static char_u	*p_spl;
373 #endif
374 static long	p_ts;
375 static long	p_tw;
376 static int	p_tx;
377 #ifdef FEAT_PERSISTENT_UNDO
378 static int	p_udf;
379 #endif
380 static long	p_wm;
381 #ifdef FEAT_KEYMAP
382 static char_u	*p_keymap;
383 #endif
384 
385 /* Saved values for when 'bin' is set. */
386 static int	p_et_nobin;
387 static int	p_ml_nobin;
388 static long	p_tw_nobin;
389 static long	p_wm_nobin;
390 
391 /* Saved values for when 'paste' is set */
392 static int	p_ai_nopaste;
393 static int	p_et_nopaste;
394 static long	p_sts_nopaste;
395 static long	p_tw_nopaste;
396 static long	p_wm_nopaste;
397 
398 struct vimoption
399 {
400     char	*fullname;	/* full option name */
401     char	*shortname;	/* permissible abbreviation */
402     long_u	flags;		/* see below */
403     char_u	*var;		/* global option: pointer to variable;
404 				 * window-local option: VAR_WIN;
405 				 * buffer-local option: global value */
406     idopt_T	indir;		/* global option: PV_NONE;
407 				 * local option: indirect option index */
408     char_u	*def_val[2];	/* default values for variable (vi and vim) */
409 #ifdef FEAT_EVAL
410     scid_T	scriptID;	/* script in which the option was last set */
411 # define SCRIPTID_INIT , 0
412 #else
413 # define SCRIPTID_INIT
414 #endif
415 };
416 
417 #define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
418 #define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */
419 
420 /*
421  * Flags
422  */
423 #define P_BOOL		0x01	/* the option is boolean */
424 #define P_NUM		0x02	/* the option is numeric */
425 #define P_STRING	0x04	/* the option is a string */
426 #define P_ALLOCED	0x08	/* the string option is in allocated memory,
427 				   must use free_string_option() when
428 				   assigning new value. Not set if default is
429 				   the same. */
430 #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
431 				   never be used for local or hidden options! */
432 #define P_NODEFAULT	0x40	/* don't set to default value */
433 #define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
434 				    use vim_free() when assigning new value */
435 #define P_WAS_SET	0x100	/* option has been set/reset */
436 #define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
437 #define P_VI_DEF	0x400	/* Use Vi default for Vim */
438 #define P_VIM		0x800	/* Vim option, reset when 'cp' set */
439 
440 				/* when option changed, what to display: */
441 #define P_RSTAT		0x1000	/* redraw status lines */
442 #define P_RWIN		0x2000	/* redraw current window and recompute text */
443 #define P_RBUF		0x4000	/* redraw current buffer and recompute text */
444 #define P_RALL		0x6000	/* redraw all windows */
445 #define P_RCLR		0x7000	/* clear and redraw all */
446 
447 #define P_COMMA		 0x8000	 /* comma separated list */
448 #define P_ONECOMMA	0x18000L /* P_COMMA and cannot have two consecutive
449 				  * commas */
450 #define P_NODUP		0x20000L /* don't allow duplicate strings */
451 #define P_FLAGLIST	0x40000L /* list of single-char flags */
452 
453 #define P_SECURE	0x80000L /* cannot change in modeline or secure mode */
454 #define P_GETTEXT      0x100000L /* expand default value with _() */
455 #define P_NOGLOB       0x200000L /* do not use local value for global vimrc */
456 #define P_NFNAME       0x400000L /* only normal file name chars allowed */
457 #define P_INSECURE     0x800000L /* option was set from a modeline */
458 #define P_PRI_MKRC    0x1000000L /* priority for :mkvimrc (setting option has
459 				    side effects) */
460 #define P_NO_ML       0x2000000L /* not allowed in modeline */
461 #define P_CURSWANT    0x4000000L /* update curswant required; not needed when
462 				  * there is a redraw flag */
463 #define P_NDNAME      0x8000000L /* only normal dir name chars allowed */
464 #define P_RWINONLY   0x10000000L /* only redraw current window */
465 
466 #define ISK_LATIN1  (char_u *)"@,48-57,_,192-255"
467 
468 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469  * for the currency sign. */
470 #if defined(MSWIN)
471 # define ISP_LATIN1 (char_u *)"@,~-255"
472 #else
473 # define ISP_LATIN1 (char_u *)"@,161-255"
474 #endif
475 
476 # define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,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,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
477 
478 /* Default python version for pyx* commands */
479 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
480 # define DEFAULT_PYTHON_VER	0
481 #elif defined(FEAT_PYTHON3)
482 # define DEFAULT_PYTHON_VER	3
483 #elif defined(FEAT_PYTHON)
484 # define DEFAULT_PYTHON_VER	2
485 #else
486 # define DEFAULT_PYTHON_VER	0
487 #endif
488 
489 /*
490  * options[] is initialized here.
491  * The order of the options MUST be alphabetic for ":set all" and findoption().
492  * All option names MUST start with a lowercase letter (for findoption()).
493  * Exception: "t_" options are at the end.
494  * The options with a NULL variable are 'hidden': a set command for them is
495  * ignored and they are not printed.
496  */
497 static struct vimoption options[] =
498 {
499     {"aleph",	    "al",   P_NUM|P_VI_DEF|P_CURSWANT,
500 #ifdef FEAT_RIGHTLEFT
501 			    (char_u *)&p_aleph, PV_NONE,
502 #else
503 			    (char_u *)NULL, PV_NONE,
504 #endif
505 			    {
506 #if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
507 			    (char_u *)128L,
508 #else
509 			    (char_u *)224L,
510 #endif
511 					    (char_u *)0L} SCRIPTID_INIT},
512     {"antialias",   "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
513 #if defined(FEAT_GUI_MAC)
514 			    (char_u *)&p_antialias, PV_NONE,
515 			    {(char_u *)FALSE, (char_u *)FALSE}
516 #else
517 			    (char_u *)NULL, PV_NONE,
518 			    {(char_u *)FALSE, (char_u *)FALSE}
519 #endif
520 			    SCRIPTID_INIT},
521     {"arabic",	    "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
522 #ifdef FEAT_ARABIC
523 			    (char_u *)VAR_WIN, PV_ARAB,
524 #else
525 			    (char_u *)NULL, PV_NONE,
526 #endif
527 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
528     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
529 #ifdef FEAT_ARABIC
530 			    (char_u *)&p_arshape, PV_NONE,
531 #else
532 			    (char_u *)NULL, PV_NONE,
533 #endif
534 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
535     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
536 #ifdef FEAT_RIGHTLEFT
537 			    (char_u *)&p_ari, PV_NONE,
538 #else
539 			    (char_u *)NULL, PV_NONE,
540 #endif
541 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
542     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
543 #ifdef FEAT_FKMAP
544 			    (char_u *)&p_altkeymap, PV_NONE,
545 #else
546 			    (char_u *)NULL, PV_NONE,
547 #endif
548 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
549     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
550 #if defined(FEAT_MBYTE)
551 			    (char_u *)&p_ambw, PV_NONE,
552 			    {(char_u *)"single", (char_u *)0L}
553 #else
554 			    (char_u *)NULL, PV_NONE,
555 			    {(char_u *)0L, (char_u *)0L}
556 #endif
557 			    SCRIPTID_INIT},
558     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
559 #ifdef FEAT_AUTOCHDIR
560 			    (char_u *)&p_acd, PV_NONE,
561 			    {(char_u *)FALSE, (char_u *)0L}
562 #else
563 			    (char_u *)NULL, PV_NONE,
564 			    {(char_u *)0L, (char_u *)0L}
565 #endif
566 			    SCRIPTID_INIT},
567     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
568 			    (char_u *)&p_ai, PV_AI,
569 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
570     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
571 			    (char_u *)NULL, PV_NONE,
572 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
573     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
574 			    (char_u *)&p_ar, PV_AR,
575 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
576     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
577 			    (char_u *)&p_aw, PV_NONE,
578 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
579     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
580 			    (char_u *)&p_awa, PV_NONE,
581 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
582     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
583 			    (char_u *)&p_bg, PV_NONE,
584 			    {
585 #if (defined(WIN3264)) && !defined(FEAT_GUI)
586 			    (char_u *)"dark",
587 #else
588 			    (char_u *)"light",
589 #endif
590 					    (char_u *)0L} SCRIPTID_INIT},
591     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
592 			    (char_u *)&p_bs, PV_NONE,
593 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
594     {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
595 			    (char_u *)&p_bk, PV_NONE,
596 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
597     {"backupcopy",  "bkc",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
598 			    (char_u *)&p_bkc, PV_BKC,
599 #ifdef UNIX
600 			    {(char_u *)"yes", (char_u *)"auto"}
601 #else
602 			    {(char_u *)"auto", (char_u *)"auto"}
603 #endif
604 			    SCRIPTID_INIT},
605     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 							    |P_NODUP|P_SECURE,
607 			    (char_u *)&p_bdir, PV_NONE,
608 			    {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
609     {"backupext",   "bex",  P_STRING|P_VI_DEF|P_NFNAME,
610 			    (char_u *)&p_bex, PV_NONE,
611 			    {
612 #ifdef VMS
613 			    (char_u *)"_",
614 #else
615 			    (char_u *)"~",
616 #endif
617 					    (char_u *)0L} SCRIPTID_INIT},
618     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_ONECOMMA,
619 #ifdef FEAT_WILDIGN
620 			    (char_u *)&p_bsk, PV_NONE,
621 			    {(char_u *)"", (char_u *)0L}
622 #else
623 			    (char_u *)NULL, PV_NONE,
624 			    {(char_u *)0L, (char_u *)0L}
625 #endif
626 			    SCRIPTID_INIT},
627     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
628 #ifdef FEAT_BEVAL
629 			    (char_u *)&p_bdlay, PV_NONE,
630 			    {(char_u *)600L, (char_u *)0L}
631 #else
632 			    (char_u *)NULL, PV_NONE,
633 			    {(char_u *)0L, (char_u *)0L}
634 #endif
635 			    SCRIPTID_INIT},
636     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
637 #ifdef FEAT_BEVAL
638 			    (char_u *)&p_beval, PV_NONE,
639 			    {(char_u *)FALSE, (char_u *)0L}
640 #else
641 			    (char_u *)NULL, PV_NONE,
642 			    {(char_u *)0L, (char_u *)0L}
643 #endif
644 			    SCRIPTID_INIT},
645     {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 			    (char_u *)&p_bexpr, PV_BEXPR,
648 			    {(char_u *)"", (char_u *)0L}
649 #else
650 			    (char_u *)NULL, PV_NONE,
651 			    {(char_u *)0L, (char_u *)0L}
652 #endif
653 			    SCRIPTID_INIT},
654     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
655 			    (char_u *)NULL, PV_NONE,
656 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
657     {"belloff",      "bo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 			    (char_u *)&p_bo, PV_NONE,
659 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
660     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
661 			    (char_u *)&p_bin, PV_BIN,
662 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
663     {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
664 			    (char_u *)NULL, PV_NONE,
665 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
666     {"bomb",	    NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667 #ifdef FEAT_MBYTE
668 			    (char_u *)&p_bomb, PV_BOMB,
669 #else
670 			    (char_u *)NULL, PV_NONE,
671 #endif
672 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
673     {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674 #ifdef FEAT_LINEBREAK
675 			    (char_u *)&p_breakat, PV_NONE,
676 			    {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677 #else
678 			    (char_u *)NULL, PV_NONE,
679 			    {(char_u *)0L, (char_u *)0L}
680 #endif
681 			    SCRIPTID_INIT},
682     {"breakindent",   "bri",  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683 #ifdef FEAT_LINEBREAK
684 			    (char_u *)VAR_WIN, PV_BRI,
685 			    {(char_u *)FALSE, (char_u *)0L}
686 #else
687 			    (char_u *)NULL, PV_NONE,
688 			    {(char_u *)0L, (char_u *)0L}
689 #endif
690 			    SCRIPTID_INIT},
691     {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 						  |P_ONECOMMA|P_NODUP,
693 #ifdef FEAT_LINEBREAK
694 			    (char_u *)VAR_WIN, PV_BRIOPT,
695 			    {(char_u *)"", (char_u *)NULL}
696 #else
697 			    (char_u *)NULL, PV_NONE,
698 			    {(char_u *)"", (char_u *)NULL}
699 #endif
700 			    SCRIPTID_INIT},
701     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
702 #ifdef FEAT_BROWSE
703 			    (char_u *)&p_bsdir, PV_NONE,
704 			    {(char_u *)"last", (char_u *)0L}
705 #else
706 			    (char_u *)NULL, PV_NONE,
707 			    {(char_u *)0L, (char_u *)0L}
708 #endif
709 			    SCRIPTID_INIT},
710     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
711 			    (char_u *)&p_bh, PV_BH,
712 			    {(char_u *)"", (char_u *)0L}
713 			    SCRIPTID_INIT},
714     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
715 			    (char_u *)&p_bl, PV_BL,
716 			    {(char_u *)1L, (char_u *)0L}
717 			    SCRIPTID_INIT},
718     {"buftype",	    "bt",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
719 			    (char_u *)&p_bt, PV_BT,
720 			    {(char_u *)"", (char_u *)0L}
721 			    SCRIPTID_INIT},
722     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
723 #ifdef FEAT_MBYTE
724 			    (char_u *)&p_cmp, PV_NONE,
725 			    {(char_u *)"internal,keepascii", (char_u *)0L}
726 #else
727 			    (char_u *)NULL, PV_NONE,
728 			    {(char_u *)0L, (char_u *)0L}
729 #endif
730 			    SCRIPTID_INIT},
731     {"cdpath",	    "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
732 #ifdef FEAT_SEARCHPATH
733 			    (char_u *)&p_cdpath, PV_NONE,
734 			    {(char_u *)",,", (char_u *)0L}
735 #else
736 			    (char_u *)NULL, PV_NONE,
737 			    {(char_u *)0L, (char_u *)0L}
738 #endif
739 			    SCRIPTID_INIT},
740     {"cedit",	    NULL,   P_STRING,
741 #ifdef FEAT_CMDWIN
742 			    (char_u *)&p_cedit, PV_NONE,
743 			    {(char_u *)"", (char_u *)CTRL_F_STR}
744 #else
745 			    (char_u *)NULL, PV_NONE,
746 			    {(char_u *)0L, (char_u *)0L}
747 #endif
748 			    SCRIPTID_INIT},
749     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
750 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
751 			    (char_u *)&p_ccv, PV_NONE,
752 			    {(char_u *)"", (char_u *)0L}
753 #else
754 			    (char_u *)NULL, PV_NONE,
755 			    {(char_u *)0L, (char_u *)0L}
756 #endif
757 			    SCRIPTID_INIT},
758     {"cindent",	    "cin",  P_BOOL|P_VI_DEF|P_VIM,
759 #ifdef FEAT_CINDENT
760 			    (char_u *)&p_cin, PV_CIN,
761 #else
762 			    (char_u *)NULL, PV_NONE,
763 #endif
764 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
765     {"cinkeys",	    "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
766 #ifdef FEAT_CINDENT
767 			    (char_u *)&p_cink, PV_CINK,
768 			    {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
769 #else
770 			    (char_u *)NULL, PV_NONE,
771 			    {(char_u *)0L, (char_u *)0L}
772 #endif
773 			    SCRIPTID_INIT},
774     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
775 #ifdef FEAT_CINDENT
776 			    (char_u *)&p_cino, PV_CINO,
777 #else
778 			    (char_u *)NULL, PV_NONE,
779 #endif
780 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
781     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
782 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 			    (char_u *)&p_cinw, PV_CINW,
784 			    {(char_u *)"if,else,while,do,for,switch",
785 				(char_u *)0L}
786 #else
787 			    (char_u *)NULL, PV_NONE,
788 			    {(char_u *)0L, (char_u *)0L}
789 #endif
790 			    SCRIPTID_INIT},
791     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
792 #ifdef FEAT_CLIPBOARD
793 			    (char_u *)&p_cb, PV_NONE,
794 # ifdef FEAT_XCLIPBOARD
795 			    {(char_u *)"autoselect,exclude:cons\\|linux",
796 							       (char_u *)0L}
797 # else
798 			    {(char_u *)"", (char_u *)0L}
799 # endif
800 #else
801 			    (char_u *)NULL, PV_NONE,
802 			    {(char_u *)"", (char_u *)0L}
803 #endif
804 			    SCRIPTID_INIT},
805     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
806 			    (char_u *)&p_ch, PV_NONE,
807 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
808     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809 #ifdef FEAT_CMDWIN
810 			    (char_u *)&p_cwh, PV_NONE,
811 #else
812 			    (char_u *)NULL, PV_NONE,
813 #endif
814 			    {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
815     {"colorcolumn", "cc",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
816 #ifdef FEAT_SYN_HL
817 			    (char_u *)VAR_WIN, PV_CC,
818 #else
819 			    (char_u *)NULL, PV_NONE,
820 #endif
821 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
822     {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 			    (char_u *)&Columns, PV_NONE,
824 			    {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
825     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 							  |P_NODUP|P_CURSWANT,
827 #ifdef FEAT_COMMENTS
828 			    (char_u *)&p_com, PV_COM,
829 			    {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 				(char_u *)0L}
831 #else
832 			    (char_u *)NULL, PV_NONE,
833 			    {(char_u *)0L, (char_u *)0L}
834 #endif
835 			    SCRIPTID_INIT},
836     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
837 #ifdef FEAT_FOLDING
838 			    (char_u *)&p_cms, PV_CMS,
839 			    {(char_u *)"/*%s*/", (char_u *)0L}
840 #else
841 			    (char_u *)NULL, PV_NONE,
842 			    {(char_u *)0L, (char_u *)0L}
843 #endif
844 			    SCRIPTID_INIT},
845 			    /* P_PRI_MKRC isn't needed here, optval_default()
846 			     * always returns TRUE for 'compatible' */
847     {"compatible",  "cp",   P_BOOL|P_RALL,
848 			    (char_u *)&p_cp, PV_NONE,
849 			    {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
850     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
851 #ifdef FEAT_INS_EXPAND
852 			    (char_u *)&p_cpt, PV_CPT,
853 			    {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854 #else
855 			    (char_u *)NULL, PV_NONE,
856 			    {(char_u *)0L, (char_u *)0L}
857 #endif
858 			    SCRIPTID_INIT},
859     {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
860 #ifdef FEAT_CONCEAL
861 			    (char_u *)VAR_WIN, PV_COCU,
862 			    {(char_u *)"", (char_u *)NULL}
863 #else
864 			    (char_u *)NULL, PV_NONE,
865 			    {(char_u *)NULL, (char_u *)0L}
866 #endif
867 			    SCRIPTID_INIT},
868     {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869 #ifdef FEAT_CONCEAL
870 			    (char_u *)VAR_WIN, PV_COLE,
871 #else
872 			    (char_u *)NULL, PV_NONE,
873 #endif
874 			    {(char_u *)0L, (char_u *)0L}
875 			    SCRIPTID_INIT},
876     {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877 #ifdef FEAT_COMPL_FUNC
878 			    (char_u *)&p_cfu, PV_CFU,
879 			    {(char_u *)"", (char_u *)0L}
880 #else
881 			    (char_u *)NULL, PV_NONE,
882 			    {(char_u *)0L, (char_u *)0L}
883 #endif
884 			    SCRIPTID_INIT},
885     {"completeopt",   "cot",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
886 #ifdef FEAT_INS_EXPAND
887 			    (char_u *)&p_cot, PV_NONE,
888 			    {(char_u *)"menu,preview", (char_u *)0L}
889 #else
890 			    (char_u *)NULL, PV_NONE,
891 			    {(char_u *)0L, (char_u *)0L}
892 #endif
893 			    SCRIPTID_INIT},
894     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
895 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 			    (char_u *)&p_confirm, PV_NONE,
897 #else
898 			    (char_u *)NULL, PV_NONE,
899 #endif
900 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
901     {"conskey",	    "consk",P_BOOL|P_VI_DEF,
902 			    (char_u *)NULL, PV_NONE,
903 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
904     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
905 			    (char_u *)&p_ci, PV_CI,
906 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
907     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 			    (char_u *)&p_cpo, PV_NONE,
909 			    {(char_u *)CPO_VI, (char_u *)CPO_VIM}
910 			    SCRIPTID_INIT},
911     {"cryptmethod", "cm",   P_STRING|P_ALLOCED|P_VI_DEF,
912 #ifdef FEAT_CRYPT
913 			    (char_u *)&p_cm, PV_CM,
914 			    {(char_u *)"zip", (char_u *)0L}
915 #else
916 			    (char_u *)NULL, PV_NONE,
917 			    {(char_u *)0L, (char_u *)0L}
918 #endif
919 			    SCRIPTID_INIT},
920     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921 #ifdef FEAT_CSCOPE
922 			    (char_u *)&p_cspc, PV_NONE,
923 #else
924 			    (char_u *)NULL, PV_NONE,
925 #endif
926 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
927     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928 #ifdef FEAT_CSCOPE
929 			    (char_u *)&p_csprg, PV_NONE,
930 			    {(char_u *)"cscope", (char_u *)0L}
931 #else
932 			    (char_u *)NULL, PV_NONE,
933 			    {(char_u *)0L, (char_u *)0L}
934 #endif
935 			    SCRIPTID_INIT},
936     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
937 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 			    (char_u *)&p_csqf, PV_NONE,
939 			    {(char_u *)"", (char_u *)0L}
940 #else
941 			    (char_u *)NULL, PV_NONE,
942 			    {(char_u *)0L, (char_u *)0L}
943 #endif
944 			    SCRIPTID_INIT},
945     {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946 #ifdef FEAT_CSCOPE
947 			    (char_u *)&p_csre, PV_NONE,
948 #else
949 			    (char_u *)NULL, PV_NONE,
950 #endif
951 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
952     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
953 #ifdef FEAT_CSCOPE
954 			    (char_u *)&p_cst, PV_NONE,
955 #else
956 			    (char_u *)NULL, PV_NONE,
957 #endif
958 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
959     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960 #ifdef FEAT_CSCOPE
961 			    (char_u *)&p_csto, PV_NONE,
962 #else
963 			    (char_u *)NULL, PV_NONE,
964 #endif
965 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
966     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967 #ifdef FEAT_CSCOPE
968 			    (char_u *)&p_csverbose, PV_NONE,
969 #else
970 			    (char_u *)NULL, PV_NONE,
971 #endif
972 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
973     {"cursorbind",  "crb",  P_BOOL|P_VI_DEF,
974 #ifdef FEAT_CURSORBIND
975 			    (char_u *)VAR_WIN, PV_CRBIND,
976 #else
977 			    (char_u *)NULL, PV_NONE,
978 #endif
979 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
980     {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
981 #ifdef FEAT_SYN_HL
982 			    (char_u *)VAR_WIN, PV_CUC,
983 #else
984 			    (char_u *)NULL, PV_NONE,
985 #endif
986 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
987     {"cursorline",   "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
988 #ifdef FEAT_SYN_HL
989 			    (char_u *)VAR_WIN, PV_CUL,
990 #else
991 			    (char_u *)NULL, PV_NONE,
992 #endif
993 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
994     {"debug",	    NULL,   P_STRING|P_VI_DEF,
995 			    (char_u *)&p_debug, PV_NONE,
996 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
997     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
998 #ifdef FEAT_FIND_ID
999 			    (char_u *)&p_def, PV_DEF,
1000 			    {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
1001 #else
1002 			    (char_u *)NULL, PV_NONE,
1003 			    {(char_u *)NULL, (char_u *)0L}
1004 #endif
1005 			    SCRIPTID_INIT},
1006     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
1007 #ifdef FEAT_MBYTE
1008 			    (char_u *)&p_deco, PV_NONE,
1009 #else
1010 			    (char_u *)NULL, PV_NONE,
1011 #endif
1012 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1013     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
1014 #ifdef FEAT_INS_EXPAND
1015 			    (char_u *)&p_dict, PV_DICT,
1016 #else
1017 			    (char_u *)NULL, PV_NONE,
1018 #endif
1019 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1020     {"diff",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1021 #ifdef FEAT_DIFF
1022 			    (char_u *)VAR_WIN, PV_DIFF,
1023 #else
1024 			    (char_u *)NULL, PV_NONE,
1025 #endif
1026 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1027     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
1028 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1029 			    (char_u *)&p_dex, PV_NONE,
1030 			    {(char_u *)"", (char_u *)0L}
1031 #else
1032 			    (char_u *)NULL, PV_NONE,
1033 			    {(char_u *)0L, (char_u *)0L}
1034 #endif
1035 			    SCRIPTID_INIT},
1036     {"diffopt",	    "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1037 								     |P_NODUP,
1038 #ifdef FEAT_DIFF
1039 			    (char_u *)&p_dip, PV_NONE,
1040 			    {(char_u *)"filler", (char_u *)NULL}
1041 #else
1042 			    (char_u *)NULL, PV_NONE,
1043 			    {(char_u *)"", (char_u *)NULL}
1044 #endif
1045 			    SCRIPTID_INIT},
1046     {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
1047 #ifdef FEAT_DIGRAPHS
1048 			    (char_u *)&p_dg, PV_NONE,
1049 #else
1050 			    (char_u *)NULL, PV_NONE,
1051 #endif
1052 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1053     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1054 							    |P_NODUP|P_SECURE,
1055 			    (char_u *)&p_dir, PV_NONE,
1056 			    {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
1057     {"display",	    "dy",   P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
1058 			    (char_u *)&p_dy, PV_NONE,
1059 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1060     {"eadirection", "ead",  P_STRING|P_VI_DEF,
1061 			    (char_u *)&p_ead, PV_NONE,
1062 			    {(char_u *)"both", (char_u *)0L}
1063 			    SCRIPTID_INIT},
1064     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
1065 			    (char_u *)&p_ed, PV_NONE,
1066 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1067     {"emoji",  "emo",	    P_BOOL|P_VI_DEF|P_RCLR,
1068 #if defined(FEAT_MBYTE)
1069 			    (char_u *)&p_emoji, PV_NONE,
1070 			    {(char_u *)TRUE, (char_u *)0L}
1071 #else
1072 			    (char_u *)NULL, PV_NONE,
1073 			    {(char_u *)0L, (char_u *)0L}
1074 #endif
1075 			    SCRIPTID_INIT},
1076     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
1077 #ifdef FEAT_MBYTE
1078 			    (char_u *)&p_enc, PV_NONE,
1079 			    {(char_u *)ENC_DFLT, (char_u *)0L}
1080 #else
1081 			    (char_u *)NULL, PV_NONE,
1082 			    {(char_u *)0L, (char_u *)0L}
1083 #endif
1084 			    SCRIPTID_INIT},
1085     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1086 			    (char_u *)&p_eol, PV_EOL,
1087 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1088     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
1089 			    (char_u *)&p_ea, PV_NONE,
1090 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1091     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1092 			    (char_u *)&p_ep, PV_EP,
1093 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1094     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
1095 			    (char_u *)&p_eb, PV_NONE,
1096 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1097     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1098 #ifdef FEAT_QUICKFIX
1099 			    (char_u *)&p_ef, PV_NONE,
1100 			    {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1101 #else
1102 			    (char_u *)NULL, PV_NONE,
1103 			    {(char_u *)NULL, (char_u *)0L}
1104 #endif
1105 			    SCRIPTID_INIT},
1106     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1107 #ifdef FEAT_QUICKFIX
1108 			    (char_u *)&p_efm, PV_EFM,
1109 			    {(char_u *)DFLT_EFM, (char_u *)0L}
1110 #else
1111 			    (char_u *)NULL, PV_NONE,
1112 			    {(char_u *)NULL, (char_u *)0L}
1113 #endif
1114 			    SCRIPTID_INIT},
1115     {"esckeys",	    "ek",   P_BOOL|P_VIM,
1116 			    (char_u *)&p_ek, PV_NONE,
1117 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1118     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1119 #ifdef FEAT_AUTOCMD
1120 			    (char_u *)&p_ei, PV_NONE,
1121 #else
1122 			    (char_u *)NULL, PV_NONE,
1123 #endif
1124 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1125     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
1126 			    (char_u *)&p_et, PV_ET,
1127 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1128     {"exrc",	    "ex",   P_BOOL|P_VI_DEF|P_SECURE,
1129 			    (char_u *)&p_exrc, PV_NONE,
1130 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1131     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1132 								   |P_NO_MKRC,
1133 #ifdef FEAT_MBYTE
1134 			    (char_u *)&p_fenc, PV_FENC,
1135 			    {(char_u *)"", (char_u *)0L}
1136 #else
1137 			    (char_u *)NULL, PV_NONE,
1138 			    {(char_u *)0L, (char_u *)0L}
1139 #endif
1140 			    SCRIPTID_INIT},
1141     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
1142 #ifdef FEAT_MBYTE
1143 			    (char_u *)&p_fencs, PV_NONE,
1144 			    {(char_u *)"ucs-bom", (char_u *)0L}
1145 #else
1146 			    (char_u *)NULL, PV_NONE,
1147 			    {(char_u *)0L, (char_u *)0L}
1148 #endif
1149 			    SCRIPTID_INIT},
1150     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1151 								  |P_CURSWANT,
1152 			    (char_u *)&p_ff, PV_FF,
1153 			    {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
1154     {"fileformats", "ffs",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
1155 			    (char_u *)&p_ffs, PV_NONE,
1156 			    {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1157 			    SCRIPTID_INIT},
1158     {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1159 			    (char_u *)&p_fic, PV_NONE,
1160 			    {
1161 #ifdef CASE_INSENSITIVE_FILENAME
1162 				    (char_u *)TRUE,
1163 #else
1164 				    (char_u *)FALSE,
1165 #endif
1166 					(char_u *)0L} SCRIPTID_INIT},
1167     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1168 #ifdef FEAT_AUTOCMD
1169 			    (char_u *)&p_ft, PV_FT,
1170 			    {(char_u *)"", (char_u *)0L}
1171 #else
1172 			    (char_u *)NULL, PV_NONE,
1173 			    {(char_u *)0L, (char_u *)0L}
1174 #endif
1175 			    SCRIPTID_INIT},
1176     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1177 			    (char_u *)&p_fcs, PV_NONE,
1178 			    {(char_u *)"vert:|,fold:-", (char_u *)0L}
1179 			    SCRIPTID_INIT},
1180     {"fixendofline",  "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1181 			    (char_u *)&p_fixeol, PV_FIXEOL,
1182 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1183     {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
1184 #ifdef FEAT_FKMAP
1185 			    (char_u *)&p_fkmap, PV_NONE,
1186 #else
1187 			    (char_u *)NULL, PV_NONE,
1188 #endif
1189 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1190     {"flash",	    "fl",   P_BOOL|P_VI_DEF,
1191 			    (char_u *)NULL, PV_NONE,
1192 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1193     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
1194 #ifdef FEAT_FOLDING
1195 			    (char_u *)&p_fcl, PV_NONE,
1196 			    {(char_u *)"", (char_u *)0L}
1197 #else
1198 			    (char_u *)NULL, PV_NONE,
1199 			    {(char_u *)NULL, (char_u *)0L}
1200 #endif
1201 			    SCRIPTID_INIT},
1202     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
1203 #ifdef FEAT_FOLDING
1204 			    (char_u *)VAR_WIN, PV_FDC,
1205 			    {(char_u *)FALSE, (char_u *)0L}
1206 #else
1207 			    (char_u *)NULL, PV_NONE,
1208 			    {(char_u *)NULL, (char_u *)0L}
1209 #endif
1210 			    SCRIPTID_INIT},
1211     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
1212 #ifdef FEAT_FOLDING
1213 			    (char_u *)VAR_WIN, PV_FEN,
1214 			    {(char_u *)TRUE, (char_u *)0L}
1215 #else
1216 			    (char_u *)NULL, PV_NONE,
1217 			    {(char_u *)NULL, (char_u *)0L}
1218 #endif
1219 			    SCRIPTID_INIT},
1220     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1221 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1222 			    (char_u *)VAR_WIN, PV_FDE,
1223 			    {(char_u *)"0", (char_u *)NULL}
1224 #else
1225 			    (char_u *)NULL, PV_NONE,
1226 			    {(char_u *)NULL, (char_u *)0L}
1227 #endif
1228 			    SCRIPTID_INIT},
1229     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1230 #ifdef FEAT_FOLDING
1231 			    (char_u *)VAR_WIN, PV_FDI,
1232 			    {(char_u *)"#", (char_u *)NULL}
1233 #else
1234 			    (char_u *)NULL, PV_NONE,
1235 			    {(char_u *)NULL, (char_u *)0L}
1236 #endif
1237 			    SCRIPTID_INIT},
1238     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
1239 #ifdef FEAT_FOLDING
1240 			    (char_u *)VAR_WIN, PV_FDL,
1241 			    {(char_u *)0L, (char_u *)0L}
1242 #else
1243 			    (char_u *)NULL, PV_NONE,
1244 			    {(char_u *)NULL, (char_u *)0L}
1245 #endif
1246 			    SCRIPTID_INIT},
1247     {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
1248 #ifdef FEAT_FOLDING
1249 			    (char_u *)&p_fdls, PV_NONE,
1250 			    {(char_u *)-1L, (char_u *)0L}
1251 #else
1252 			    (char_u *)NULL, PV_NONE,
1253 			    {(char_u *)NULL, (char_u *)0L}
1254 #endif
1255 			    SCRIPTID_INIT},
1256     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1257 						    P_RWIN|P_ONECOMMA|P_NODUP,
1258 #ifdef FEAT_FOLDING
1259 			    (char_u *)VAR_WIN, PV_FMR,
1260 			    {(char_u *)"{{{,}}}", (char_u *)NULL}
1261 #else
1262 			    (char_u *)NULL, PV_NONE,
1263 			    {(char_u *)NULL, (char_u *)0L}
1264 #endif
1265 			    SCRIPTID_INIT},
1266     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1267 #ifdef FEAT_FOLDING
1268 			    (char_u *)VAR_WIN, PV_FDM,
1269 			    {(char_u *)"manual", (char_u *)NULL}
1270 #else
1271 			    (char_u *)NULL, PV_NONE,
1272 			    {(char_u *)NULL, (char_u *)0L}
1273 #endif
1274 			    SCRIPTID_INIT},
1275     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
1276 #ifdef FEAT_FOLDING
1277 			    (char_u *)VAR_WIN, PV_FML,
1278 			    {(char_u *)1L, (char_u *)0L}
1279 #else
1280 			    (char_u *)NULL, PV_NONE,
1281 			    {(char_u *)NULL, (char_u *)0L}
1282 #endif
1283 			    SCRIPTID_INIT},
1284     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
1285 #ifdef FEAT_FOLDING
1286 			    (char_u *)VAR_WIN, PV_FDN,
1287 			    {(char_u *)20L, (char_u *)0L}
1288 #else
1289 			    (char_u *)NULL, PV_NONE,
1290 			    {(char_u *)NULL, (char_u *)0L}
1291 #endif
1292 			    SCRIPTID_INIT},
1293     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1294 #ifdef FEAT_FOLDING
1295 			    (char_u *)&p_fdo, PV_NONE,
1296 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1297 						 (char_u *)0L}
1298 #else
1299 			    (char_u *)NULL, PV_NONE,
1300 			    {(char_u *)NULL, (char_u *)0L}
1301 #endif
1302 			    SCRIPTID_INIT},
1303     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1304 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1305 			    (char_u *)VAR_WIN, PV_FDT,
1306 			    {(char_u *)"foldtext()", (char_u *)NULL}
1307 #else
1308 			    (char_u *)NULL, PV_NONE,
1309 			    {(char_u *)NULL, (char_u *)0L}
1310 #endif
1311 			    SCRIPTID_INIT},
1312     {"formatexpr", "fex",   P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1313 #ifdef FEAT_EVAL
1314 			    (char_u *)&p_fex, PV_FEX,
1315 			    {(char_u *)"", (char_u *)0L}
1316 #else
1317 			    (char_u *)NULL, PV_NONE,
1318 			    {(char_u *)0L, (char_u *)0L}
1319 #endif
1320 			    SCRIPTID_INIT},
1321     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1322 			    (char_u *)&p_fo, PV_FO,
1323 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1324 			    SCRIPTID_INIT},
1325     {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1326 			    (char_u *)&p_flp, PV_FLP,
1327 			    {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1328 						 (char_u *)0L} SCRIPTID_INIT},
1329     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1330 			    (char_u *)&p_fp, PV_FP,
1331 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1332     {"fsync",       "fs",   P_BOOL|P_SECURE|P_VI_DEF,
1333 #ifdef HAVE_FSYNC
1334 			    (char_u *)&p_fs, PV_NONE,
1335 			    {(char_u *)TRUE, (char_u *)0L}
1336 #else
1337 			    (char_u *)NULL, PV_NONE,
1338 			    {(char_u *)FALSE, (char_u *)0L}
1339 #endif
1340 			    SCRIPTID_INIT},
1341     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
1342 			    (char_u *)&p_gd, PV_NONE,
1343 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1344     {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
1345 			    (char_u *)NULL, PV_NONE,
1346 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1347     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1348 #ifdef FEAT_QUICKFIX
1349 			    (char_u *)&p_gefm, PV_NONE,
1350 			    {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
1351 #else
1352 			    (char_u *)NULL, PV_NONE,
1353 			    {(char_u *)NULL, (char_u *)0L}
1354 #endif
1355 			    SCRIPTID_INIT},
1356     {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1357 #ifdef FEAT_QUICKFIX
1358 			    (char_u *)&p_gp, PV_GP,
1359 			    {
1360 # ifdef WIN3264
1361 			    /* may be changed to "grep -n" in os_win32.c */
1362 			    (char_u *)"findstr /n",
1363 # else
1364 #  ifdef UNIX
1365 			    /* Add an extra file name so that grep will always
1366 			     * insert a file name in the match line. */
1367 			    (char_u *)"grep -n $* /dev/null",
1368 #  else
1369 #   ifdef VMS
1370 			    (char_u *)"SEARCH/NUMBERS ",
1371 #   else
1372 			    (char_u *)"grep -n ",
1373 #   endif
1374 #  endif
1375 # endif
1376 			    (char_u *)0L}
1377 #else
1378 			    (char_u *)NULL, PV_NONE,
1379 			    {(char_u *)NULL, (char_u *)0L}
1380 #endif
1381 			    SCRIPTID_INIT},
1382     {"guicursor",    "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1383 #ifdef CURSOR_SHAPE
1384 			    (char_u *)&p_guicursor, PV_NONE,
1385 			    {
1386 # ifdef FEAT_GUI
1387 				(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",
1388 # else	/* Win32 console */
1389 				(char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1390 # endif
1391 				    (char_u *)0L}
1392 #else
1393 			    (char_u *)NULL, PV_NONE,
1394 			    {(char_u *)NULL, (char_u *)0L}
1395 #endif
1396 			    SCRIPTID_INIT},
1397     {"guifont",	    "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1398 #ifdef FEAT_GUI
1399 			    (char_u *)&p_guifont, PV_NONE,
1400 			    {(char_u *)"", (char_u *)0L}
1401 #else
1402 			    (char_u *)NULL, PV_NONE,
1403 			    {(char_u *)NULL, (char_u *)0L}
1404 #endif
1405 			    SCRIPTID_INIT},
1406     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
1407 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1408 			    (char_u *)&p_guifontset, PV_NONE,
1409 			    {(char_u *)"", (char_u *)0L}
1410 #else
1411 			    (char_u *)NULL, PV_NONE,
1412 			    {(char_u *)NULL, (char_u *)0L}
1413 #endif
1414 			    SCRIPTID_INIT},
1415     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1416 #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1417 			    (char_u *)&p_guifontwide, PV_NONE,
1418 			    {(char_u *)"", (char_u *)0L}
1419 #else
1420 			    (char_u *)NULL, PV_NONE,
1421 			    {(char_u *)NULL, (char_u *)0L}
1422 #endif
1423 			    SCRIPTID_INIT},
1424     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
1425 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1426 			    (char_u *)&p_ghr, PV_NONE,
1427 #else
1428 			    (char_u *)NULL, PV_NONE,
1429 #endif
1430 			    {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
1431     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1432 #if defined(FEAT_GUI)
1433 			    (char_u *)&p_go, PV_NONE,
1434 # if defined(UNIX) && !defined(FEAT_GUI_MAC)
1435 			    {(char_u *)"aegimrLtT", (char_u *)0L}
1436 # else
1437 			    {(char_u *)"egmrLtT", (char_u *)0L}
1438 # endif
1439 #else
1440 			    (char_u *)NULL, PV_NONE,
1441 			    {(char_u *)NULL, (char_u *)0L}
1442 #endif
1443 			    SCRIPTID_INIT},
1444     {"guipty",	    NULL,   P_BOOL|P_VI_DEF,
1445 #if defined(FEAT_GUI)
1446 			    (char_u *)&p_guipty, PV_NONE,
1447 #else
1448 			    (char_u *)NULL, PV_NONE,
1449 #endif
1450 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1451     {"guitablabel",  "gtl", P_STRING|P_VI_DEF|P_RWIN,
1452 #if defined(FEAT_GUI_TABLINE)
1453 			    (char_u *)&p_gtl, PV_NONE,
1454 			    {(char_u *)"", (char_u *)0L}
1455 #else
1456 			    (char_u *)NULL, PV_NONE,
1457 			    {(char_u *)NULL, (char_u *)0L}
1458 #endif
1459 			    SCRIPTID_INIT},
1460     {"guitabtooltip",  "gtt", P_STRING|P_VI_DEF|P_RWIN,
1461 #if defined(FEAT_GUI_TABLINE)
1462 			    (char_u *)&p_gtt, PV_NONE,
1463 			    {(char_u *)"", (char_u *)0L}
1464 #else
1465 			    (char_u *)NULL, PV_NONE,
1466 			    {(char_u *)NULL, (char_u *)0L}
1467 #endif
1468 			    SCRIPTID_INIT},
1469     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
1470 			    (char_u *)NULL, PV_NONE,
1471 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
1472     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1473 			    (char_u *)&p_hf, PV_NONE,
1474 			    {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1475 			    SCRIPTID_INIT},
1476     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
1477 			    (char_u *)&p_hh, PV_NONE,
1478 			    {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
1479     {"helplang",    "hlg",  P_STRING|P_VI_DEF|P_ONECOMMA,
1480 #ifdef FEAT_MULTI_LANG
1481 			    (char_u *)&p_hlg, PV_NONE,
1482 			    {(char_u *)"", (char_u *)0L}
1483 #else
1484 			    (char_u *)NULL, PV_NONE,
1485 			    {(char_u *)0L, (char_u *)0L}
1486 #endif
1487 			    SCRIPTID_INIT},
1488     {"hidden",	    "hid",  P_BOOL|P_VI_DEF,
1489 			    (char_u *)&p_hid, PV_NONE,
1490 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1491     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1492 			    (char_u *)&p_hl, PV_NONE,
1493 			    {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1494 			    SCRIPTID_INIT},
1495     {"history",	    "hi",   P_NUM|P_VIM,
1496 			    (char_u *)&p_hi, PV_NONE,
1497 			    {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
1498     {"hkmap",	    "hk",   P_BOOL|P_VI_DEF|P_VIM,
1499 #ifdef FEAT_RIGHTLEFT
1500 			    (char_u *)&p_hkmap, PV_NONE,
1501 #else
1502 			    (char_u *)NULL, PV_NONE,
1503 #endif
1504 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1505     {"hkmapp",	    "hkp",  P_BOOL|P_VI_DEF|P_VIM,
1506 #ifdef FEAT_RIGHTLEFT
1507 			    (char_u *)&p_hkmapp, PV_NONE,
1508 #else
1509 			    (char_u *)NULL, PV_NONE,
1510 #endif
1511 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1512     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1513 			    (char_u *)&p_hls, PV_NONE,
1514 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1515     {"icon",	    NULL,   P_BOOL|P_VI_DEF,
1516 #ifdef FEAT_TITLE
1517 			    (char_u *)&p_icon, PV_NONE,
1518 #else
1519 			    (char_u *)NULL, PV_NONE,
1520 #endif
1521 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1522     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
1523 #ifdef FEAT_TITLE
1524 			    (char_u *)&p_iconstring, PV_NONE,
1525 #else
1526 			    (char_u *)NULL, PV_NONE,
1527 #endif
1528 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1529     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
1530 			    (char_u *)&p_ic, PV_NONE,
1531 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1532     {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1533 # if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1534 			    (char_u *)&p_imaf, PV_NONE,
1535 			    {(char_u *)"", (char_u *)NULL}
1536 # else
1537 			    (char_u *)NULL, PV_NONE,
1538 			    {(char_u *)NULL, (char_u *)0L}
1539 # endif
1540 			    SCRIPTID_INIT},
1541     {"imactivatekey","imak",P_STRING|P_VI_DEF,
1542 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1543 			    (char_u *)&p_imak, PV_NONE,
1544 #else
1545 			    (char_u *)NULL, PV_NONE,
1546 #endif
1547 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1548     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
1549 #ifdef USE_IM_CONTROL
1550 			    (char_u *)&p_imcmdline, PV_NONE,
1551 #else
1552 			    (char_u *)NULL, PV_NONE,
1553 #endif
1554 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1555     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
1556 #ifdef USE_IM_CONTROL
1557 			    (char_u *)&p_imdisable, PV_NONE,
1558 #else
1559 			    (char_u *)NULL, PV_NONE,
1560 #endif
1561 #ifdef __sgi
1562 			    {(char_u *)TRUE, (char_u *)0L}
1563 #else
1564 			    {(char_u *)FALSE, (char_u *)0L}
1565 #endif
1566 			    SCRIPTID_INIT},
1567     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
1568 			    (char_u *)&p_iminsert, PV_IMI,
1569 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1570 			    SCRIPTID_INIT},
1571     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
1572 			    (char_u *)&p_imsearch, PV_IMS,
1573 			    {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
1574 			    SCRIPTID_INIT},
1575     {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
1576 #if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1577 			    (char_u *)&p_imsf, PV_NONE,
1578 			    {(char_u *)"", (char_u *)NULL}
1579 #else
1580 			    (char_u *)NULL, PV_NONE,
1581 			    {(char_u *)NULL, (char_u *)0L}
1582 #endif
1583 			    SCRIPTID_INIT},
1584     {"imstyle",	    "imst", P_NUM|P_VI_DEF|P_SECURE,
1585 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1586 			    (char_u *)&p_imst, PV_NONE,
1587 			    {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1588 #else
1589 			    (char_u *)NULL, PV_NONE,
1590 			    {(char_u *)0L, (char_u *)0L}
1591 #endif
1592 			    SCRIPTID_INIT},
1593     {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
1594 #ifdef FEAT_FIND_ID
1595 			    (char_u *)&p_inc, PV_INC,
1596 			    {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1597 #else
1598 			    (char_u *)NULL, PV_NONE,
1599 			    {(char_u *)0L, (char_u *)0L}
1600 #endif
1601 			    SCRIPTID_INIT},
1602     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1603 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1604 			    (char_u *)&p_inex, PV_INEX,
1605 			    {(char_u *)"", (char_u *)0L}
1606 #else
1607 			    (char_u *)NULL, PV_NONE,
1608 			    {(char_u *)0L, (char_u *)0L}
1609 #endif
1610 			    SCRIPTID_INIT},
1611     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
1612 			    (char_u *)&p_is, PV_NONE,
1613 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1614     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1615 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1616 			    (char_u *)&p_inde, PV_INDE,
1617 			    {(char_u *)"", (char_u *)0L}
1618 #else
1619 			    (char_u *)NULL, PV_NONE,
1620 			    {(char_u *)0L, (char_u *)0L}
1621 #endif
1622 			    SCRIPTID_INIT},
1623     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1624 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1625 			    (char_u *)&p_indk, PV_INDK,
1626 			    {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1627 #else
1628 			    (char_u *)NULL, PV_NONE,
1629 			    {(char_u *)0L, (char_u *)0L}
1630 #endif
1631 			    SCRIPTID_INIT},
1632     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
1633 			    (char_u *)&p_inf, PV_INF,
1634 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1635     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
1636 			    (char_u *)&p_im, PV_NONE,
1637 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1638     {"isfname",	    "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1639 			    (char_u *)&p_isf, PV_NONE,
1640 			    {
1641 #ifdef BACKSLASH_IN_FILENAME
1642 				/* Excluded are: & and ^ are special in cmd.exe
1643 				 * ( and ) are used in text separating fnames */
1644 			    (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1645 #else
1646 # ifdef AMIGA
1647 			    (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1648 # else
1649 #  ifdef VMS
1650 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1651 #  else /* UNIX et al. */
1652 #   ifdef EBCDIC
1653 			    (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1654 #   else
1655 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1656 #   endif
1657 #  endif
1658 # endif
1659 #endif
1660 				(char_u *)0L} SCRIPTID_INIT},
1661     {"isident",	    "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 			    (char_u *)&p_isi, PV_NONE,
1663 			    {
1664 #if defined(MSWIN)
1665 			    (char_u *)"@,48-57,_,128-167,224-235",
1666 #else
1667 # ifdef EBCDIC
1668 			    /* TODO: EBCDIC Check this! @ == isalpha()*/
1669 			    (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1670 				    "112-120,128,140-142,156,158,172,"
1671 				    "174,186,191,203-207,219-225,235-239,"
1672 				    "251-254",
1673 # else
1674 			    (char_u *)"@,48-57,_,192-255",
1675 # endif
1676 #endif
1677 				(char_u *)0L} SCRIPTID_INIT},
1678     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1679 			    (char_u *)&p_isk, PV_ISK,
1680 			    {
1681 #ifdef EBCDIC
1682 			     (char_u *)"@,240-249,_",
1683 			     /* TODO: EBCDIC Check this! @ == isalpha()*/
1684 			     (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1685 				    "112-120,128,140-142,156,158,172,"
1686 				    "174,186,191,203-207,219-225,235-239,"
1687 				    "251-254",
1688 #else
1689 				(char_u *)"@,48-57,_",
1690 # if defined(MSWIN)
1691 				(char_u *)"@,48-57,_,128-167,224-235"
1692 # else
1693 				ISK_LATIN1
1694 # endif
1695 #endif
1696 			    } SCRIPTID_INIT},
1697     {"isprint",	    "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1698 			    (char_u *)&p_isp, PV_NONE,
1699 			    {
1700 #if defined(MSWIN) || defined(VMS)
1701 			    (char_u *)"@,~-255",
1702 #else
1703 # ifdef EBCDIC
1704 			    /* all chars above 63 are printable */
1705 			    (char_u *)"63-255",
1706 # else
1707 			    ISP_LATIN1,
1708 # endif
1709 #endif
1710 				(char_u *)0L} SCRIPTID_INIT},
1711     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
1712 			    (char_u *)&p_js, PV_NONE,
1713 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1714     {"key",	    NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1715 #ifdef FEAT_CRYPT
1716 			    (char_u *)&p_key, PV_KEY,
1717 			    {(char_u *)"", (char_u *)0L}
1718 #else
1719 			    (char_u *)NULL, PV_NONE,
1720 			    {(char_u *)0L, (char_u *)0L}
1721 #endif
1722 			    SCRIPTID_INIT},
1723     {"keymap",	    "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1724 #ifdef FEAT_KEYMAP
1725 			    (char_u *)&p_keymap, PV_KMAP,
1726 			    {(char_u *)"", (char_u *)0L}
1727 #else
1728 			    (char_u *)NULL, PV_NONE,
1729 			    {(char_u *)"", (char_u *)0L}
1730 #endif
1731 			    SCRIPTID_INIT},
1732     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1733 			    (char_u *)&p_km, PV_NONE,
1734 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1735     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1736 			    (char_u *)&p_kp, PV_KP,
1737 			    {
1738 #ifdef MSWIN
1739 			    (char_u *)":help",
1740 #else
1741 # ifdef VMS
1742 			    (char_u *)"help",
1743 # else
1744 #  ifdef USEMAN_S
1745 			    (char_u *)"man -s",
1746 #  else
1747 			    (char_u *)"man",
1748 #  endif
1749 # endif
1750 #endif
1751 				(char_u *)0L} SCRIPTID_INIT},
1752     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
1753 #ifdef FEAT_LANGMAP
1754 			    (char_u *)&p_langmap, PV_NONE,
1755 			    {(char_u *)"",	/* unmatched } */
1756 #else
1757 			    (char_u *)NULL, PV_NONE,
1758 			    {(char_u *)NULL,
1759 #endif
1760 				(char_u *)0L} SCRIPTID_INIT},
1761     {"langmenu",    "lm",   P_STRING|P_VI_DEF|P_NFNAME,
1762 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1763 			    (char_u *)&p_lm, PV_NONE,
1764 #else
1765 			    (char_u *)NULL, PV_NONE,
1766 #endif
1767 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1768     {"langnoremap",  "lnr",   P_BOOL|P_VI_DEF,
1769 #ifdef FEAT_LANGMAP
1770 			    (char_u *)&p_lnr, PV_NONE,
1771 #else
1772 			    (char_u *)NULL, PV_NONE,
1773 #endif
1774 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1775     {"langremap",  "lrm",   P_BOOL|P_VI_DEF,
1776 #ifdef FEAT_LANGMAP
1777 			    (char_u *)&p_lrm, PV_NONE,
1778 #else
1779 			    (char_u *)NULL, PV_NONE,
1780 #endif
1781 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1782     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
1783 			    (char_u *)&p_ls, PV_NONE,
1784 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
1785     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
1786 			    (char_u *)&p_lz, PV_NONE,
1787 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1788     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
1789 #ifdef FEAT_LINEBREAK
1790 			    (char_u *)VAR_WIN, PV_LBR,
1791 #else
1792 			    (char_u *)NULL, PV_NONE,
1793 #endif
1794 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1795     {"lines",	    NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1796 			    (char_u *)&Rows, PV_NONE,
1797 			    {
1798 #if defined(WIN3264)
1799 			    (char_u *)25L,
1800 #else
1801 			    (char_u *)24L,
1802 #endif
1803 					    (char_u *)0L} SCRIPTID_INIT},
1804     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
1805 #ifdef FEAT_GUI
1806 			    (char_u *)&p_linespace, PV_NONE,
1807 #else
1808 			    (char_u *)NULL, PV_NONE,
1809 #endif
1810 #ifdef FEAT_GUI_W32
1811 			    {(char_u *)1L, (char_u *)0L}
1812 #else
1813 			    {(char_u *)0L, (char_u *)0L}
1814 #endif
1815 			    SCRIPTID_INIT},
1816     {"lisp",	    NULL,   P_BOOL|P_VI_DEF,
1817 #ifdef FEAT_LISP
1818 			    (char_u *)&p_lisp, PV_LISP,
1819 #else
1820 			    (char_u *)NULL, PV_NONE,
1821 #endif
1822 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1823     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1824 #ifdef FEAT_LISP
1825 			    (char_u *)&p_lispwords, PV_LW,
1826 			    {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1827 #else
1828 			    (char_u *)NULL, PV_NONE,
1829 			    {(char_u *)"", (char_u *)0L}
1830 #endif
1831 			    SCRIPTID_INIT},
1832     {"list",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
1833 			    (char_u *)VAR_WIN, PV_LIST,
1834 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1835     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1836 			    (char_u *)&p_lcs, PV_NONE,
1837 			    {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
1838     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
1839 			    (char_u *)&p_lpl, PV_NONE,
1840 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1841     {"luadll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1842 #if defined(DYNAMIC_LUA)
1843 			    (char_u *)&p_luadll, PV_NONE,
1844 			    {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1845 #else
1846 			    (char_u *)NULL, PV_NONE,
1847 			    {(char_u *)"", (char_u *)0L}
1848 #endif
1849 			    SCRIPTID_INIT},
1850     {"macatsui",    NULL,   P_BOOL|P_VI_DEF|P_RCLR,
1851 #ifdef FEAT_GUI_MAC
1852 			    (char_u *)&p_macatsui, PV_NONE,
1853 			    {(char_u *)TRUE, (char_u *)0L}
1854 #else
1855 			    (char_u *)NULL, PV_NONE,
1856 			    {(char_u *)"", (char_u *)0L}
1857 #endif
1858 			    SCRIPTID_INIT},
1859     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
1860 			    (char_u *)&p_magic, PV_NONE,
1861 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1862     {"makeef",	    "mef",  P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1863 #ifdef FEAT_QUICKFIX
1864 			    (char_u *)&p_mef, PV_NONE,
1865 			    {(char_u *)"", (char_u *)0L}
1866 #else
1867 			    (char_u *)NULL, PV_NONE,
1868 			    {(char_u *)NULL, (char_u *)0L}
1869 #endif
1870 			    SCRIPTID_INIT},
1871     {"makeencoding","menc", P_STRING|P_VI_DEF,
1872 #ifdef FEAT_MBYTE
1873 			    (char_u *)&p_menc, PV_MENC,
1874 			    {(char_u *)"", (char_u *)0L}
1875 #else
1876 			    (char_u *)NULL, PV_NONE,
1877 			    {(char_u *)0L, (char_u *)0L}
1878 #endif
1879 			    SCRIPTID_INIT},
1880     {"makeprg",	    "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1881 #ifdef FEAT_QUICKFIX
1882 			    (char_u *)&p_mp, PV_MP,
1883 # ifdef VMS
1884 			    {(char_u *)"MMS", (char_u *)0L}
1885 # else
1886 			    {(char_u *)"make", (char_u *)0L}
1887 # endif
1888 #else
1889 			    (char_u *)NULL, PV_NONE,
1890 			    {(char_u *)NULL, (char_u *)0L}
1891 #endif
1892 			    SCRIPTID_INIT},
1893     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1894 			    (char_u *)&p_mps, PV_MPS,
1895 			    {(char_u *)"(:),{:},[:]", (char_u *)0L}
1896 			    SCRIPTID_INIT},
1897     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
1898 			    (char_u *)&p_mat, PV_NONE,
1899 			    {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1900     {"maxcombine",  "mco",  P_NUM|P_VI_DEF|P_CURSWANT,
1901 #ifdef FEAT_MBYTE
1902 			    (char_u *)&p_mco, PV_NONE,
1903 #else
1904 			    (char_u *)NULL, PV_NONE,
1905 #endif
1906 			    {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
1907     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1908 #ifdef FEAT_EVAL
1909 			    (char_u *)&p_mfd, PV_NONE,
1910 #else
1911 			    (char_u *)NULL, PV_NONE,
1912 #endif
1913 			    {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
1914     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
1915 			    (char_u *)&p_mmd, PV_NONE,
1916 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1917     {"maxmem",	    "mm",   P_NUM|P_VI_DEF,
1918 			    (char_u *)&p_mm, PV_NONE,
1919 			    {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1920 			    SCRIPTID_INIT},
1921     {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1922 			    (char_u *)&p_mmp, PV_NONE,
1923 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1924     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
1925 			    (char_u *)&p_mmt, PV_NONE,
1926 			    {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1927 			    SCRIPTID_INIT},
1928     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
1929 #ifdef FEAT_MENU
1930 			    (char_u *)&p_mis, PV_NONE,
1931 #else
1932 			    (char_u *)NULL, PV_NONE,
1933 #endif
1934 			    {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
1935     {"mesg",	    NULL,   P_BOOL|P_VI_DEF,
1936 			    (char_u *)NULL, PV_NONE,
1937 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1938     {"mkspellmem",  "msm",  P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1939 #ifdef FEAT_SPELL
1940 			    (char_u *)&p_msm, PV_NONE,
1941 			    {(char_u *)"460000,2000,500", (char_u *)0L}
1942 #else
1943 			    (char_u *)NULL, PV_NONE,
1944 			    {(char_u *)0L, (char_u *)0L}
1945 #endif
1946 			    SCRIPTID_INIT},
1947     {"modeline",    "ml",   P_BOOL|P_VIM,
1948 			    (char_u *)&p_ml, PV_ML,
1949 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1950     {"modelines",   "mls",  P_NUM|P_VI_DEF,
1951 			    (char_u *)&p_mls, PV_NONE,
1952 			    {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1953     {"modifiable",  "ma",   P_BOOL|P_VI_DEF|P_NOGLOB,
1954 			    (char_u *)&p_ma, PV_MA,
1955 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1956     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1957 			    (char_u *)&p_mod, PV_MOD,
1958 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1959     {"more",	    NULL,   P_BOOL|P_VIM,
1960 			    (char_u *)&p_more, PV_NONE,
1961 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1962     {"mouse",	    NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
1963 			    (char_u *)&p_mouse, PV_NONE,
1964 			    {
1965 #if defined(WIN3264)
1966 				(char_u *)"a",
1967 #else
1968 				(char_u *)"",
1969 #endif
1970 				(char_u *)0L} SCRIPTID_INIT},
1971     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
1972 #ifdef FEAT_GUI
1973 			    (char_u *)&p_mousef, PV_NONE,
1974 #else
1975 			    (char_u *)NULL, PV_NONE,
1976 #endif
1977 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1978     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
1979 #ifdef FEAT_GUI
1980 			    (char_u *)&p_mh, PV_NONE,
1981 #else
1982 			    (char_u *)NULL, PV_NONE,
1983 #endif
1984 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1985     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
1986 			    (char_u *)&p_mousem, PV_NONE,
1987 			    {
1988 #if defined(MSWIN)
1989 				(char_u *)"popup",
1990 #else
1991 # if defined(MACOS_X)
1992 				(char_u *)"popup_setpos",
1993 # else
1994 				(char_u *)"extend",
1995 # endif
1996 #endif
1997 				(char_u *)0L} SCRIPTID_INIT},
1998     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1999 #ifdef FEAT_MOUSESHAPE
2000 			    (char_u *)&p_mouseshape, PV_NONE,
2001 			    {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2002 #else
2003 			    (char_u *)NULL, PV_NONE,
2004 			    {(char_u *)NULL, (char_u *)0L}
2005 #endif
2006 			    SCRIPTID_INIT},
2007     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
2008 			    (char_u *)&p_mouset, PV_NONE,
2009 			    {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
2010     {"mzschemedll", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2011 #if defined(DYNAMIC_MZSCHEME)
2012 			    (char_u *)&p_mzschemedll, PV_NONE,
2013 			    {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
2014 #else
2015 			    (char_u *)NULL, PV_NONE,
2016 			    {(char_u *)"", (char_u *)0L}
2017 #endif
2018 			    SCRIPTID_INIT},
2019     {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2020 #if defined(DYNAMIC_MZSCHEME)
2021 			    (char_u *)&p_mzschemegcdll, PV_NONE,
2022 			    {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
2023 #else
2024 			    (char_u *)NULL, PV_NONE,
2025 			    {(char_u *)"", (char_u *)0L}
2026 #endif
2027 			    SCRIPTID_INIT},
2028     {"mzquantum",  "mzq",   P_NUM,
2029 #ifdef FEAT_MZSCHEME
2030 			    (char_u *)&p_mzq, PV_NONE,
2031 #else
2032 			    (char_u *)NULL, PV_NONE,
2033 #endif
2034 			    {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
2035     {"novice",	    NULL,   P_BOOL|P_VI_DEF,
2036 			    (char_u *)NULL, PV_NONE,
2037 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2038     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
2039 			    (char_u *)&p_nf, PV_NF,
2040 			    {(char_u *)"bin,octal,hex", (char_u *)0L}
2041 			    SCRIPTID_INIT},
2042     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
2043 			    (char_u *)VAR_WIN, PV_NU,
2044 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2045     {"numberwidth", "nuw",  P_NUM|P_RWIN|P_VIM,
2046 #ifdef FEAT_LINEBREAK
2047 			    (char_u *)VAR_WIN, PV_NUW,
2048 #else
2049 			    (char_u *)NULL, PV_NONE,
2050 #endif
2051 			    {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
2052     {"omnifunc",    "ofu",  P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2053 #ifdef FEAT_COMPL_FUNC
2054 			    (char_u *)&p_ofu, PV_OFU,
2055 			    {(char_u *)"", (char_u *)0L}
2056 #else
2057 			    (char_u *)NULL, PV_NONE,
2058 			    {(char_u *)0L, (char_u *)0L}
2059 #endif
2060 			    SCRIPTID_INIT},
2061     {"open",	    NULL,   P_BOOL|P_VI_DEF,
2062 			    (char_u *)NULL, PV_NONE,
2063 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2064     {"opendevice",  "odev", P_BOOL|P_VI_DEF,
2065 #if defined(MSWIN)
2066 			    (char_u *)&p_odev, PV_NONE,
2067 #else
2068 			    (char_u *)NULL, PV_NONE,
2069 #endif
2070 			    {(char_u *)FALSE, (char_u *)FALSE}
2071 			    SCRIPTID_INIT},
2072     {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2073 			    (char_u *)&p_opfunc, PV_NONE,
2074 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2075     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
2076 			    (char_u *)NULL, PV_NONE,
2077 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2078     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
2079 			    (char_u *)NULL, PV_NONE,
2080 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2081     {"packpath",    "pp",   P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2082 								    |P_SECURE,
2083 			    (char_u *)&p_pp, PV_NONE,
2084 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2085 			    SCRIPTID_INIT},
2086     {"paragraphs",  "para", P_STRING|P_VI_DEF,
2087 			    (char_u *)&p_para, PV_NONE,
2088 			    {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
2089 				(char_u *)0L} SCRIPTID_INIT},
2090     {"paste",	    NULL,   P_BOOL|P_VI_DEF|P_PRI_MKRC,
2091 			    (char_u *)&p_paste, PV_NONE,
2092 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2093     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
2094 			    (char_u *)&p_pt, PV_NONE,
2095 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2096     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
2097 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2098 			    (char_u *)&p_pex, PV_NONE,
2099 			    {(char_u *)"", (char_u *)0L}
2100 #else
2101 			    (char_u *)NULL, PV_NONE,
2102 			    {(char_u *)0L, (char_u *)0L}
2103 #endif
2104 			    SCRIPTID_INIT},
2105     {"patchmode",   "pm",   P_STRING|P_VI_DEF|P_NFNAME,
2106 			    (char_u *)&p_pm, PV_NONE,
2107 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2108     {"path",	    "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2109 			    (char_u *)&p_path, PV_PATH,
2110 			    {
2111 #if defined(AMIGA) || defined(MSWIN)
2112 			    (char_u *)".,,",
2113 #else
2114 			    (char_u *)".,/usr/include,,",
2115 #endif
2116 				(char_u *)0L} SCRIPTID_INIT},
2117     {"perldll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2118 #if defined(DYNAMIC_PERL)
2119 			    (char_u *)&p_perldll, PV_NONE,
2120 			    {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2121 #else
2122 			    (char_u *)NULL, PV_NONE,
2123 			    {(char_u *)0L, (char_u *)0L}
2124 #endif
2125 			    SCRIPTID_INIT},
2126     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2127 			    (char_u *)&p_pi, PV_PI,
2128 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2129     {"previewheight", "pvh", P_NUM|P_VI_DEF,
2130 #if defined(FEAT_QUICKFIX)
2131 			    (char_u *)&p_pvh, PV_NONE,
2132 #else
2133 			    (char_u *)NULL, PV_NONE,
2134 #endif
2135 			    {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
2136     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2137 #if defined(FEAT_QUICKFIX)
2138 			    (char_u *)VAR_WIN, PV_PVW,
2139 #else
2140 			    (char_u *)NULL, PV_NONE,
2141 #endif
2142 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2143     {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
2144 #ifdef FEAT_PRINTER
2145 			    (char_u *)&p_pdev, PV_NONE,
2146 			    {(char_u *)"", (char_u *)0L}
2147 #else
2148 			    (char_u *)NULL, PV_NONE,
2149 			    {(char_u *)NULL, (char_u *)0L}
2150 #endif
2151 			    SCRIPTID_INIT},
2152     {"printencoding", "penc", P_STRING|P_VI_DEF,
2153 #ifdef FEAT_POSTSCRIPT
2154 			    (char_u *)&p_penc, PV_NONE,
2155 			    {(char_u *)"", (char_u *)0L}
2156 #else
2157 			    (char_u *)NULL, PV_NONE,
2158 			    {(char_u *)NULL, (char_u *)0L}
2159 #endif
2160 			    SCRIPTID_INIT},
2161     {"printexpr", "pexpr",  P_STRING|P_VI_DEF|P_SECURE,
2162 #ifdef FEAT_POSTSCRIPT
2163 			    (char_u *)&p_pexpr, PV_NONE,
2164 			    {(char_u *)"", (char_u *)0L}
2165 #else
2166 			    (char_u *)NULL, PV_NONE,
2167 			    {(char_u *)NULL, (char_u *)0L}
2168 #endif
2169 			    SCRIPTID_INIT},
2170     {"printfont", "pfn",    P_STRING|P_VI_DEF,
2171 #ifdef FEAT_PRINTER
2172 			    (char_u *)&p_pfn, PV_NONE,
2173 			    {
2174 # ifdef MSWIN
2175 				(char_u *)"Courier_New:h10",
2176 # else
2177 				(char_u *)"courier",
2178 # endif
2179 				(char_u *)0L}
2180 #else
2181 			    (char_u *)NULL, PV_NONE,
2182 			    {(char_u *)NULL, (char_u *)0L}
2183 #endif
2184 			    SCRIPTID_INIT},
2185     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
2186 #ifdef FEAT_PRINTER
2187 			    (char_u *)&p_header, PV_NONE,
2188 			    /* untranslated to avoid problems when 'encoding'
2189 			     * is changed */
2190 			    {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
2191 #else
2192 			    (char_u *)NULL, PV_NONE,
2193 			    {(char_u *)NULL, (char_u *)0L}
2194 #endif
2195 			    SCRIPTID_INIT},
2196    {"printmbcharset", "pmbcs",  P_STRING|P_VI_DEF,
2197 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2198 			    (char_u *)&p_pmcs, PV_NONE,
2199 			    {(char_u *)"", (char_u *)0L}
2200 #else
2201 			    (char_u *)NULL, PV_NONE,
2202 			    {(char_u *)NULL, (char_u *)0L}
2203 #endif
2204 			    SCRIPTID_INIT},
2205     {"printmbfont", "pmbfn",  P_STRING|P_VI_DEF,
2206 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 			    (char_u *)&p_pmfn, PV_NONE,
2208 			    {(char_u *)"", (char_u *)0L}
2209 #else
2210 			    (char_u *)NULL, PV_NONE,
2211 			    {(char_u *)NULL, (char_u *)0L}
2212 #endif
2213 			    SCRIPTID_INIT},
2214     {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2215 #ifdef FEAT_PRINTER
2216 			    (char_u *)&p_popt, PV_NONE,
2217 			    {(char_u *)"", (char_u *)0L}
2218 #else
2219 			    (char_u *)NULL, PV_NONE,
2220 			    {(char_u *)NULL, (char_u *)0L}
2221 #endif
2222 			    SCRIPTID_INIT},
2223     {"prompt",	    NULL,   P_BOOL|P_VI_DEF,
2224 			    (char_u *)&p_prompt, PV_NONE,
2225 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2226     {"pumheight",   "ph",   P_NUM|P_VI_DEF,
2227 #ifdef FEAT_INS_EXPAND
2228 			    (char_u *)&p_ph, PV_NONE,
2229 #else
2230 			    (char_u *)NULL, PV_NONE,
2231 #endif
2232 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2233     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2234 #if defined(DYNAMIC_PYTHON3)
2235 			    (char_u *)&p_py3dll, PV_NONE,
2236 			    {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2237 #else
2238 			    (char_u *)NULL, PV_NONE,
2239 			    {(char_u *)NULL, (char_u *)0L}
2240 #endif
2241 			    SCRIPTID_INIT},
2242     {"pythondll",   NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2243 #if defined(DYNAMIC_PYTHON)
2244 			    (char_u *)&p_pydll, PV_NONE,
2245 			    {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2246 #else
2247 			    (char_u *)NULL, PV_NONE,
2248 			    {(char_u *)NULL, (char_u *)0L}
2249 #endif
2250 			    SCRIPTID_INIT},
2251     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
2252 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2253 			    (char_u *)&p_pyx, PV_NONE,
2254 #else
2255 			    (char_u *)NULL, PV_NONE,
2256 #endif
2257 			    {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2258 			    SCRIPTID_INIT},
2259     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
2260 #ifdef FEAT_TEXTOBJ
2261 			    (char_u *)&p_qe, PV_QE,
2262 			    {(char_u *)"\\", (char_u *)0L}
2263 #else
2264 			    (char_u *)NULL, PV_NONE,
2265 			    {(char_u *)NULL, (char_u *)0L}
2266 #endif
2267 			    SCRIPTID_INIT},
2268     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2269 			    (char_u *)&p_ro, PV_RO,
2270 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2271     {"redraw",	    NULL,   P_BOOL|P_VI_DEF,
2272 			    (char_u *)NULL, PV_NONE,
2273 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2274     {"redrawtime",  "rdt",  P_NUM|P_VI_DEF,
2275 #ifdef FEAT_RELTIME
2276 			    (char_u *)&p_rdt, PV_NONE,
2277 #else
2278 			    (char_u *)NULL, PV_NONE,
2279 #endif
2280 			    {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
2281     {"regexpengine", "re",  P_NUM|P_VI_DEF,
2282 			    (char_u *)&p_re, PV_NONE,
2283 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2284     {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2285 			    (char_u *)VAR_WIN, PV_RNU,
2286 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2287     {"remap",	    NULL,   P_BOOL|P_VI_DEF,
2288 			    (char_u *)&p_remap, PV_NONE,
2289 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2290     {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
2291 #ifdef FEAT_RENDER_OPTIONS
2292 			    (char_u *)&p_rop, PV_NONE,
2293 			    {(char_u *)"", (char_u *)0L}
2294 #else
2295 			    (char_u *)NULL, PV_NONE,
2296 			    {(char_u *)NULL, (char_u *)0L}
2297 #endif
2298 			    SCRIPTID_INIT},
2299     {"report",	    NULL,   P_NUM|P_VI_DEF,
2300 			    (char_u *)&p_report, PV_NONE,
2301 			    {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
2302     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2303 #ifdef WIN3264
2304 			    (char_u *)&p_rs, PV_NONE,
2305 #else
2306 			    (char_u *)NULL, PV_NONE,
2307 #endif
2308 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2309     {"revins",	    "ri",   P_BOOL|P_VI_DEF|P_VIM,
2310 #ifdef FEAT_RIGHTLEFT
2311 			    (char_u *)&p_ri, PV_NONE,
2312 #else
2313 			    (char_u *)NULL, PV_NONE,
2314 #endif
2315 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2316     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
2317 #ifdef FEAT_RIGHTLEFT
2318 			    (char_u *)VAR_WIN, PV_RL,
2319 #else
2320 			    (char_u *)NULL, PV_NONE,
2321 #endif
2322 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2323     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2324 #ifdef FEAT_RIGHTLEFT
2325 			    (char_u *)VAR_WIN, PV_RLC,
2326 			    {(char_u *)"search", (char_u *)NULL}
2327 #else
2328 			    (char_u *)NULL, PV_NONE,
2329 			    {(char_u *)NULL, (char_u *)0L}
2330 #endif
2331 			    SCRIPTID_INIT},
2332     {"rubydll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2333 #if defined(DYNAMIC_RUBY)
2334 			    (char_u *)&p_rubydll, PV_NONE,
2335 			    {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2336 #else
2337 			    (char_u *)NULL, PV_NONE,
2338 			    {(char_u *)NULL, (char_u *)0L}
2339 #endif
2340 			    SCRIPTID_INIT},
2341     {"ruler",	    "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2342 #ifdef FEAT_CMDL_INFO
2343 			    (char_u *)&p_ru, PV_NONE,
2344 #else
2345 			    (char_u *)NULL, PV_NONE,
2346 #endif
2347 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2348     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2349 #ifdef FEAT_STL_OPT
2350 			    (char_u *)&p_ruf, PV_NONE,
2351 #else
2352 			    (char_u *)NULL, PV_NONE,
2353 #endif
2354 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2355     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2356 								    |P_SECURE,
2357 			    (char_u *)&p_rtp, PV_NONE,
2358 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2359 			    SCRIPTID_INIT},
2360     {"scroll",	    "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
2361 			    (char_u *)VAR_WIN, PV_SCROLL,
2362 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2363     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
2364 #ifdef FEAT_SCROLLBIND
2365 			    (char_u *)VAR_WIN, PV_SCBIND,
2366 #else
2367 			    (char_u *)NULL, PV_NONE,
2368 #endif
2369 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2370     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
2371 			    (char_u *)&p_sj, PV_NONE,
2372 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2373     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
2374 			    (char_u *)&p_so, PV_NONE,
2375 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2376     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2377 #ifdef FEAT_SCROLLBIND
2378 			    (char_u *)&p_sbo, PV_NONE,
2379 			    {(char_u *)"ver,jump", (char_u *)0L}
2380 #else
2381 			    (char_u *)NULL, PV_NONE,
2382 			    {(char_u *)0L, (char_u *)0L}
2383 #endif
2384 			    SCRIPTID_INIT},
2385     {"sections",    "sect", P_STRING|P_VI_DEF,
2386 			    (char_u *)&p_sections, PV_NONE,
2387 			    {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2388 			    SCRIPTID_INIT},
2389     {"secure",	    NULL,   P_BOOL|P_VI_DEF|P_SECURE,
2390 			    (char_u *)&p_secure, PV_NONE,
2391 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2392     {"selection",   "sel",  P_STRING|P_VI_DEF,
2393 			    (char_u *)&p_sel, PV_NONE,
2394 			    {(char_u *)"inclusive", (char_u *)0L}
2395 			    SCRIPTID_INIT},
2396     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2397 			    (char_u *)&p_slm, PV_NONE,
2398 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2399     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2400 #ifdef FEAT_SESSION
2401 			    (char_u *)&p_ssop, PV_NONE,
2402 	 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
2403 							       (char_u *)0L}
2404 #else
2405 			    (char_u *)NULL, PV_NONE,
2406 			    {(char_u *)0L, (char_u *)0L}
2407 #endif
2408 			    SCRIPTID_INIT},
2409     {"shell",	    "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2410 			    (char_u *)&p_sh, PV_NONE,
2411 			    {
2412 #ifdef VMS
2413 			    (char_u *)"-",
2414 #else
2415 # if defined(WIN3264)
2416 			    (char_u *)"",	/* set in set_init_1() */
2417 # else
2418 			    (char_u *)"sh",
2419 # endif
2420 #endif /* VMS */
2421 				(char_u *)0L} SCRIPTID_INIT},
2422     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2423 			    (char_u *)&p_shcf, PV_NONE,
2424 			    {
2425 #if defined(MSWIN)
2426 			    (char_u *)"/c",
2427 #else
2428 			    (char_u *)"-c",
2429 #endif
2430 				(char_u *)0L} SCRIPTID_INIT},
2431     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
2432 #ifdef FEAT_QUICKFIX
2433 			    (char_u *)&p_sp, PV_NONE,
2434 			    {
2435 #if defined(UNIX)
2436 			    (char_u *)"| tee",
2437 #else
2438 			    (char_u *)">",
2439 #endif
2440 				(char_u *)0L}
2441 #else
2442 			    (char_u *)NULL, PV_NONE,
2443 			    {(char_u *)0L, (char_u *)0L}
2444 #endif
2445 			    SCRIPTID_INIT},
2446     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
2447 			    (char_u *)&p_shq, PV_NONE,
2448 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2449     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
2450 			    (char_u *)&p_srr, PV_NONE,
2451 			    {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
2452     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
2453 #ifdef BACKSLASH_IN_FILENAME
2454 			    (char_u *)&p_ssl, PV_NONE,
2455 #else
2456 			    (char_u *)NULL, PV_NONE,
2457 #endif
2458 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2459     {"shelltemp",   "stmp", P_BOOL,
2460 			    (char_u *)&p_stmp, PV_NONE,
2461 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2462     {"shelltype",   "st",   P_NUM|P_VI_DEF,
2463 #ifdef AMIGA
2464 			    (char_u *)&p_st, PV_NONE,
2465 #else
2466 			    (char_u *)NULL, PV_NONE,
2467 #endif
2468 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2469     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
2470 			    (char_u *)&p_sxq, PV_NONE,
2471 			    {
2472 #if defined(UNIX) && defined(USE_SYSTEM)
2473 			    (char_u *)"\"",
2474 #else
2475 			    (char_u *)"",
2476 #endif
2477 				(char_u *)0L} SCRIPTID_INIT},
2478     {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2479 			    (char_u *)&p_sxe, PV_NONE,
2480 			    {
2481 #if defined(WIN3264)
2482 			    (char_u *)"\"&|<>()@^",
2483 #else
2484 			    (char_u *)"",
2485 #endif
2486 				(char_u *)0L} SCRIPTID_INIT},
2487     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
2488 			    (char_u *)&p_sr, PV_NONE,
2489 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2490     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
2491 			    (char_u *)&p_sw, PV_SW,
2492 			    {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2493     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
2494 			    (char_u *)&p_shm, PV_NONE,
2495 			    {(char_u *)"", (char_u *)"filnxtToO"}
2496 			    SCRIPTID_INIT},
2497     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
2498 			    (char_u *)&p_sn, PV_SN,
2499 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2500     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
2501 #ifdef FEAT_LINEBREAK
2502 			    (char_u *)&p_sbr, PV_NONE,
2503 #else
2504 			    (char_u *)NULL, PV_NONE,
2505 #endif
2506 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2507     {"showcmd",	    "sc",   P_BOOL|P_VIM,
2508 #ifdef FEAT_CMDL_INFO
2509 			    (char_u *)&p_sc, PV_NONE,
2510 #else
2511 			    (char_u *)NULL, PV_NONE,
2512 #endif
2513 			    {(char_u *)FALSE,
2514 #ifdef UNIX
2515 				(char_u *)FALSE
2516 #else
2517 				(char_u *)TRUE
2518 #endif
2519 				} SCRIPTID_INIT},
2520     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
2521 			    (char_u *)&p_sft, PV_NONE,
2522 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2523     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
2524 			    (char_u *)&p_sm, PV_NONE,
2525 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2526     {"showmode",    "smd",  P_BOOL|P_VIM,
2527 			    (char_u *)&p_smd, PV_NONE,
2528 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2529     {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2530 			    (char_u *)&p_stal, PV_NONE,
2531 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2532     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
2533 			    (char_u *)&p_ss, PV_NONE,
2534 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2535     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2536 			    (char_u *)&p_siso, PV_NONE,
2537 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2538     {"signcolumn",   "scl",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2539 #ifdef FEAT_SIGNS
2540 			    (char_u *)VAR_WIN, PV_SCL,
2541 			    {(char_u *)"auto", (char_u *)0L}
2542 #else
2543 			    (char_u *)NULL, PV_NONE,
2544 			    {(char_u *)NULL, (char_u *)0L}
2545 #endif
2546 			    SCRIPTID_INIT},
2547     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
2548 			    (char_u *)NULL, PV_NONE,
2549 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2550     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
2551 			    (char_u *)&p_scs, PV_NONE,
2552 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2553     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
2554 #ifdef FEAT_SMARTINDENT
2555 			    (char_u *)&p_si, PV_SI,
2556 #else
2557 			    (char_u *)NULL, PV_NONE,
2558 #endif
2559 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2560     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
2561 			    (char_u *)&p_sta, PV_NONE,
2562 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2563     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
2564 			    (char_u *)&p_sts, PV_STS,
2565 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2566     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
2567 			    (char_u *)NULL, PV_NONE,
2568 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2569     {"spell",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
2570 #ifdef FEAT_SPELL
2571 			    (char_u *)VAR_WIN, PV_SPELL,
2572 #else
2573 			    (char_u *)NULL, PV_NONE,
2574 #endif
2575 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2576     {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2577 #ifdef FEAT_SPELL
2578 			    (char_u *)&p_spc, PV_SPC,
2579 			    {(char_u *)"[.?!]\\_[\\])'\"	 ]\\+", (char_u *)0L}
2580 #else
2581 			    (char_u *)NULL, PV_NONE,
2582 			    {(char_u *)0L, (char_u *)0L}
2583 #endif
2584 			    SCRIPTID_INIT},
2585     {"spellfile",   "spf",  P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2586 								  |P_ONECOMMA,
2587 #ifdef FEAT_SPELL
2588 			    (char_u *)&p_spf, PV_SPF,
2589 			    {(char_u *)"", (char_u *)0L}
2590 #else
2591 			    (char_u *)NULL, PV_NONE,
2592 			    {(char_u *)0L, (char_u *)0L}
2593 #endif
2594 			    SCRIPTID_INIT},
2595     {"spelllang",   "spl",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2596 							     |P_RBUF|P_EXPAND,
2597 #ifdef FEAT_SPELL
2598 			    (char_u *)&p_spl, PV_SPL,
2599 			    {(char_u *)"en", (char_u *)0L}
2600 #else
2601 			    (char_u *)NULL, PV_NONE,
2602 			    {(char_u *)0L, (char_u *)0L}
2603 #endif
2604 			    SCRIPTID_INIT},
2605     {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
2606 #ifdef FEAT_SPELL
2607 			    (char_u *)&p_sps, PV_NONE,
2608 			    {(char_u *)"best", (char_u *)0L}
2609 #else
2610 			    (char_u *)NULL, PV_NONE,
2611 			    {(char_u *)0L, (char_u *)0L}
2612 #endif
2613 			    SCRIPTID_INIT},
2614     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
2615 			    (char_u *)&p_sb, PV_NONE,
2616 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2617     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
2618 			    (char_u *)&p_spr, PV_NONE,
2619 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2620     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
2621 			    (char_u *)&p_sol, PV_NONE,
2622 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2623     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2624 #ifdef FEAT_STL_OPT
2625 			    (char_u *)&p_stl, PV_STL,
2626 #else
2627 			    (char_u *)NULL, PV_NONE,
2628 #endif
2629 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2630     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2631 			    (char_u *)&p_su, PV_NONE,
2632 			    {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2633 				(char_u *)0L} SCRIPTID_INIT},
2634     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
2635 #ifdef FEAT_SEARCHPATH
2636 			    (char_u *)&p_sua, PV_SUA,
2637 			    {(char_u *)"", (char_u *)0L}
2638 #else
2639 			    (char_u *)NULL, PV_NONE,
2640 			    {(char_u *)0L, (char_u *)0L}
2641 #endif
2642 			    SCRIPTID_INIT},
2643     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
2644 			    (char_u *)&p_swf, PV_SWF,
2645 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2646     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
2647 			    (char_u *)&p_sws, PV_NONE,
2648 			    {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
2649     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2650 			    (char_u *)&p_swb, PV_NONE,
2651 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2652     {"synmaxcol",   "smc",  P_NUM|P_VI_DEF|P_RBUF,
2653 #ifdef FEAT_SYN_HL
2654 			    (char_u *)&p_smc, PV_SMC,
2655 			    {(char_u *)3000L, (char_u *)0L}
2656 #else
2657 			    (char_u *)NULL, PV_NONE,
2658 			    {(char_u *)0L, (char_u *)0L}
2659 #endif
2660 			    SCRIPTID_INIT},
2661     {"syntax",	    "syn",  P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2662 #ifdef FEAT_SYN_HL
2663 			    (char_u *)&p_syn, PV_SYN,
2664 			    {(char_u *)"", (char_u *)0L}
2665 #else
2666 			    (char_u *)NULL, PV_NONE,
2667 			    {(char_u *)0L, (char_u *)0L}
2668 #endif
2669 			    SCRIPTID_INIT},
2670     {"tabline",	    "tal",  P_STRING|P_VI_DEF|P_RALL,
2671 #ifdef FEAT_STL_OPT
2672 			    (char_u *)&p_tal, PV_NONE,
2673 #else
2674 			    (char_u *)NULL, PV_NONE,
2675 #endif
2676 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2677     {"tabpagemax",  "tpm",  P_NUM|P_VI_DEF,
2678 			    (char_u *)&p_tpm, PV_NONE,
2679 			    {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
2680     {"tabstop",	    "ts",   P_NUM|P_VI_DEF|P_RBUF,
2681 			    (char_u *)&p_ts, PV_TS,
2682 			    {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2683     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
2684 			    (char_u *)&p_tbs, PV_NONE,
2685 #ifdef VMS	/* binary searching doesn't appear to work on VMS */
2686 			    {(char_u *)0L, (char_u *)0L}
2687 #else
2688 			    {(char_u *)TRUE, (char_u *)0L}
2689 #endif
2690 			    SCRIPTID_INIT},
2691     {"tagcase",	    "tc",   P_STRING|P_VIM,
2692 			    (char_u *)&p_tc, PV_TC,
2693 			    {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
2694     {"taglength",   "tl",   P_NUM|P_VI_DEF,
2695 			    (char_u *)&p_tl, PV_NONE,
2696 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2697     {"tagrelative", "tr",   P_BOOL|P_VIM,
2698 			    (char_u *)&p_tr, PV_NONE,
2699 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2700     {"tags",	    "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
2701 			    (char_u *)&p_tags, PV_TAGS,
2702 			    {
2703 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2704 			    (char_u *)"./tags,./TAGS,tags,TAGS",
2705 #else
2706 			    (char_u *)"./tags,tags",
2707 #endif
2708 				(char_u *)0L} SCRIPTID_INIT},
2709     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
2710 			    (char_u *)&p_tgst, PV_NONE,
2711 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2712     {"tcldll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2713 #if defined(DYNAMIC_TCL)
2714 			    (char_u *)&p_tcldll, PV_NONE,
2715 			    {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2716 #else
2717 			    (char_u *)NULL, PV_NONE,
2718 			    {(char_u *)0L, (char_u *)0L}
2719 #endif
2720 			    SCRIPTID_INIT},
2721     {"term",	    NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2722 			    (char_u *)&T_NAME, PV_NONE,
2723 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2724     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
2725 #ifdef FEAT_ARABIC
2726 			    (char_u *)&p_tbidi, PV_NONE,
2727 #else
2728 			    (char_u *)NULL, PV_NONE,
2729 #endif
2730 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2731     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2732 #ifdef FEAT_MBYTE
2733 			    (char_u *)&p_tenc, PV_NONE,
2734 			    {(char_u *)"", (char_u *)0L}
2735 #else
2736 			    (char_u *)NULL, PV_NONE,
2737 			    {(char_u *)0L, (char_u *)0L}
2738 #endif
2739 			    SCRIPTID_INIT},
2740     {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2741 #ifdef FEAT_TERMGUICOLORS
2742 			    (char_u *)&p_tgc, PV_NONE,
2743 			    {(char_u *)FALSE, (char_u *)FALSE}
2744 #else
2745 			    (char_u*)NULL, PV_NONE,
2746 			    {(char_u *)FALSE, (char_u *)FALSE}
2747 #endif
2748 			    SCRIPTID_INIT},
2749     {"termkey", "tk",	    P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2750 #ifdef FEAT_TERMINAL
2751 			    (char_u *)VAR_WIN, PV_TK,
2752 			    {(char_u *)"", (char_u *)NULL}
2753 #else
2754 			    (char_u *)NULL, PV_NONE,
2755 			    {(char_u *)NULL, (char_u *)0L}
2756 #endif
2757 			    SCRIPTID_INIT},
2758     {"termsize", "tms",	    P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2759 #ifdef FEAT_TERMINAL
2760 			    (char_u *)VAR_WIN, PV_TMS,
2761 			    {(char_u *)"", (char_u *)NULL}
2762 #else
2763 			    (char_u *)NULL, PV_NONE,
2764 			    {(char_u *)NULL, (char_u *)0L}
2765 #endif
2766 			    SCRIPTID_INIT},
2767     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
2768 			    (char_u *)&p_terse, PV_NONE,
2769 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2770     {"textauto",    "ta",   P_BOOL|P_VIM,
2771 			    (char_u *)&p_ta, PV_NONE,
2772 			    {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2773 			    SCRIPTID_INIT},
2774     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
2775 			    (char_u *)&p_tx, PV_TX,
2776 			    {
2777 #ifdef USE_CRNL
2778 			    (char_u *)TRUE,
2779 #else
2780 			    (char_u *)FALSE,
2781 #endif
2782 				(char_u *)0L} SCRIPTID_INIT},
2783     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2784 			    (char_u *)&p_tw, PV_TW,
2785 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2786     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
2787 #ifdef FEAT_INS_EXPAND
2788 			    (char_u *)&p_tsr, PV_TSR,
2789 #else
2790 			    (char_u *)NULL, PV_NONE,
2791 #endif
2792 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2793     {"tildeop",	    "top",  P_BOOL|P_VI_DEF|P_VIM,
2794 			    (char_u *)&p_to, PV_NONE,
2795 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2796     {"timeout",	    "to",   P_BOOL|P_VI_DEF,
2797 			    (char_u *)&p_timeout, PV_NONE,
2798 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2799     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
2800 			    (char_u *)&p_tm, PV_NONE,
2801 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
2802     {"title",	    NULL,   P_BOOL|P_VI_DEF,
2803 #ifdef FEAT_TITLE
2804 			    (char_u *)&p_title, PV_NONE,
2805 #else
2806 			    (char_u *)NULL, PV_NONE,
2807 #endif
2808 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2809     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
2810 #ifdef FEAT_TITLE
2811 			    (char_u *)&p_titlelen, PV_NONE,
2812 #else
2813 			    (char_u *)NULL, PV_NONE,
2814 #endif
2815 			    {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
2816     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2817 #ifdef FEAT_TITLE
2818 			    (char_u *)&p_titleold, PV_NONE,
2819 			    {(char_u *)N_("Thanks for flying Vim"),
2820 							       (char_u *)0L}
2821 #else
2822 			    (char_u *)NULL, PV_NONE,
2823 			    {(char_u *)0L, (char_u *)0L}
2824 #endif
2825 			    SCRIPTID_INIT},
2826     {"titlestring", NULL,   P_STRING|P_VI_DEF,
2827 #ifdef FEAT_TITLE
2828 			    (char_u *)&p_titlestring, PV_NONE,
2829 #else
2830 			    (char_u *)NULL, PV_NONE,
2831 #endif
2832 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2833     {"toolbar",     "tb",   P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
2834 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2835 			    (char_u *)&p_toolbar, PV_NONE,
2836 			    {(char_u *)"icons,tooltips", (char_u *)0L}
2837 #else
2838 			    (char_u *)NULL, PV_NONE,
2839 			    {(char_u *)0L, (char_u *)0L}
2840 #endif
2841 			    SCRIPTID_INIT},
2842     {"toolbariconsize",	"tbis", P_STRING|P_VI_DEF,
2843 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
2844 			    (char_u *)&p_tbis, PV_NONE,
2845 			    {(char_u *)"small", (char_u *)0L}
2846 #else
2847 			    (char_u *)NULL, PV_NONE,
2848 			    {(char_u *)0L, (char_u *)0L}
2849 #endif
2850 			    SCRIPTID_INIT},
2851     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
2852 			    (char_u *)&p_ttimeout, PV_NONE,
2853 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2854     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
2855 			    (char_u *)&p_ttm, PV_NONE,
2856 			    {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
2857     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
2858 			    (char_u *)&p_tbi, PV_NONE,
2859 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2860     {"ttyfast",	    "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
2861 			    (char_u *)&p_tf, PV_NONE,
2862 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2863     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2864 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2865 			    (char_u *)&p_ttym, PV_NONE,
2866 #else
2867 			    (char_u *)NULL, PV_NONE,
2868 #endif
2869 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2870     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
2871 			    (char_u *)&p_ttyscroll, PV_NONE,
2872 			    {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
2873     {"ttytype",	    "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2874 			    (char_u *)&T_NAME, PV_NONE,
2875 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2876     {"undodir",     "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2877 								    |P_VI_DEF,
2878 #ifdef FEAT_PERSISTENT_UNDO
2879 			    (char_u *)&p_udir, PV_NONE,
2880 			    {(char_u *)".", (char_u *)0L}
2881 #else
2882 			    (char_u *)NULL, PV_NONE,
2883 			    {(char_u *)0L, (char_u *)0L}
2884 #endif
2885 			    SCRIPTID_INIT},
2886     {"undofile",    "udf",  P_BOOL|P_VI_DEF|P_VIM,
2887 #ifdef FEAT_PERSISTENT_UNDO
2888 			    (char_u *)&p_udf, PV_UDF,
2889 #else
2890 			    (char_u *)NULL, PV_NONE,
2891 #endif
2892 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2893     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
2894 			    (char_u *)&p_ul, PV_UL,
2895 			    {
2896 #if defined(UNIX) || defined(WIN3264) || defined(VMS)
2897 			    (char_u *)1000L,
2898 #else
2899 			    (char_u *)100L,
2900 #endif
2901 				(char_u *)0L} SCRIPTID_INIT},
2902     {"undoreload",  "ur",   P_NUM|P_VI_DEF,
2903 			    (char_u *)&p_ur, PV_NONE,
2904 			    { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
2905     {"updatecount", "uc",   P_NUM|P_VI_DEF,
2906 			    (char_u *)&p_uc, PV_NONE,
2907 			    {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
2908     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
2909 			    (char_u *)&p_ut, PV_NONE,
2910 			    {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
2911     {"verbose",	    "vbs",  P_NUM|P_VI_DEF,
2912 			    (char_u *)&p_verbose, PV_NONE,
2913 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2914     {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915 			    (char_u *)&p_vfile, PV_NONE,
2916 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2917     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2918 #ifdef FEAT_SESSION
2919 			    (char_u *)&p_vdir, PV_NONE,
2920 			    {(char_u *)DFLT_VDIR, (char_u *)0L}
2921 #else
2922 			    (char_u *)NULL, PV_NONE,
2923 			    {(char_u *)0L, (char_u *)0L}
2924 #endif
2925 			    SCRIPTID_INIT},
2926     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2927 #ifdef FEAT_SESSION
2928 			    (char_u *)&p_vop, PV_NONE,
2929 			    {(char_u *)"folds,options,cursor", (char_u *)0L}
2930 #else
2931 			    (char_u *)NULL, PV_NONE,
2932 			    {(char_u *)0L, (char_u *)0L}
2933 #endif
2934 			    SCRIPTID_INIT},
2935     {"viminfo",	    "vi",   P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
2936 #ifdef FEAT_VIMINFO
2937 			    (char_u *)&p_viminfo, PV_NONE,
2938 #if defined(MSWIN)
2939 			    {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2940 #else
2941 # ifdef AMIGA
2942 			    {(char_u *)"",
2943 				 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2944 # else
2945 			    {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2946 # endif
2947 #endif
2948 #else
2949 			    (char_u *)NULL, PV_NONE,
2950 			    {(char_u *)0L, (char_u *)0L}
2951 #endif
2952 			    SCRIPTID_INIT},
2953     {"viminfofile", "vif",  P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2954 #ifdef FEAT_VIMINFO
2955 			    (char_u *)&p_viminfofile, PV_NONE,
2956 			    {(char_u *)"", (char_u *)0L}
2957 #else
2958 			    (char_u *)NULL, PV_NONE,
2959 			    {(char_u *)0L, (char_u *)0L}
2960 #endif
2961 			    SCRIPTID_INIT},
2962     {"virtualedit", "ve",   P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2963 							    |P_VIM|P_CURSWANT,
2964 #ifdef FEAT_VIRTUALEDIT
2965 			    (char_u *)&p_ve, PV_NONE,
2966 			    {(char_u *)"", (char_u *)""}
2967 #else
2968 			    (char_u *)NULL, PV_NONE,
2969 			    {(char_u *)0L, (char_u *)0L}
2970 #endif
2971 			    SCRIPTID_INIT},
2972     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
2973 			    (char_u *)&p_vb, PV_NONE,
2974 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2975     {"w300",	    NULL,   P_NUM|P_VI_DEF,
2976 			    (char_u *)NULL, PV_NONE,
2977 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2978     {"w1200",	    NULL,   P_NUM|P_VI_DEF,
2979 			    (char_u *)NULL, PV_NONE,
2980 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2981     {"w9600",	    NULL,   P_NUM|P_VI_DEF,
2982 			    (char_u *)NULL, PV_NONE,
2983 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2984     {"warn",	    NULL,   P_BOOL|P_VI_DEF,
2985 			    (char_u *)&p_warn, PV_NONE,
2986 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2987     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
2988 			    (char_u *)&p_wiv, PV_NONE,
2989 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2990     {"whichwrap",   "ww",   P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
2991 			    (char_u *)&p_ww, PV_NONE,
2992 			    {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
2993     {"wildchar",    "wc",   P_NUM|P_VIM,
2994 			    (char_u *)&p_wc, PV_NONE,
2995 			    {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2996 			    SCRIPTID_INIT},
2997     {"wildcharm",   "wcm",  P_NUM|P_VI_DEF,
2998 			    (char_u *)&p_wcm, PV_NONE,
2999 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3000     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
3001 #ifdef FEAT_WILDIGN
3002 			    (char_u *)&p_wig, PV_NONE,
3003 #else
3004 			    (char_u *)NULL, PV_NONE,
3005 #endif
3006 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
3007     {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3008 			    (char_u *)&p_wic, PV_NONE,
3009 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3010     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
3011 #ifdef FEAT_WILDMENU
3012 			    (char_u *)&p_wmnu, PV_NONE,
3013 #else
3014 			    (char_u *)NULL, PV_NONE,
3015 #endif
3016 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3017     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
3018 			    (char_u *)&p_wim, PV_NONE,
3019 			    {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
3020     {"wildoptions", "wop",  P_STRING|P_VI_DEF,
3021 #ifdef FEAT_CMDL_COMPL
3022 			    (char_u *)&p_wop, PV_NONE,
3023 			    {(char_u *)"", (char_u *)0L}
3024 #else
3025 			    (char_u *)NULL, PV_NONE,
3026 			    {(char_u *)NULL, (char_u *)0L}
3027 #endif
3028 			    SCRIPTID_INIT},
3029     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
3030 #ifdef FEAT_WAK
3031 			    (char_u *)&p_wak, PV_NONE,
3032 			    {(char_u *)"menu", (char_u *)0L}
3033 #else
3034 			    (char_u *)NULL, PV_NONE,
3035 			    {(char_u *)NULL, (char_u *)0L}
3036 #endif
3037 			    SCRIPTID_INIT},
3038     {"window",	    "wi",   P_NUM|P_VI_DEF,
3039 			    (char_u *)&p_window, PV_NONE,
3040 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3041     {"winheight",   "wh",   P_NUM|P_VI_DEF,
3042 			    (char_u *)&p_wh, PV_NONE,
3043 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3044     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
3045 			    (char_u *)VAR_WIN, PV_WFH,
3046 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3047     {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
3048 			    (char_u *)VAR_WIN, PV_WFW,
3049 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3050     {"winminheight", "wmh", P_NUM|P_VI_DEF,
3051 			    (char_u *)&p_wmh, PV_NONE,
3052 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3053     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
3054 			    (char_u *)&p_wmw, PV_NONE,
3055 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3056     {"winptydll", NULL,	    P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
3057 #if defined(WIN3264) && defined(FEAT_TERMINAL)
3058 			    (char_u *)&p_winptydll, PV_NONE, {
3059 # ifdef _WIN64
3060 			    (char_u *)"winpty64.dll",
3061 # else
3062 			    (char_u *)"winpty32.dll",
3063 # endif
3064 				(char_u *)0L}
3065 #else
3066 			    (char_u *)NULL, PV_NONE,
3067 			    {(char_u *)0L, (char_u *)0L}
3068 #endif
3069 			    SCRIPTID_INIT},
3070     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
3071 			    (char_u *)&p_wiw, PV_NONE,
3072 			    {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
3073     {"wrap",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
3074 			    (char_u *)VAR_WIN, PV_WRAP,
3075 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3076     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
3077 			    (char_u *)&p_wm, PV_WM,
3078 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3079     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
3080 			    (char_u *)&p_ws, PV_NONE,
3081 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3082     {"write",	    NULL,   P_BOOL|P_VI_DEF,
3083 			    (char_u *)&p_write, PV_NONE,
3084 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3085     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
3086 			    (char_u *)&p_wa, PV_NONE,
3087 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3088     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
3089 			    (char_u *)&p_wb, PV_NONE,
3090 			    {
3091 #ifdef FEAT_WRITEBACKUP
3092 			    (char_u *)TRUE,
3093 #else
3094 			    (char_u *)FALSE,
3095 #endif
3096 				(char_u *)0L} SCRIPTID_INIT},
3097     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
3098 			    (char_u *)&p_wd, PV_NONE,
3099 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3100 
3101 /* terminal output codes */
3102 #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
3103 			    (char_u *)&vvv, PV_NONE, \
3104 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
3105 
3106     p_term("t_AB", T_CAB)
3107     p_term("t_AF", T_CAF)
3108     p_term("t_AL", T_CAL)
3109     p_term("t_al", T_AL)
3110     p_term("t_bc", T_BC)
3111     p_term("t_BE", T_BE)
3112     p_term("t_BD", T_BD)
3113     p_term("t_cd", T_CD)
3114     p_term("t_ce", T_CE)
3115     p_term("t_cl", T_CL)
3116     p_term("t_cm", T_CM)
3117     p_term("t_Ce", T_UCE)
3118     p_term("t_Co", T_CCO)
3119     p_term("t_CS", T_CCS)
3120     p_term("t_Cs", T_UCS)
3121     p_term("t_cs", T_CS)
3122     p_term("t_CV", T_CSV)
3123     p_term("t_da", T_DA)
3124     p_term("t_db", T_DB)
3125     p_term("t_DL", T_CDL)
3126     p_term("t_dl", T_DL)
3127     p_term("t_EC", T_CEC)
3128     p_term("t_EI", T_CEI)
3129     p_term("t_fs", T_FS)
3130     p_term("t_GP", T_CGP)
3131     p_term("t_IE", T_CIE)
3132     p_term("t_IS", T_CIS)
3133     p_term("t_ke", T_KE)
3134     p_term("t_ks", T_KS)
3135     p_term("t_le", T_LE)
3136     p_term("t_mb", T_MB)
3137     p_term("t_md", T_MD)
3138     p_term("t_me", T_ME)
3139     p_term("t_mr", T_MR)
3140     p_term("t_ms", T_MS)
3141     p_term("t_nd", T_ND)
3142     p_term("t_op", T_OP)
3143     p_term("t_RF", T_RFG)
3144     p_term("t_RB", T_RBG)
3145     p_term("t_RC", T_CRC)
3146     p_term("t_RI", T_CRI)
3147     p_term("t_RS", T_CRS)
3148     p_term("t_RV", T_CRV)
3149     p_term("t_Sb", T_CSB)
3150     p_term("t_SC", T_CSC)
3151     p_term("t_se", T_SE)
3152     p_term("t_Sf", T_CSF)
3153     p_term("t_SH", T_CSH)
3154     p_term("t_SI", T_CSI)
3155     p_term("t_so", T_SO)
3156     p_term("t_SR", T_CSR)
3157     p_term("t_sr", T_SR)
3158     p_term("t_Te", T_STE)
3159     p_term("t_te", T_TE)
3160     p_term("t_ti", T_TI)
3161     p_term("t_Ts", T_STS)
3162     p_term("t_ts", T_TS)
3163     p_term("t_u7", T_U7)
3164     p_term("t_ue", T_UE)
3165     p_term("t_us", T_US)
3166     p_term("t_ut", T_UT)
3167     p_term("t_vb", T_VB)
3168     p_term("t_ve", T_VE)
3169     p_term("t_vi", T_VI)
3170     p_term("t_VS", T_CVS)
3171     p_term("t_vs", T_VS)
3172     p_term("t_WP", T_CWP)
3173     p_term("t_WS", T_CWS)
3174     p_term("t_xn", T_XN)
3175     p_term("t_xs", T_XS)
3176     p_term("t_ZH", T_CZH)
3177     p_term("t_ZR", T_CZR)
3178     p_term("t_8f", T_8F)
3179     p_term("t_8b", T_8B)
3180 
3181 /* terminal key codes are not in here */
3182 
3183     /* end marker */
3184     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
3185 };
3186 
3187 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3188 
3189 #ifdef FEAT_MBYTE
3190 static char *(p_ambw_values[]) = {"single", "double", NULL};
3191 #endif
3192 static char *(p_bg_values[]) = {"light", "dark", NULL};
3193 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
3194 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
3195 #ifdef FEAT_CRYPT
3196 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
3197 #endif
3198 #ifdef FEAT_CMDL_COMPL
3199 static char *(p_wop_values[]) = {"tagfile", NULL};
3200 #endif
3201 #ifdef FEAT_WAK
3202 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3203 #endif
3204 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
3205 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3206 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
3207 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
3208 #ifdef FEAT_BROWSE
3209 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3210 #endif
3211 #ifdef FEAT_SCROLLBIND
3212 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3213 #endif
3214 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
3215 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3216 #ifdef FEAT_AUTOCMD
3217 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3218 #else
3219 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
3220 #endif
3221 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3222 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3223 #ifdef FEAT_FOLDING
3224 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
3225 # ifdef FEAT_DIFF
3226 				"diff",
3227 # endif
3228 				NULL};
3229 static char *(p_fcl_values[]) = {"all", NULL};
3230 #endif
3231 #ifdef FEAT_INS_EXPAND
3232 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
3233 #endif
3234 #ifdef FEAT_SIGNS
3235 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3236 #endif
3237 
3238 static void set_option_default(int, int opt_flags, int compatible);
3239 static void set_options_default(int opt_flags);
3240 static char_u *term_bg_default(void);
3241 static void did_set_option(int opt_idx, int opt_flags, int new_value);
3242 static char_u *illegal_char(char_u *, int);
3243 #ifdef FEAT_CMDWIN
3244 static char_u *check_cedit(void);
3245 #endif
3246 #ifdef FEAT_TITLE
3247 static void did_set_title(int icon);
3248 #endif
3249 static char_u *option_expand(int opt_idx, char_u *val);
3250 static void didset_options(void);
3251 static void didset_options2(void);
3252 static void check_string_option(char_u **pp);
3253 #if defined(FEAT_EVAL) || defined(PROTO)
3254 static long_u *insecure_flag(int opt_idx, int opt_flags);
3255 #else
3256 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3257 #endif
3258 static void set_string_option_global(int opt_idx, char_u **varp);
3259 static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3260 static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3261 static char_u *set_chars_option(char_u **varp);
3262 #ifdef FEAT_SYN_HL
3263 static int int_cmp(const void *a, const void *b);
3264 #endif
3265 #ifdef FEAT_CLIPBOARD
3266 static char_u *check_clipboard_option(void);
3267 #endif
3268 #ifdef FEAT_SPELL
3269 static char_u *did_set_spell_option(int is_spellfile);
3270 static char_u *compile_cap_prog(synblock_T *synblock);
3271 #endif
3272 #ifdef FEAT_EVAL
3273 static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
3274 #endif
3275 static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276 static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3277 static void check_redraw(long_u flags);
3278 static int findoption(char_u *);
3279 static int find_key_option(char_u *);
3280 static void showoptions(int all, int opt_flags);
3281 static int optval_default(struct vimoption *, char_u *varp);
3282 static void showoneopt(struct vimoption *, int opt_flags);
3283 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3284 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285 static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286 static int  istermoption(struct vimoption *);
3287 static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288 static char_u *get_varp(struct vimoption *);
3289 static void option_value2string(struct vimoption *, int opt_flags);
3290 static void check_winopt(winopt_T *wop);
3291 static int wc_use_keyname(char_u *varp, long *wcp);
3292 #ifdef FEAT_LANGMAP
3293 static void langmap_init(void);
3294 static void langmap_set(void);
3295 #endif
3296 static void paste_option_changed(void);
3297 static void compatible_set(void);
3298 #ifdef FEAT_LINEBREAK
3299 static void fill_breakat_flags(void);
3300 #endif
3301 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302 static int check_opt_strings(char_u *val, char **values, int);
3303 static int check_opt_wim(void);
3304 #ifdef FEAT_LINEBREAK
3305 static int briopt_check(win_T *wp);
3306 #endif
3307 
3308 /*
3309  * Initialize the options, first part.
3310  *
3311  * Called only once from main(), just after creating the first buffer.
3312  */
3313     void
3314 set_init_1(void)
3315 {
3316     char_u	*p;
3317     int		opt_idx;
3318     long_u	n;
3319 
3320 #ifdef FEAT_LANGMAP
3321     langmap_init();
3322 #endif
3323 
3324     /* Be Vi compatible by default */
3325     p_cp = TRUE;
3326 
3327     /* Use POSIX compatibility when $VIM_POSIX is set. */
3328     if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3329     {
3330 	set_string_default("cpo", (char_u *)CPO_ALL);
3331 	set_string_default("shm", (char_u *)"A");
3332     }
3333 
3334     /*
3335      * Find default value for 'shell' option.
3336      * Don't use it if it is empty.
3337      */
3338     if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3339 #if defined(MSWIN)
3340 	    || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3341 # ifdef WIN3264
3342 	    || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
3343 # endif
3344 #endif
3345 	    )
3346 	set_string_default("sh", p);
3347 
3348 #ifdef FEAT_WILDIGN
3349     /*
3350      * Set the default for 'backupskip' to include environment variables for
3351      * temp files.
3352      */
3353     {
3354 # ifdef UNIX
3355 	static char	*(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3356 # else
3357 	static char	*(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3358 # endif
3359 	int		len;
3360 	garray_T	ga;
3361 	int		mustfree;
3362 
3363 	ga_init2(&ga, 1, 100);
3364 	for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3365 	{
3366 	    mustfree = FALSE;
3367 # ifdef UNIX
3368 	    if (*names[n] == NUL)
3369 		p = (char_u *)"/tmp";
3370 	    else
3371 # endif
3372 		p = vim_getenv((char_u *)names[n], &mustfree);
3373 	    if (p != NULL && *p != NUL)
3374 	    {
3375 		/* First time count the NUL, otherwise count the ','. */
3376 		len = (int)STRLEN(p) + 3;
3377 		if (ga_grow(&ga, len) == OK)
3378 		{
3379 		    if (ga.ga_len > 0)
3380 			STRCAT(ga.ga_data, ",");
3381 		    STRCAT(ga.ga_data, p);
3382 		    add_pathsep(ga.ga_data);
3383 		    STRCAT(ga.ga_data, "*");
3384 		    ga.ga_len += len;
3385 		}
3386 	    }
3387 	    if (mustfree)
3388 		vim_free(p);
3389 	}
3390 	if (ga.ga_data != NULL)
3391 	{
3392 	    set_string_default("bsk", ga.ga_data);
3393 	    vim_free(ga.ga_data);
3394 	}
3395     }
3396 #endif
3397 
3398     /*
3399      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3400      */
3401     opt_idx = findoption((char_u *)"maxmemtot");
3402     if (opt_idx >= 0)
3403     {
3404 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3405 	if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3406 #endif
3407 	{
3408 #ifdef HAVE_AVAIL_MEM
3409 	    /* Use amount of memory available at this moment. */
3410 	    n = (mch_avail_mem(FALSE) >> 1);
3411 #else
3412 # ifdef HAVE_TOTAL_MEM
3413 	    /* Use amount of memory available to Vim. */
3414 	    n = (mch_total_mem(FALSE) >> 1);
3415 # else
3416 	    n = (0x7fffffff >> 11);
3417 # endif
3418 #endif
3419 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3420 	    opt_idx = findoption((char_u *)"maxmem");
3421 	    if (opt_idx >= 0)
3422 	    {
3423 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3424 		if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3425 		  || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3426 #endif
3427 		    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3428 	    }
3429 	}
3430     }
3431 
3432 #ifdef FEAT_SEARCHPATH
3433     {
3434 	char_u	*cdpath;
3435 	char_u	*buf;
3436 	int	i;
3437 	int	j;
3438 	int	mustfree = FALSE;
3439 
3440 	/* Initialize the 'cdpath' option's default value. */
3441 	cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3442 	if (cdpath != NULL)
3443 	{
3444 	    buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3445 	    if (buf != NULL)
3446 	    {
3447 		buf[0] = ',';	    /* start with ",", current dir first */
3448 		j = 1;
3449 		for (i = 0; cdpath[i] != NUL; ++i)
3450 		{
3451 		    if (vim_ispathlistsep(cdpath[i]))
3452 			buf[j++] = ',';
3453 		    else
3454 		    {
3455 			if (cdpath[i] == ' ' || cdpath[i] == ',')
3456 			    buf[j++] = '\\';
3457 			buf[j++] = cdpath[i];
3458 		    }
3459 		}
3460 		buf[j] = NUL;
3461 		opt_idx = findoption((char_u *)"cdpath");
3462 		if (opt_idx >= 0)
3463 		{
3464 		    options[opt_idx].def_val[VI_DEFAULT] = buf;
3465 		    options[opt_idx].flags |= P_DEF_ALLOCED;
3466 		}
3467 		else
3468 		    vim_free(buf); /* cannot happen */
3469 	    }
3470 	    if (mustfree)
3471 		vim_free(cdpath);
3472 	}
3473     }
3474 #endif
3475 
3476 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3477     /* Set print encoding on platforms that don't default to latin1 */
3478     set_string_default("penc",
3479 # if defined(MSWIN)
3480 		       (char_u *)"cp1252"
3481 # else
3482 #  ifdef VMS
3483 		       (char_u *)"dec-mcs"
3484 #  else
3485 #   ifdef EBCDIC
3486 		       (char_u *)"ebcdic-uk"
3487 #   else
3488 #    ifdef MAC
3489 		       (char_u *)"mac-roman"
3490 #    else /* HPUX */
3491 		       (char_u *)"hp-roman8"
3492 #    endif
3493 #   endif
3494 #  endif
3495 # endif
3496 		       );
3497 #endif
3498 
3499 #ifdef FEAT_POSTSCRIPT
3500     /* 'printexpr' must be allocated to be able to evaluate it. */
3501     set_string_default("pexpr",
3502 # if defined(MSWIN)
3503 	    (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3504 # else
3505 #  ifdef VMS
3506 	    (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3507 
3508 #  else
3509 	    (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3510 #  endif
3511 # endif
3512 	    );
3513 #endif
3514 
3515     /*
3516      * Set all the options (except the terminal options) to their default
3517      * value.  Also set the global value for local options.
3518      */
3519     set_options_default(0);
3520 
3521 #ifdef FEAT_GUI
3522     if (found_reverse_arg)
3523 	set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3524 #endif
3525 
3526     curbuf->b_p_initialized = TRUE;
3527     curbuf->b_p_ar = -1;	/* no local 'autoread' value */
3528     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
3529     check_buf_options(curbuf);
3530     check_win_options(curwin);
3531     check_options();
3532 
3533     /* Must be before option_expand(), because that one needs vim_isIDc() */
3534     didset_options();
3535 
3536 #ifdef FEAT_SPELL
3537     /* Use the current chartab for the generic chartab. This is not in
3538      * didset_options() because it only depends on 'encoding'. */
3539     init_spell_chartab();
3540 #endif
3541 
3542     /*
3543      * Expand environment variables and things like "~" for the defaults.
3544      * If option_expand() returns non-NULL the variable is expanded.  This can
3545      * only happen for non-indirect options.
3546      * Also set the default to the expanded value, so ":set" does not list
3547      * them.
3548      * Don't set the P_ALLOCED flag, because we don't want to free the
3549      * default.
3550      */
3551     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3552     {
3553 	if ((options[opt_idx].flags & P_GETTEXT)
3554 					      && options[opt_idx].var != NULL)
3555 	    p = (char_u *)_(*(char **)options[opt_idx].var);
3556 	else
3557 	    p = option_expand(opt_idx, NULL);
3558 	if (p != NULL && (p = vim_strsave(p)) != NULL)
3559 	{
3560 	    *(char_u **)options[opt_idx].var = p;
3561 	    /* VIMEXP
3562 	     * Defaults for all expanded options are currently the same for Vi
3563 	     * and Vim.  When this changes, add some code here!  Also need to
3564 	     * split P_DEF_ALLOCED in two.
3565 	     */
3566 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3567 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3568 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3569 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3570 	}
3571     }
3572 
3573     save_file_ff(curbuf);	/* Buffer is unchanged */
3574 
3575 #if defined(FEAT_ARABIC)
3576     /* Detect use of mlterm.
3577      * Mlterm is a terminal emulator akin to xterm that has some special
3578      * abilities (bidi namely).
3579      * NOTE: mlterm's author is being asked to 'set' a variable
3580      *       instead of an environment variable due to inheritance.
3581      */
3582     if (mch_getenv((char_u *)"MLTERM") != NULL)
3583 	set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3584 #endif
3585 
3586     didset_options2();
3587 
3588 #ifdef FEAT_MBYTE
3589 # if defined(WIN3264) && defined(FEAT_GETTEXT)
3590     /*
3591      * If $LANG isn't set, try to get a good value for it.  This makes the
3592      * right language be used automatically.  Don't do this for English.
3593      */
3594     if (mch_getenv((char_u *)"LANG") == NULL)
3595     {
3596 	char	buf[20];
3597 
3598 	/* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3599 	 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3600 	 * only the first two. */
3601 	n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3602 							     (LPTSTR)buf, 20);
3603 	if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3604 	{
3605 	    /* There are a few exceptions (probably more) */
3606 	    if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3607 		STRCPY(buf, "zh_TW");
3608 	    else if (STRNICMP(buf, "chs", 3) == 0
3609 					      || STRNICMP(buf, "zhc", 3) == 0)
3610 		STRCPY(buf, "zh_CN");
3611 	    else if (STRNICMP(buf, "jp", 2) == 0)
3612 		STRCPY(buf, "ja");
3613 	    else
3614 		buf[2] = NUL;		/* truncate to two-letter code */
3615 	    vim_setenv((char_u *)"LANG", (char_u *)buf);
3616 	}
3617     }
3618 # else
3619 #  ifdef MACOS_CONVERT
3620     /* Moved to os_mac_conv.c to avoid dependency problems. */
3621     mac_lang_init();
3622 #  endif
3623 # endif
3624 
3625     /* enc_locale() will try to find the encoding of the current locale. */
3626     p = enc_locale();
3627     if (p != NULL)
3628     {
3629 	char_u *save_enc;
3630 
3631 	/* Try setting 'encoding' and check if the value is valid.
3632 	 * If not, go back to the default "latin1". */
3633 	save_enc = p_enc;
3634 	p_enc = p;
3635 	if (STRCMP(p_enc, "gb18030") == 0)
3636 	{
3637 	    /* We don't support "gb18030", but "cp936" is a good substitute
3638 	     * for practical purposes, thus use that.  It's not an alias to
3639 	     * still support conversion between gb18030 and utf-8. */
3640 	    p_enc = vim_strsave((char_u *)"cp936");
3641 	    vim_free(p);
3642 	}
3643 	if (mb_init() == NULL)
3644 	{
3645 	    opt_idx = findoption((char_u *)"encoding");
3646 	    if (opt_idx >= 0)
3647 	    {
3648 		options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3649 		options[opt_idx].flags |= P_DEF_ALLOCED;
3650 	    }
3651 
3652 #if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
3653 	    if (STRCMP(p_enc, "latin1") == 0
3654 # ifdef FEAT_MBYTE
3655 		    || enc_utf8
3656 # endif
3657 		    )
3658 	    {
3659 		/* Adjust the default for 'isprint' and 'iskeyword' to match
3660 		 * latin1.  Also set the defaults for when 'nocompatible' is
3661 		 * set. */
3662 		set_string_option_direct((char_u *)"isp", -1,
3663 					      ISP_LATIN1, OPT_FREE, SID_NONE);
3664 		set_string_option_direct((char_u *)"isk", -1,
3665 					      ISK_LATIN1, OPT_FREE, SID_NONE);
3666 		opt_idx = findoption((char_u *)"isp");
3667 		if (opt_idx >= 0)
3668 		    options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3669 		opt_idx = findoption((char_u *)"isk");
3670 		if (opt_idx >= 0)
3671 		    options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3672 		(void)init_chartab();
3673 	    }
3674 #endif
3675 
3676 # if defined(WIN3264) && !defined(FEAT_GUI)
3677 	    /* Win32 console: When GetACP() returns a different value from
3678 	     * GetConsoleCP() set 'termencoding'. */
3679 	    if (GetACP() != GetConsoleCP())
3680 	    {
3681 		char	buf[50];
3682 
3683 		sprintf(buf, "cp%ld", (long)GetConsoleCP());
3684 		p_tenc = vim_strsave((char_u *)buf);
3685 		if (p_tenc != NULL)
3686 		{
3687 		    opt_idx = findoption((char_u *)"termencoding");
3688 		    if (opt_idx >= 0)
3689 		    {
3690 			options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3691 			options[opt_idx].flags |= P_DEF_ALLOCED;
3692 		    }
3693 		    convert_setup(&input_conv, p_tenc, p_enc);
3694 		    convert_setup(&output_conv, p_enc, p_tenc);
3695 		}
3696 		else
3697 		    p_tenc = empty_option;
3698 	    }
3699 # endif
3700 # if defined(WIN3264) && defined(FEAT_MBYTE)
3701 	    /* $HOME may have characters in active code page. */
3702 	    init_homedir();
3703 # endif
3704 	}
3705 	else
3706 	{
3707 	    vim_free(p_enc);
3708 	    p_enc = save_enc;
3709 	}
3710     }
3711 #endif
3712 
3713 #ifdef FEAT_MULTI_LANG
3714     /* Set the default for 'helplang'. */
3715     set_helplang_default(get_mess_lang());
3716 #endif
3717 }
3718 
3719 /*
3720  * Set an option to its default value.
3721  * This does not take care of side effects!
3722  */
3723     static void
3724 set_option_default(
3725     int		opt_idx,
3726     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3727     int		compatible)	/* use Vi default value */
3728 {
3729     char_u	*varp;		/* pointer to variable for current option */
3730     int		dvi;		/* index in def_val[] */
3731     long_u	flags;
3732     long_u	*flagsp;
3733     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3734 
3735     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3736     flags = options[opt_idx].flags;
3737     if (varp != NULL)	    /* skip hidden option, nothing to do for it */
3738     {
3739 	dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3740 	if (flags & P_STRING)
3741 	{
3742 	    /* Use set_string_option_direct() for local options to handle
3743 	     * freeing and allocating the value. */
3744 	    if (options[opt_idx].indir != PV_NONE)
3745 		set_string_option_direct(NULL, opt_idx,
3746 				 options[opt_idx].def_val[dvi], opt_flags, 0);
3747 	    else
3748 	    {
3749 		if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3750 		    free_string_option(*(char_u **)(varp));
3751 		*(char_u **)varp = options[opt_idx].def_val[dvi];
3752 		options[opt_idx].flags &= ~P_ALLOCED;
3753 	    }
3754 	}
3755 	else if (flags & P_NUM)
3756 	{
3757 	    if (options[opt_idx].indir == PV_SCROLL)
3758 		win_comp_scroll(curwin);
3759 	    else
3760 	    {
3761 		*(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
3762 		/* May also set global value for local option. */
3763 		if (both)
3764 		    *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3765 								*(long *)varp;
3766 	    }
3767 	}
3768 	else	/* P_BOOL */
3769 	{
3770 	    /* the cast to long is required for Manx C, long_i is needed for
3771 	     * MSVC */
3772 	    *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3773 #ifdef UNIX
3774 	    /* 'modeline' defaults to off for root */
3775 	    if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3776 		*(int *)varp = FALSE;
3777 #endif
3778 	    /* May also set global value for local option. */
3779 	    if (both)
3780 		*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3781 								*(int *)varp;
3782 	}
3783 
3784 	/* The default value is not insecure. */
3785 	flagsp = insecure_flag(opt_idx, opt_flags);
3786 	*flagsp = *flagsp & ~P_INSECURE;
3787     }
3788 
3789 #ifdef FEAT_EVAL
3790     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
3791 #endif
3792 }
3793 
3794 /*
3795  * Set all options (except terminal options) to their default value.
3796  * When "opt_flags" is non-zero skip 'encoding'.
3797  */
3798     static void
3799 set_options_default(
3800     int		opt_flags)	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3801 {
3802     int		i;
3803     win_T	*wp;
3804     tabpage_T	*tp;
3805 
3806     for (i = 0; !istermoption(&options[i]); i++)
3807 	if (!(options[i].flags & P_NODEFAULT)
3808 #if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
3809 		&& (opt_flags == 0
3810 		    || (TRUE
3811 # if defined(FEAT_MBYTE)
3812 			&& options[i].var != (char_u *)&p_enc
3813 # endif
3814 # if defined(FEAT_CRYPT)
3815 			&& options[i].var != (char_u *)&p_cm
3816 			&& options[i].var != (char_u *)&p_key
3817 # endif
3818 			))
3819 #endif
3820 			)
3821 	    set_option_default(i, opt_flags, p_cp);
3822 
3823     /* The 'scroll' option must be computed for all windows. */
3824     FOR_ALL_TAB_WINDOWS(tp, wp)
3825 	win_comp_scroll(wp);
3826 #ifdef FEAT_CINDENT
3827     parse_cino(curbuf);
3828 #endif
3829 }
3830 
3831 /*
3832  * Set the Vi-default value of a string option.
3833  * Used for 'sh', 'backupskip' and 'term'.
3834  */
3835     void
3836 set_string_default(char *name, char_u *val)
3837 {
3838     char_u	*p;
3839     int		opt_idx;
3840 
3841     p = vim_strsave(val);
3842     if (p != NULL)		/* we don't want a NULL */
3843     {
3844 	opt_idx = findoption((char_u *)name);
3845 	if (opt_idx >= 0)
3846 	{
3847 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3848 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3849 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3850 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3851 	}
3852     }
3853 }
3854 
3855 /*
3856  * Set the Vi-default value of a number option.
3857  * Used for 'lines' and 'columns'.
3858  */
3859     void
3860 set_number_default(char *name, long val)
3861 {
3862     int		opt_idx;
3863 
3864     opt_idx = findoption((char_u *)name);
3865     if (opt_idx >= 0)
3866 	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3867 }
3868 
3869 #if defined(EXITFREE) || defined(PROTO)
3870 /*
3871  * Free all options.
3872  */
3873     void
3874 free_all_options(void)
3875 {
3876     int		i;
3877 
3878     for (i = 0; !istermoption(&options[i]); i++)
3879     {
3880 	if (options[i].indir == PV_NONE)
3881 	{
3882 	    /* global option: free value and default value. */
3883 	    if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
3884 		free_string_option(*(char_u **)options[i].var);
3885 	    if (options[i].flags & P_DEF_ALLOCED)
3886 		free_string_option(options[i].def_val[VI_DEFAULT]);
3887 	}
3888 	else if (options[i].var != VAR_WIN
3889 		&& (options[i].flags & P_STRING))
3890 	    /* buffer-local option: free global value */
3891 	    free_string_option(*(char_u **)options[i].var);
3892     }
3893 }
3894 #endif
3895 
3896 
3897 /*
3898  * Initialize the options, part two: After getting Rows and Columns and
3899  * setting 'term'.
3900  */
3901     void
3902 set_init_2(void)
3903 {
3904     int		idx;
3905 
3906     /*
3907      * 'scroll' defaults to half the window height. The stored default is zero,
3908      * which results in the actual value computed from the window height.
3909      */
3910     idx = findoption((char_u *)"scroll");
3911     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3912 	set_option_default(idx, OPT_LOCAL, p_cp);
3913     comp_col();
3914 
3915     /*
3916      * 'window' is only for backwards compatibility with Vi.
3917      * Default is Rows - 1.
3918      */
3919     if (!option_was_set((char_u *)"window"))
3920 	p_window = Rows - 1;
3921     set_number_default("window", Rows - 1);
3922 
3923     /* For DOS console the default is always black. */
3924 #if !((defined(WIN3264)) && !defined(FEAT_GUI))
3925     /*
3926      * If 'background' wasn't set by the user, try guessing the value,
3927      * depending on the terminal name.  Only need to check for terminals
3928      * with a dark background, that can handle color.
3929      */
3930     idx = findoption((char_u *)"bg");
3931     if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3932 						 && *term_bg_default() == 'd')
3933     {
3934 	set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3935 	/* don't mark it as set, when starting the GUI it may be
3936 	 * changed again */
3937 	options[idx].flags &= ~P_WAS_SET;
3938     }
3939 #endif
3940 
3941 #ifdef CURSOR_SHAPE
3942     parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3943 #endif
3944 #ifdef FEAT_MOUSESHAPE
3945     parse_shape_opt(SHAPE_MOUSE);  /* set mouse shapes from 'mouseshape' */
3946 #endif
3947 #ifdef FEAT_PRINTER
3948     (void)parse_printoptions();	    /* parse 'printoptions' default value */
3949 #endif
3950 }
3951 
3952 /*
3953  * Return "dark" or "light" depending on the kind of terminal.
3954  * This is just guessing!  Recognized are:
3955  * "linux"	    Linux console
3956  * "screen.linux"   Linux console with screen
3957  * "cygwin.*"	    Cygwin shell
3958  * "putty.*"	    Putty program
3959  * We also check the COLORFGBG environment variable, which is set by
3960  * rxvt and derivatives. This variable contains either two or three
3961  * values separated by semicolons; we want the last value in either
3962  * case. If this value is 0-6 or 8, our background is dark.
3963  */
3964     static char_u *
3965 term_bg_default(void)
3966 {
3967 #if defined(WIN3264)
3968     /* DOS console is nearly always black */
3969     return (char_u *)"dark";
3970 #else
3971     char_u	*p;
3972 
3973     if (STRCMP(T_NAME, "linux") == 0
3974 	    || STRCMP(T_NAME, "screen.linux") == 0
3975 	    || STRNCMP(T_NAME, "cygwin", 6) == 0
3976 	    || STRNCMP(T_NAME, "putty", 5) == 0
3977 	    || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3978 		&& (p = vim_strrchr(p, ';')) != NULL
3979 		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3980 		&& p[2] == NUL))
3981 	return (char_u *)"dark";
3982     return (char_u *)"light";
3983 #endif
3984 }
3985 
3986 /*
3987  * Initialize the options, part three: After reading the .vimrc
3988  */
3989     void
3990 set_init_3(void)
3991 {
3992 #if defined(UNIX) || defined(WIN3264)
3993 /*
3994  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3995  * This is done after other initializations, where 'shell' might have been
3996  * set, but only if they have not been set before.
3997  */
3998     char_u  *p;
3999     int	    idx_srr;
4000     int	    do_srr;
4001 # ifdef FEAT_QUICKFIX
4002     int	    idx_sp;
4003     int	    do_sp;
4004 # endif
4005 
4006     idx_srr = findoption((char_u *)"srr");
4007     if (idx_srr < 0)
4008 	do_srr = FALSE;
4009     else
4010 	do_srr = !(options[idx_srr].flags & P_WAS_SET);
4011 # ifdef FEAT_QUICKFIX
4012     idx_sp = findoption((char_u *)"sp");
4013     if (idx_sp < 0)
4014 	do_sp = FALSE;
4015     else
4016 	do_sp = !(options[idx_sp].flags & P_WAS_SET);
4017 # endif
4018     p = get_isolated_shell_name();
4019     if (p != NULL)
4020     {
4021 	/*
4022 	 * Default for p_sp is "| tee", for p_srr is ">".
4023 	 * For known shells it is changed here to include stderr.
4024 	 */
4025 	if (	   fnamecmp(p, "csh") == 0
4026 		|| fnamecmp(p, "tcsh") == 0
4027 # if defined(WIN3264)	/* also check with .exe extension */
4028 		|| fnamecmp(p, "csh.exe") == 0
4029 		|| fnamecmp(p, "tcsh.exe") == 0
4030 # endif
4031 	   )
4032 	{
4033 # if defined(FEAT_QUICKFIX)
4034 	    if (do_sp)
4035 	    {
4036 #  ifdef WIN3264
4037 		p_sp = (char_u *)">&";
4038 #  else
4039 		p_sp = (char_u *)"|& tee";
4040 #  endif
4041 		options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4042 	    }
4043 # endif
4044 	    if (do_srr)
4045 	    {
4046 		p_srr = (char_u *)">&";
4047 		options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4048 	    }
4049 	}
4050 	else
4051 	    /* Always use bourne shell style redirection if we reach this */
4052 	    if (       fnamecmp(p, "sh") == 0
4053 		    || fnamecmp(p, "ksh") == 0
4054 		    || fnamecmp(p, "mksh") == 0
4055 		    || fnamecmp(p, "pdksh") == 0
4056 		    || fnamecmp(p, "zsh") == 0
4057 		    || fnamecmp(p, "zsh-beta") == 0
4058 		    || fnamecmp(p, "bash") == 0
4059 		    || fnamecmp(p, "fish") == 0
4060 # ifdef WIN3264
4061 		    || fnamecmp(p, "cmd") == 0
4062 		    || fnamecmp(p, "sh.exe") == 0
4063 		    || fnamecmp(p, "ksh.exe") == 0
4064 		    || fnamecmp(p, "mksh.exe") == 0
4065 		    || fnamecmp(p, "pdksh.exe") == 0
4066 		    || fnamecmp(p, "zsh.exe") == 0
4067 		    || fnamecmp(p, "zsh-beta.exe") == 0
4068 		    || fnamecmp(p, "bash.exe") == 0
4069 		    || fnamecmp(p, "cmd.exe") == 0
4070 # endif
4071 		    )
4072 	    {
4073 # if defined(FEAT_QUICKFIX)
4074 		if (do_sp)
4075 		{
4076 #  ifdef WIN3264
4077 		    p_sp = (char_u *)">%s 2>&1";
4078 #  else
4079 		    p_sp = (char_u *)"2>&1| tee";
4080 #  endif
4081 		    options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4082 		}
4083 # endif
4084 		if (do_srr)
4085 		{
4086 		    p_srr = (char_u *)">%s 2>&1";
4087 		    options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4088 		}
4089 	    }
4090 	vim_free(p);
4091     }
4092 #endif
4093 
4094 #if defined(WIN3264)
4095     /*
4096      * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4097      * 'shell' option.
4098      * This is done after other initializations, where 'shell' might have been
4099      * set, but only if they have not been set before.  Default for p_shcf is
4100      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
4101      * "-c" and "\"".  And for Win32 we need to set p_sxq instead.
4102      */
4103     if (strstr((char *)gettail(p_sh), "sh") != NULL)
4104     {
4105 	int	idx3;
4106 
4107 	idx3 = findoption((char_u *)"shcf");
4108 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4109 	{
4110 	    p_shcf = (char_u *)"-c";
4111 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4112 	}
4113 
4114 	/* Somehow Win32 requires the quotes around the redirection too */
4115 	idx3 = findoption((char_u *)"sxq");
4116 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4117 	{
4118 	    p_sxq = (char_u *)"\"";
4119 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4120 	}
4121     }
4122     else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4123     {
4124 	int	idx3;
4125 
4126 	/*
4127 	 * cmd.exe on Windows will strip the first and last double quote given
4128 	 * on the command line, e.g. most of the time things like:
4129 	 *   cmd /c "my path/to/echo" "my args to echo"
4130 	 * become:
4131 	 *   my path/to/echo" "my args to echo
4132 	 * when executed.
4133 	 *
4134 	 * To avoid this, set shellxquote to surround the command in
4135 	 * parenthesis.  This appears to make most commands work, without
4136 	 * breaking commands that worked previously, such as
4137 	 * '"path with spaces/cmd" "a&b"'.
4138 	 */
4139 	idx3 = findoption((char_u *)"sxq");
4140 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4141 	{
4142 	    p_sxq = (char_u *)"(";
4143 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4144 	}
4145 
4146 	idx3 = findoption((char_u *)"shcf");
4147 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4148 	{
4149 	    p_shcf = (char_u *)"/c";
4150 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4151 	}
4152     }
4153 #endif
4154 
4155     if (BUFEMPTY())
4156     {
4157 	int idx_ffs = findoption((char_u *)"ffs");
4158 
4159 	/* Apply the first entry of 'fileformats' to the initial buffer. */
4160 	if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4161 	    set_fileformat(default_fileformat(), OPT_LOCAL);
4162     }
4163 
4164 #ifdef FEAT_TITLE
4165     set_title_defaults();
4166 #endif
4167 }
4168 
4169 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
4170 /*
4171  * When 'helplang' is still at its default value, set it to "lang".
4172  * Only the first two characters of "lang" are used.
4173  */
4174     void
4175 set_helplang_default(char_u *lang)
4176 {
4177     int		idx;
4178 
4179     if (lang == NULL || STRLEN(lang) < 2)	/* safety check */
4180 	return;
4181     idx = findoption((char_u *)"hlg");
4182     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
4183     {
4184 	if (options[idx].flags & P_ALLOCED)
4185 	    free_string_option(p_hlg);
4186 	p_hlg = vim_strsave(lang);
4187 	if (p_hlg == NULL)
4188 	    p_hlg = empty_option;
4189 	else
4190 	{
4191 	    /* zh_CN becomes "cn", zh_TW becomes "tw". */
4192 	    if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4193 	    {
4194 		p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4195 		p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4196 	    }
4197 	    p_hlg[2] = NUL;
4198 	}
4199 	options[idx].flags |= P_ALLOCED;
4200     }
4201 }
4202 #endif
4203 
4204 #ifdef FEAT_GUI
4205 static char_u *gui_bg_default(void);
4206 
4207     static char_u *
4208 gui_bg_default(void)
4209 {
4210     if (gui_get_lightness(gui.back_pixel) < 127)
4211 	return (char_u *)"dark";
4212     return (char_u *)"light";
4213 }
4214 
4215 /*
4216  * Option initializations that can only be done after opening the GUI window.
4217  */
4218     void
4219 init_gui_options(void)
4220 {
4221     /* Set the 'background' option according to the lightness of the
4222      * background color, unless the user has set it already. */
4223     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4224     {
4225 	set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4226 	highlight_changed();
4227     }
4228 }
4229 #endif
4230 
4231 #ifdef FEAT_TITLE
4232 /*
4233  * 'title' and 'icon' only default to true if they have not been set or reset
4234  * in .vimrc and we can read the old value.
4235  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4236  * they can be reset.  This reduces startup time when using X on a remote
4237  * machine.
4238  */
4239     void
4240 set_title_defaults(void)
4241 {
4242     int	    idx1;
4243     long    val;
4244 
4245     /*
4246      * If GUI is (going to be) used, we can always set the window title and
4247      * icon name.  Saves a bit of time, because the X11 display server does
4248      * not need to be contacted.
4249      */
4250     idx1 = findoption((char_u *)"title");
4251     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4252     {
4253 #ifdef FEAT_GUI
4254 	if (gui.starting || gui.in_use)
4255 	    val = TRUE;
4256 	else
4257 #endif
4258 	    val = mch_can_restore_title();
4259 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4260 	p_title = val;
4261     }
4262     idx1 = findoption((char_u *)"icon");
4263     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4264     {
4265 #ifdef FEAT_GUI
4266 	if (gui.starting || gui.in_use)
4267 	    val = TRUE;
4268 	else
4269 #endif
4270 	    val = mch_can_restore_icon();
4271 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4272 	p_icon = val;
4273     }
4274 }
4275 #endif
4276 
4277 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4278     static void
4279 trigger_optionsset_string(
4280 	int	opt_idx,
4281 	int	opt_flags,
4282 	char_u *oldval,
4283 	char_u *newval)
4284 {
4285     if (oldval != NULL && newval != NULL)
4286     {
4287 	char_u buf_type[7];
4288 
4289 	sprintf((char *)buf_type, "%s",
4290 	    (opt_flags & OPT_LOCAL) ? "local" : "global");
4291 	set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4292 	set_vim_var_string(VV_OPTION_NEW, newval, -1);
4293 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4294 	apply_autocmds(EVENT_OPTIONSET,
4295 		       (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4296 	reset_v_option_vars();
4297     }
4298 }
4299 #endif
4300 
4301 /*
4302  * Parse 'arg' for option settings.
4303  *
4304  * 'arg' may be IObuff, but only when no errors can be present and option
4305  * does not need to be expanded with option_expand().
4306  * "opt_flags":
4307  * 0 for ":set"
4308  * OPT_GLOBAL   for ":setglobal"
4309  * OPT_LOCAL    for ":setlocal" and a modeline
4310  * OPT_MODELINE for a modeline
4311  * OPT_WINONLY  to only set window-local options
4312  * OPT_NOWIN	to skip setting window-local options
4313  *
4314  * returns FAIL if an error is detected, OK otherwise
4315  */
4316     int
4317 do_set(
4318     char_u	*arg,		/* option string (may be written to!) */
4319     int		opt_flags)
4320 {
4321     int		opt_idx;
4322     char_u	*errmsg;
4323     char_u	errbuf[80];
4324     char_u	*startarg;
4325     int		prefix;	/* 1: nothing, 0: "no", 2: "inv" in front of name */
4326     int		nextchar;	    /* next non-white char after option name */
4327     int		afterchar;	    /* character just after option name */
4328     int		len;
4329     int		i;
4330     varnumber_T	value;
4331     int		key;
4332     long_u	flags;		    /* flags for current option */
4333     char_u	*varp = NULL;	    /* pointer to variable for current option */
4334     int		did_show = FALSE;   /* already showed one value */
4335     int		adding;		    /* "opt+=arg" */
4336     int		prepending;	    /* "opt^=arg" */
4337     int		removing;	    /* "opt-=arg" */
4338     int		cp_val = 0;
4339     char_u	key_name[2];
4340 
4341     if (*arg == NUL)
4342     {
4343 	showoptions(0, opt_flags);
4344 	did_show = TRUE;
4345 	goto theend;
4346     }
4347 
4348     while (*arg != NUL)		/* loop to process all options */
4349     {
4350 	errmsg = NULL;
4351 	startarg = arg;		/* remember for error message */
4352 
4353 	if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4354 						&& !(opt_flags & OPT_MODELINE))
4355 	{
4356 	    /*
4357 	     * ":set all"  show all options.
4358 	     * ":set all&" set all options to their default value.
4359 	     */
4360 	    arg += 3;
4361 	    if (*arg == '&')
4362 	    {
4363 		++arg;
4364 		/* Only for :set command set global value of local options. */
4365 		set_options_default(OPT_FREE | opt_flags);
4366 		didset_options();
4367 		didset_options2();
4368 		redraw_all_later(CLEAR);
4369 	    }
4370 	    else
4371 	    {
4372 		showoptions(1, opt_flags);
4373 		did_show = TRUE;
4374 	    }
4375 	}
4376 	else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4377 	{
4378 	    showoptions(2, opt_flags);
4379 	    show_termcodes();
4380 	    did_show = TRUE;
4381 	    arg += 7;
4382 	}
4383 	else
4384 	{
4385 	    prefix = 1;
4386 	    if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4387 	    {
4388 		prefix = 0;
4389 		arg += 2;
4390 	    }
4391 	    else if (STRNCMP(arg, "inv", 3) == 0)
4392 	    {
4393 		prefix = 2;
4394 		arg += 3;
4395 	    }
4396 
4397 	    /* find end of name */
4398 	    key = 0;
4399 	    if (*arg == '<')
4400 	    {
4401 		nextchar = 0;
4402 		opt_idx = -1;
4403 		/* look out for <t_>;> */
4404 		if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4405 		    len = 5;
4406 		else
4407 		{
4408 		    len = 1;
4409 		    while (arg[len] != NUL && arg[len] != '>')
4410 			++len;
4411 		}
4412 		if (arg[len] != '>')
4413 		{
4414 		    errmsg = e_invarg;
4415 		    goto skip;
4416 		}
4417 		arg[len] = NUL;			    /* put NUL after name */
4418 		if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4419 		    opt_idx = findoption(arg + 1);
4420 		arg[len++] = '>';		    /* restore '>' */
4421 		if (opt_idx == -1)
4422 		    key = find_key_option(arg + 1);
4423 	    }
4424 	    else
4425 	    {
4426 		len = 0;
4427 		/*
4428 		 * The two characters after "t_" may not be alphanumeric.
4429 		 */
4430 		if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4431 		    len = 4;
4432 		else
4433 		    while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4434 			++len;
4435 		nextchar = arg[len];
4436 		arg[len] = NUL;			    /* put NUL after name */
4437 		opt_idx = findoption(arg);
4438 		arg[len] = nextchar;		    /* restore nextchar */
4439 		if (opt_idx == -1)
4440 		    key = find_key_option(arg);
4441 	    }
4442 
4443 	    /* remember character after option name */
4444 	    afterchar = arg[len];
4445 
4446 	    /* skip white space, allow ":set ai  ?" */
4447 	    while (VIM_ISWHITE(arg[len]))
4448 		++len;
4449 
4450 	    adding = FALSE;
4451 	    prepending = FALSE;
4452 	    removing = FALSE;
4453 	    if (arg[len] != NUL && arg[len + 1] == '=')
4454 	    {
4455 		if (arg[len] == '+')
4456 		{
4457 		    adding = TRUE;		/* "+=" */
4458 		    ++len;
4459 		}
4460 		else if (arg[len] == '^')
4461 		{
4462 		    prepending = TRUE;		/* "^=" */
4463 		    ++len;
4464 		}
4465 		else if (arg[len] == '-')
4466 		{
4467 		    removing = TRUE;		/* "-=" */
4468 		    ++len;
4469 		}
4470 	    }
4471 	    nextchar = arg[len];
4472 
4473 	    if (opt_idx == -1 && key == 0)	/* found a mismatch: skip */
4474 	    {
4475 		errmsg = (char_u *)N_("E518: Unknown option");
4476 		goto skip;
4477 	    }
4478 
4479 	    if (opt_idx >= 0)
4480 	    {
4481 		if (options[opt_idx].var == NULL)   /* hidden option: skip */
4482 		{
4483 		    /* Only give an error message when requesting the value of
4484 		     * a hidden option, ignore setting it. */
4485 		    if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4486 			    && (!(options[opt_idx].flags & P_BOOL)
4487 				|| nextchar == '?'))
4488 			errmsg = (char_u *)N_("E519: Option not supported");
4489 		    goto skip;
4490 		}
4491 
4492 		flags = options[opt_idx].flags;
4493 		varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4494 	    }
4495 	    else
4496 	    {
4497 		flags = P_STRING;
4498 		if (key < 0)
4499 		{
4500 		    key_name[0] = KEY2TERMCAP0(key);
4501 		    key_name[1] = KEY2TERMCAP1(key);
4502 		}
4503 		else
4504 		{
4505 		    key_name[0] = KS_KEY;
4506 		    key_name[1] = (key & 0xff);
4507 		}
4508 	    }
4509 
4510 	    /* Skip all options that are not window-local (used when showing
4511 	     * an already loaded buffer in a window). */
4512 	    if ((opt_flags & OPT_WINONLY)
4513 			  && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4514 		goto skip;
4515 
4516 	    /* Skip all options that are window-local (used for :vimgrep). */
4517 	    if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4518 					   && options[opt_idx].var == VAR_WIN)
4519 		goto skip;
4520 
4521 	    /* Disallow changing some options from modelines. */
4522 	    if (opt_flags & OPT_MODELINE)
4523 	    {
4524 		if (flags & (P_SECURE | P_NO_ML))
4525 		{
4526 		    errmsg = (char_u *)_("E520: Not allowed in a modeline");
4527 		    goto skip;
4528 		}
4529 #ifdef FEAT_DIFF
4530 		/* In diff mode some options are overruled.  This avoids that
4531 		 * 'foldmethod' becomes "marker" instead of "diff" and that
4532 		 * "wrap" gets set. */
4533 		if (curwin->w_p_diff
4534 			&& opt_idx >= 0  /* shut up coverity warning */
4535 			&& (
4536 #ifdef FEAT_FOLDING
4537 			    options[opt_idx].indir == PV_FDM ||
4538 #endif
4539 			    options[opt_idx].indir == PV_WRAP))
4540 		    goto skip;
4541 #endif
4542 	    }
4543 
4544 #ifdef HAVE_SANDBOX
4545 	    /* Disallow changing some options in the sandbox */
4546 	    if (sandbox != 0 && (flags & P_SECURE))
4547 	    {
4548 		errmsg = (char_u *)_(e_sandbox);
4549 		goto skip;
4550 	    }
4551 #endif
4552 
4553 	    if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4554 	    {
4555 		arg += len;
4556 		cp_val = p_cp;
4557 		if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4558 		{
4559 		    if (arg[3] == 'm')	/* "opt&vim": set to Vim default */
4560 		    {
4561 			cp_val = FALSE;
4562 			arg += 3;
4563 		    }
4564 		    else		/* "opt&vi": set to Vi default */
4565 		    {
4566 			cp_val = TRUE;
4567 			arg += 2;
4568 		    }
4569 		}
4570 		if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4571 			&& arg[1] != NUL && !VIM_ISWHITE(arg[1]))
4572 		{
4573 		    errmsg = e_trailing;
4574 		    goto skip;
4575 		}
4576 	    }
4577 
4578 	    /*
4579 	     * allow '=' and ':' for hystorical reasons (MSDOS command.com
4580 	     * allows only one '=' character per "set" command line. grrr. (jw)
4581 	     */
4582 	    if (nextchar == '?'
4583 		    || (prefix == 1
4584 			&& vim_strchr((char_u *)"=:&<", nextchar) == NULL
4585 			&& !(flags & P_BOOL)))
4586 	    {
4587 		/*
4588 		 * print value
4589 		 */
4590 		if (did_show)
4591 		    msg_putchar('\n');	    /* cursor below last one */
4592 		else
4593 		{
4594 		    gotocmdline(TRUE);	    /* cursor at status line */
4595 		    did_show = TRUE;	    /* remember that we did a line */
4596 		}
4597 		if (opt_idx >= 0)
4598 		{
4599 		    showoneopt(&options[opt_idx], opt_flags);
4600 #ifdef FEAT_EVAL
4601 		    if (p_verbose > 0)
4602 		    {
4603 			/* Mention where the option was last set. */
4604 			if (varp == options[opt_idx].var)
4605 			    last_set_msg(options[opt_idx].scriptID);
4606 			else if ((int)options[opt_idx].indir & PV_WIN)
4607 			    last_set_msg(curwin->w_p_scriptID[
4608 				      (int)options[opt_idx].indir & PV_MASK]);
4609 			else if ((int)options[opt_idx].indir & PV_BUF)
4610 			    last_set_msg(curbuf->b_p_scriptID[
4611 				      (int)options[opt_idx].indir & PV_MASK]);
4612 		    }
4613 #endif
4614 		}
4615 		else
4616 		{
4617 		    char_u	    *p;
4618 
4619 		    p = find_termcode(key_name);
4620 		    if (p == NULL)
4621 		    {
4622 			errmsg = (char_u *)N_("E846: Key code not set");
4623 			goto skip;
4624 		    }
4625 		    else
4626 			(void)show_one_termcode(key_name, p, TRUE);
4627 		}
4628 		if (nextchar != '?'
4629 			&& nextchar != NUL && !VIM_ISWHITE(afterchar))
4630 		    errmsg = e_trailing;
4631 	    }
4632 	    else
4633 	    {
4634 		if (flags & P_BOOL)		    /* boolean */
4635 		{
4636 		    if (nextchar == '=' || nextchar == ':')
4637 		    {
4638 			errmsg = e_invarg;
4639 			goto skip;
4640 		    }
4641 
4642 		    /*
4643 		     * ":set opt!": invert
4644 		     * ":set opt&": reset to default value
4645 		     * ":set opt<": reset to global value
4646 		     */
4647 		    if (nextchar == '!')
4648 			value = *(int *)(varp) ^ 1;
4649 		    else if (nextchar == '&')
4650 			value = (int)(long)(long_i)options[opt_idx].def_val[
4651 						((flags & P_VI_DEF) || cp_val)
4652 						 ?  VI_DEFAULT : VIM_DEFAULT];
4653 		    else if (nextchar == '<')
4654 		    {
4655 			/* For 'autoread' -1 means to use global value. */
4656 			if ((int *)varp == &curbuf->b_p_ar
4657 						    && opt_flags == OPT_LOCAL)
4658 			    value = -1;
4659 			else
4660 			    value = *(int *)get_varp_scope(&(options[opt_idx]),
4661 								  OPT_GLOBAL);
4662 		    }
4663 		    else
4664 		    {
4665 			/*
4666 			 * ":set invopt": invert
4667 			 * ":set opt" or ":set noopt": set or reset
4668 			 */
4669 			if (nextchar != NUL && !VIM_ISWHITE(afterchar))
4670 			{
4671 			    errmsg = e_trailing;
4672 			    goto skip;
4673 			}
4674 			if (prefix == 2)	/* inv */
4675 			    value = *(int *)(varp) ^ 1;
4676 			else
4677 			    value = prefix;
4678 		    }
4679 
4680 		    errmsg = set_bool_option(opt_idx, varp, (int)value,
4681 								   opt_flags);
4682 		}
4683 		else				    /* numeric or string */
4684 		{
4685 		    if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4686 							       || prefix != 1)
4687 		    {
4688 			errmsg = e_invarg;
4689 			goto skip;
4690 		    }
4691 
4692 		    if (flags & P_NUM)		    /* numeric */
4693 		    {
4694 			/*
4695 			 * Different ways to set a number option:
4696 			 * &	    set to default value
4697 			 * <	    set to global value
4698 			 * <xx>	    accept special key codes for 'wildchar'
4699 			 * c	    accept any non-digit for 'wildchar'
4700 			 * [-]0-9   set number
4701 			 * other    error
4702 			 */
4703 			++arg;
4704 			if (nextchar == '&')
4705 			    value = (long)(long_i)options[opt_idx].def_val[
4706 						((flags & P_VI_DEF) || cp_val)
4707 						 ?  VI_DEFAULT : VIM_DEFAULT];
4708 			else if (nextchar == '<')
4709 			{
4710 			    /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4711 			     * use the global value. */
4712 			    if ((long *)varp == &curbuf->b_p_ul
4713 						    && opt_flags == OPT_LOCAL)
4714 				value = NO_LOCAL_UNDOLEVEL;
4715 			    else
4716 				value = *(long *)get_varp_scope(
4717 					     &(options[opt_idx]), OPT_GLOBAL);
4718 			}
4719 			else if (((long *)varp == &p_wc
4720 				    || (long *)varp == &p_wcm)
4721 				&& (*arg == '<'
4722 				    || *arg == '^'
4723 				    || (*arg != NUL
4724 					&& (!arg[1] || VIM_ISWHITE(arg[1]))
4725 					&& !VIM_ISDIGIT(*arg))))
4726 			{
4727 			    value = string_to_key(arg, FALSE);
4728 			    if (value == 0 && (long *)varp != &p_wcm)
4729 			    {
4730 				errmsg = e_invarg;
4731 				goto skip;
4732 			    }
4733 			}
4734 			else if (*arg == '-' || VIM_ISDIGIT(*arg))
4735 			{
4736 			    /* Allow negative (for 'undolevels'), octal and
4737 			     * hex numbers. */
4738 			    vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4739 							     &value, NULL, 0);
4740 			    if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
4741 			    {
4742 				errmsg = e_invarg;
4743 				goto skip;
4744 			    }
4745 			}
4746 			else
4747 			{
4748 			    errmsg = (char_u *)N_("E521: Number required after =");
4749 			    goto skip;
4750 			}
4751 
4752 			if (adding)
4753 			    value = *(long *)varp + value;
4754 			if (prepending)
4755 			    value = *(long *)varp * value;
4756 			if (removing)
4757 			    value = *(long *)varp - value;
4758 			errmsg = set_num_option(opt_idx, varp, value,
4759 					   errbuf, sizeof(errbuf), opt_flags);
4760 		    }
4761 		    else if (opt_idx >= 0)		    /* string */
4762 		    {
4763 			char_u	  *save_arg = NULL;
4764 			char_u	  *s = NULL;
4765 			char_u	  *oldval = NULL; /* previous value if *varp */
4766 			char_u	  *newval;
4767 			char_u	  *origval = NULL;
4768 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4769 			char_u	  *saved_origval = NULL;
4770 			char_u	  *saved_newval = NULL;
4771 #endif
4772 			unsigned  newlen;
4773 			int	  comma;
4774 			int	  bs;
4775 			int	  new_value_alloced;	/* new string option
4776 							   was allocated */
4777 
4778 			/* When using ":set opt=val" for a global option
4779 			 * with a local value the local value will be
4780 			 * reset, use the global value here. */
4781 			if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4782 				&& ((int)options[opt_idx].indir & PV_BOTH))
4783 			    varp = options[opt_idx].var;
4784 
4785 			/* The old value is kept until we are sure that the
4786 			 * new value is valid. */
4787 			oldval = *(char_u **)varp;
4788 
4789 			/* When setting the local value of a global
4790 			 * option, the old value may be the global value. */
4791 			if (((int)options[opt_idx].indir & PV_BOTH)
4792 					       && (opt_flags & OPT_LOCAL))
4793 			    origval = *(char_u **)get_varp(
4794 						       &options[opt_idx]);
4795 			else
4796 			    origval = oldval;
4797 
4798 			if (nextchar == '&')	/* set to default val */
4799 			{
4800 			    newval = options[opt_idx].def_val[
4801 						((flags & P_VI_DEF) || cp_val)
4802 						 ?  VI_DEFAULT : VIM_DEFAULT];
4803 			    if ((char_u **)varp == &p_bg)
4804 			    {
4805 				/* guess the value of 'background' */
4806 #ifdef FEAT_GUI
4807 				if (gui.in_use)
4808 				    newval = gui_bg_default();
4809 				else
4810 #endif
4811 				    newval = term_bg_default();
4812 			    }
4813 
4814 			    /* expand environment variables and ~ (since the
4815 			     * default value was already expanded, only
4816 			     * required when an environment variable was set
4817 			     * later */
4818 			    if (newval == NULL)
4819 				newval = empty_option;
4820 			    else
4821 			    {
4822 				s = option_expand(opt_idx, newval);
4823 				if (s == NULL)
4824 				    s = newval;
4825 				newval = vim_strsave(s);
4826 			    }
4827 			    new_value_alloced = TRUE;
4828 			}
4829 			else if (nextchar == '<')	/* set to global val */
4830 			{
4831 			    newval = vim_strsave(*(char_u **)get_varp_scope(
4832 					     &(options[opt_idx]), OPT_GLOBAL));
4833 			    new_value_alloced = TRUE;
4834 			}
4835 			else
4836 			{
4837 			    ++arg;	/* jump to after the '=' or ':' */
4838 
4839 			    /*
4840 			     * Set 'keywordprg' to ":help" if an empty
4841 			     * value was passed to :set by the user.
4842 			     * Misuse errbuf[] for the resulting string.
4843 			     */
4844 			    if (varp == (char_u *)&p_kp
4845 					      && (*arg == NUL || *arg == ' '))
4846 			    {
4847 				STRCPY(errbuf, ":help");
4848 				save_arg = arg;
4849 				arg = errbuf;
4850 			    }
4851 			    /*
4852 			     * Convert 'backspace' number to string, for
4853 			     * adding, prepending and removing string.
4854 			     */
4855 			    else if (varp == (char_u *)&p_bs
4856 					 && VIM_ISDIGIT(**(char_u **)varp))
4857 			    {
4858 				i = getdigits((char_u **)varp);
4859 				switch (i)
4860 				{
4861 				    case 0:
4862 					*(char_u **)varp = empty_option;
4863 					break;
4864 				    case 1:
4865 					*(char_u **)varp = vim_strsave(
4866 						      (char_u *)"indent,eol");
4867 					break;
4868 				    case 2:
4869 					*(char_u **)varp = vim_strsave(
4870 						(char_u *)"indent,eol,start");
4871 					break;
4872 				}
4873 				vim_free(oldval);
4874 				if (origval == oldval)
4875 				    origval = *(char_u **)varp;
4876 				oldval = *(char_u **)varp;
4877 			    }
4878 			    /*
4879 			     * Convert 'whichwrap' number to string, for
4880 			     * backwards compatibility with Vim 3.0.
4881 			     * Misuse errbuf[] for the resulting string.
4882 			     */
4883 			    else if (varp == (char_u *)&p_ww
4884 							 && VIM_ISDIGIT(*arg))
4885 			    {
4886 				*errbuf = NUL;
4887 				i = getdigits(&arg);
4888 				if (i & 1)
4889 				    STRCAT(errbuf, "b,");
4890 				if (i & 2)
4891 				    STRCAT(errbuf, "s,");
4892 				if (i & 4)
4893 				    STRCAT(errbuf, "h,l,");
4894 				if (i & 8)
4895 				    STRCAT(errbuf, "<,>,");
4896 				if (i & 16)
4897 				    STRCAT(errbuf, "[,],");
4898 				if (*errbuf != NUL)	/* remove trailing , */
4899 				    errbuf[STRLEN(errbuf) - 1] = NUL;
4900 				save_arg = arg;
4901 				arg = errbuf;
4902 			    }
4903 			    /*
4904 			     * Remove '>' before 'dir' and 'bdir', for
4905 			     * backwards compatibility with version 3.0
4906 			     */
4907 			    else if (  *arg == '>'
4908 				    && (varp == (char_u *)&p_dir
4909 					    || varp == (char_u *)&p_bdir))
4910 			    {
4911 				++arg;
4912 			    }
4913 
4914 			    /*
4915 			     * Copy the new string into allocated memory.
4916 			     * Can't use set_string_option_direct(), because
4917 			     * we need to remove the backslashes.
4918 			     */
4919 			    /* get a bit too much */
4920 			    newlen = (unsigned)STRLEN(arg) + 1;
4921 			    if (adding || prepending || removing)
4922 				newlen += (unsigned)STRLEN(origval) + 1;
4923 			    newval = alloc(newlen);
4924 			    if (newval == NULL)  /* out of mem, don't change */
4925 				break;
4926 			    s = newval;
4927 
4928 			    /*
4929 			     * Copy the string, skip over escaped chars.
4930 			     * For MS-DOS and WIN32 backslashes before normal
4931 			     * file name characters are not removed, and keep
4932 			     * backslash at start, for "\\machine\path", but
4933 			     * do remove it for "\\\\machine\\path".
4934 			     * The reverse is found in ExpandOldSetting().
4935 			     */
4936 			    while (*arg && !VIM_ISWHITE(*arg))
4937 			    {
4938 				if (*arg == '\\' && arg[1] != NUL
4939 #ifdef BACKSLASH_IN_FILENAME
4940 					&& !((flags & P_EXPAND)
4941 						&& vim_isfilec(arg[1])
4942 						&& (arg[1] != '\\'
4943 						    || (s == newval
4944 							&& arg[2] != '\\')))
4945 #endif
4946 								    )
4947 				    ++arg;	/* remove backslash */
4948 #ifdef FEAT_MBYTE
4949 				if (has_mbyte
4950 					&& (i = (*mb_ptr2len)(arg)) > 1)
4951 				{
4952 				    /* copy multibyte char */
4953 				    mch_memmove(s, arg, (size_t)i);
4954 				    arg += i;
4955 				    s += i;
4956 				}
4957 				else
4958 #endif
4959 				    *s++ = *arg++;
4960 			    }
4961 			    *s = NUL;
4962 
4963 			    /*
4964 			     * Expand environment variables and ~.
4965 			     * Don't do it when adding without inserting a
4966 			     * comma.
4967 			     */
4968 			    if (!(adding || prepending || removing)
4969 							 || (flags & P_COMMA))
4970 			    {
4971 				s = option_expand(opt_idx, newval);
4972 				if (s != NULL)
4973 				{
4974 				    vim_free(newval);
4975 				    newlen = (unsigned)STRLEN(s) + 1;
4976 				    if (adding || prepending || removing)
4977 					newlen += (unsigned)STRLEN(origval) + 1;
4978 				    newval = alloc(newlen);
4979 				    if (newval == NULL)
4980 					break;
4981 				    STRCPY(newval, s);
4982 				}
4983 			    }
4984 
4985 			    /* locate newval[] in origval[] when removing it
4986 			     * and when adding to avoid duplicates */
4987 			    i = 0;	/* init for GCC */
4988 			    if (removing || (flags & P_NODUP))
4989 			    {
4990 				i = (int)STRLEN(newval);
4991 				bs = 0;
4992 				for (s = origval; *s; ++s)
4993 				{
4994 				    if ((!(flags & P_COMMA)
4995 						|| s == origval
4996 						|| (s[-1] == ',' && !(bs & 1)))
4997 					    && STRNCMP(s, newval, i) == 0
4998 					    && (!(flags & P_COMMA)
4999 						|| s[i] == ','
5000 						|| s[i] == NUL))
5001 					break;
5002 				    /* Count backslashes.  Only a comma with an
5003 				     * even number of backslashes or a single
5004 				     * backslash preceded by a comma before it
5005 				     * is recognized as a separator */
5006 				    if ((s > origval + 1
5007 						&& s[-1] == '\\'
5008 						&& s[-2] != ',')
5009 					    || (s == origval + 1
5010 						&& s[-1] == '\\'))
5011 
5012 					++bs;
5013 				    else
5014 					bs = 0;
5015 				}
5016 
5017 				/* do not add if already there */
5018 				if ((adding || prepending) && *s)
5019 				{
5020 				    prepending = FALSE;
5021 				    adding = FALSE;
5022 				    STRCPY(newval, origval);
5023 				}
5024 			    }
5025 
5026 			    /* concatenate the two strings; add a ',' if
5027 			     * needed */
5028 			    if (adding || prepending)
5029 			    {
5030 				comma = ((flags & P_COMMA) && *origval != NUL
5031 							   && *newval != NUL);
5032 				if (adding)
5033 				{
5034 				    i = (int)STRLEN(origval);
5035 				    /* strip a trailing comma, would get 2 */
5036 				    if (comma && i > 1
5037 					  && (flags & P_ONECOMMA) == P_ONECOMMA
5038 					  && origval[i - 1] == ','
5039 					  && origval[i - 2] != '\\')
5040 					i--;
5041 				    mch_memmove(newval + i + comma, newval,
5042 							  STRLEN(newval) + 1);
5043 				    mch_memmove(newval, origval, (size_t)i);
5044 				}
5045 				else
5046 				{
5047 				    i = (int)STRLEN(newval);
5048 				    STRMOVE(newval + i + comma, origval);
5049 				}
5050 				if (comma)
5051 				    newval[i] = ',';
5052 			    }
5053 
5054 			    /* Remove newval[] from origval[]. (Note: "i" has
5055 			     * been set above and is used here). */
5056 			    if (removing)
5057 			    {
5058 				STRCPY(newval, origval);
5059 				if (*s)
5060 				{
5061 				    /* may need to remove a comma */
5062 				    if (flags & P_COMMA)
5063 				    {
5064 					if (s == origval)
5065 					{
5066 					    /* include comma after string */
5067 					    if (s[i] == ',')
5068 						++i;
5069 					}
5070 					else
5071 					{
5072 					    /* include comma before string */
5073 					    --s;
5074 					    ++i;
5075 					}
5076 				    }
5077 				    STRMOVE(newval + (s - origval), s + i);
5078 				}
5079 			    }
5080 
5081 			    if (flags & P_FLAGLIST)
5082 			    {
5083 				/* Remove flags that appear twice. */
5084 				for (s = newval; *s;)
5085 				{
5086 				    /* if options have P_FLAGLIST and
5087 				     * P_ONECOMMA such as 'whichwrap' */
5088 				    if (flags & P_ONECOMMA)
5089 				    {
5090 					if (*s != ',' && *(s + 1) == ','
5091 					      && vim_strchr(s + 2, *s) != NULL)
5092 					{
5093 					    /* Remove the duplicated value and
5094 					     * the next comma. */
5095 					    STRMOVE(s, s + 2);
5096 					    continue;
5097 					}
5098 				    }
5099 				    else
5100 				    {
5101 					if ((!(flags & P_COMMA) || *s != ',')
5102 					      && vim_strchr(s + 1, *s) != NULL)
5103 					{
5104 					    STRMOVE(s, s + 1);
5105 					    continue;
5106 					}
5107 				    }
5108 				    ++s;
5109 				}
5110 			    }
5111 
5112 			    if (save_arg != NULL)   /* number for 'whichwrap' */
5113 				arg = save_arg;
5114 			    new_value_alloced = TRUE;
5115 			}
5116 
5117 			/*
5118 			 * Set the new value.
5119 			 */
5120 			*(char_u **)(varp) = newval;
5121 
5122 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5123 			if (!starting
5124 # ifdef FEAT_CRYPT
5125 				&& options[opt_idx].indir != PV_KEY
5126 # endif
5127 					  && origval != NULL && newval != NULL)
5128 			{
5129 			    /* origval may be freed by
5130 			     * did_set_string_option(), make a copy. */
5131 			    saved_origval = vim_strsave(origval);
5132 			    /* newval (and varp) may become invalid if the
5133 			     * buffer is closed by autocommands. */
5134 			    saved_newval = vim_strsave(newval);
5135 			}
5136 #endif
5137 
5138 			/* Handle side effects, and set the global value for
5139 			 * ":set" on local options. Note: when setting 'syntax'
5140 			 * or 'filetype' autocommands may be triggered that can
5141 			 * cause havoc. */
5142 			errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5143 				new_value_alloced, oldval, errbuf, opt_flags);
5144 
5145 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5146 			if (errmsg == NULL)
5147 			    trigger_optionsset_string(opt_idx, opt_flags,
5148 						  saved_origval, saved_newval);
5149 			vim_free(saved_origval);
5150 			vim_free(saved_newval);
5151 #endif
5152 			/* If error detected, print the error message. */
5153 			if (errmsg != NULL)
5154 			    goto skip;
5155 		    }
5156 		    else	    /* key code option */
5157 		    {
5158 			char_u	    *p;
5159 
5160 			if (nextchar == '&')
5161 			{
5162 			    if (add_termcap_entry(key_name, TRUE) == FAIL)
5163 				errmsg = (char_u *)N_("E522: Not found in termcap");
5164 			}
5165 			else
5166 			{
5167 			    ++arg; /* jump to after the '=' or ':' */
5168 			    for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
5169 				if (*p == '\\' && p[1] != NUL)
5170 				    ++p;
5171 			    nextchar = *p;
5172 			    *p = NUL;
5173 			    add_termcode(key_name, arg, FALSE);
5174 			    *p = nextchar;
5175 			}
5176 			if (full_screen)
5177 			    ttest(FALSE);
5178 			redraw_all_later(CLEAR);
5179 		    }
5180 		}
5181 
5182 		if (opt_idx >= 0)
5183 		    did_set_option(opt_idx, opt_flags,
5184 					 !prepending && !adding && !removing);
5185 	    }
5186 
5187 skip:
5188 	    /*
5189 	     * Advance to next argument.
5190 	     * - skip until a blank found, taking care of backslashes
5191 	     * - skip blanks
5192 	     * - skip one "=val" argument (for hidden options ":set gfn =xx")
5193 	     */
5194 	    for (i = 0; i < 2 ; ++i)
5195 	    {
5196 		while (*arg != NUL && !VIM_ISWHITE(*arg))
5197 		    if (*arg++ == '\\' && *arg != NUL)
5198 			++arg;
5199 		arg = skipwhite(arg);
5200 		if (*arg != '=')
5201 		    break;
5202 	    }
5203 	}
5204 
5205 	if (errmsg != NULL)
5206 	{
5207 	    vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
5208 	    i = (int)STRLEN(IObuff) + 2;
5209 	    if (i + (arg - startarg) < IOSIZE)
5210 	    {
5211 		/* append the argument with the error */
5212 		STRCAT(IObuff, ": ");
5213 		mch_memmove(IObuff + i, startarg, (arg - startarg));
5214 		IObuff[i + (arg - startarg)] = NUL;
5215 	    }
5216 	    /* make sure all characters are printable */
5217 	    trans_characters(IObuff, IOSIZE);
5218 
5219 	    ++no_wait_return;	/* wait_return done later */
5220 	    emsg(IObuff);	/* show error highlighted */
5221 	    --no_wait_return;
5222 
5223 	    return FAIL;
5224 	}
5225 
5226 	arg = skipwhite(arg);
5227     }
5228 
5229 theend:
5230     if (silent_mode && did_show)
5231     {
5232 	/* After displaying option values in silent mode. */
5233 	silent_mode = FALSE;
5234 	info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
5235 	msg_putchar('\n');
5236 	cursor_on();		/* msg_start() switches it off */
5237 	out_flush();
5238 	silent_mode = TRUE;
5239 	info_message = FALSE;	/* use mch_msg(), not mch_errmsg() */
5240     }
5241 
5242     return OK;
5243 }
5244 
5245 /*
5246  * Call this when an option has been given a new value through a user command.
5247  * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5248  */
5249     static void
5250 did_set_option(
5251     int	    opt_idx,
5252     int	    opt_flags,	    /* possibly with OPT_MODELINE */
5253     int	    new_value)	    /* value was replaced completely */
5254 {
5255     long_u	*p;
5256 
5257     options[opt_idx].flags |= P_WAS_SET;
5258 
5259     /* When an option is set in the sandbox, from a modeline or in secure mode
5260      * set the P_INSECURE flag.  Otherwise, if a new value is stored reset the
5261      * flag. */
5262     p = insecure_flag(opt_idx, opt_flags);
5263     if (secure
5264 #ifdef HAVE_SANDBOX
5265 	    || sandbox != 0
5266 #endif
5267 	    || (opt_flags & OPT_MODELINE))
5268 	*p = *p | P_INSECURE;
5269     else if (new_value)
5270 	*p = *p & ~P_INSECURE;
5271 }
5272 
5273     static char_u *
5274 illegal_char(char_u *errbuf, int c)
5275 {
5276     if (errbuf == NULL)
5277 	return (char_u *)"";
5278     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
5279 							(char *)transchar(c));
5280     return errbuf;
5281 }
5282 
5283 /*
5284  * Convert a key name or string into a key value.
5285  * Used for 'wildchar' and 'cedit' options.
5286  * When "multi_byte" is TRUE allow for multi-byte characters.
5287  */
5288     int
5289 string_to_key(char_u *arg, int multi_byte)
5290 {
5291     if (*arg == '<')
5292 	return find_key_option(arg + 1);
5293     if (*arg == '^')
5294 	return Ctrl_chr(arg[1]);
5295     if (multi_byte)
5296 	return PTR2CHAR(arg);
5297     return *arg;
5298 }
5299 
5300 #ifdef FEAT_CMDWIN
5301 /*
5302  * Check value of 'cedit' and set cedit_key.
5303  * Returns NULL if value is OK, error message otherwise.
5304  */
5305     static char_u *
5306 check_cedit(void)
5307 {
5308     int n;
5309 
5310     if (*p_cedit == NUL)
5311 	cedit_key = -1;
5312     else
5313     {
5314 	n = string_to_key(p_cedit, FALSE);
5315 	if (vim_isprintc(n))
5316 	    return e_invarg;
5317 	cedit_key = n;
5318     }
5319     return NULL;
5320 }
5321 #endif
5322 
5323 #ifdef FEAT_TITLE
5324 /*
5325  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5326  * maketitle() to create and display it.
5327  * When switching the title or icon off, call mch_restore_title() to get
5328  * the old value back.
5329  */
5330     static void
5331 did_set_title(
5332     int	    icon)	    /* Did set icon instead of title */
5333 {
5334     if (starting != NO_SCREEN
5335 #ifdef FEAT_GUI
5336 	    && !gui.starting
5337 #endif
5338 				)
5339     {
5340 	maketitle();
5341 	if (icon)
5342 	{
5343 	    if (!p_icon)
5344 		mch_restore_title(2);
5345 	}
5346 	else
5347 	{
5348 	    if (!p_title)
5349 		mch_restore_title(1);
5350 	}
5351     }
5352 }
5353 #endif
5354 
5355 /*
5356  * set_options_bin -  called when 'bin' changes value.
5357  */
5358     void
5359 set_options_bin(
5360     int		oldval,
5361     int		newval,
5362     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5363 {
5364     /*
5365      * The option values that are changed when 'bin' changes are
5366      * copied when 'bin is set and restored when 'bin' is reset.
5367      */
5368     if (newval)
5369     {
5370 	if (!oldval)		/* switched on */
5371 	{
5372 	    if (!(opt_flags & OPT_GLOBAL))
5373 	    {
5374 		curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5375 		curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5376 		curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5377 		curbuf->b_p_et_nobin = curbuf->b_p_et;
5378 	    }
5379 	    if (!(opt_flags & OPT_LOCAL))
5380 	    {
5381 		p_tw_nobin = p_tw;
5382 		p_wm_nobin = p_wm;
5383 		p_ml_nobin = p_ml;
5384 		p_et_nobin = p_et;
5385 	    }
5386 	}
5387 
5388 	if (!(opt_flags & OPT_GLOBAL))
5389 	{
5390 	    curbuf->b_p_tw = 0;	/* no automatic line wrap */
5391 	    curbuf->b_p_wm = 0;	/* no automatic line wrap */
5392 	    curbuf->b_p_ml = 0;	/* no modelines */
5393 	    curbuf->b_p_et = 0;	/* no expandtab */
5394 	}
5395 	if (!(opt_flags & OPT_LOCAL))
5396 	{
5397 	    p_tw = 0;
5398 	    p_wm = 0;
5399 	    p_ml = FALSE;
5400 	    p_et = FALSE;
5401 	    p_bin = TRUE;	/* needed when called for the "-b" argument */
5402 	}
5403     }
5404     else if (oldval)		/* switched off */
5405     {
5406 	if (!(opt_flags & OPT_GLOBAL))
5407 	{
5408 	    curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5409 	    curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5410 	    curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5411 	    curbuf->b_p_et = curbuf->b_p_et_nobin;
5412 	}
5413 	if (!(opt_flags & OPT_LOCAL))
5414 	{
5415 	    p_tw = p_tw_nobin;
5416 	    p_wm = p_wm_nobin;
5417 	    p_ml = p_ml_nobin;
5418 	    p_et = p_et_nobin;
5419 	}
5420     }
5421 }
5422 
5423 #ifdef FEAT_VIMINFO
5424 /*
5425  * Find the parameter represented by the given character (eg ', :, ", or /),
5426  * and return its associated value in the 'viminfo' string.
5427  * Only works for number parameters, not for 'r' or 'n'.
5428  * If the parameter is not specified in the string or there is no following
5429  * number, return -1.
5430  */
5431     int
5432 get_viminfo_parameter(int type)
5433 {
5434     char_u  *p;
5435 
5436     p = find_viminfo_parameter(type);
5437     if (p != NULL && VIM_ISDIGIT(*p))
5438 	return atoi((char *)p);
5439     return -1;
5440 }
5441 
5442 /*
5443  * Find the parameter represented by the given character (eg ''', ':', '"', or
5444  * '/') in the 'viminfo' option and return a pointer to the string after it.
5445  * Return NULL if the parameter is not specified in the string.
5446  */
5447     char_u *
5448 find_viminfo_parameter(int type)
5449 {
5450     char_u  *p;
5451 
5452     for (p = p_viminfo; *p; ++p)
5453     {
5454 	if (*p == type)
5455 	    return p + 1;
5456 	if (*p == 'n')		    /* 'n' is always the last one */
5457 	    break;
5458 	p = vim_strchr(p, ',');	    /* skip until next ',' */
5459 	if (p == NULL)		    /* hit the end without finding parameter */
5460 	    break;
5461     }
5462     return NULL;
5463 }
5464 #endif
5465 
5466 /*
5467  * Expand environment variables for some string options.
5468  * These string options cannot be indirect!
5469  * If "val" is NULL expand the current value of the option.
5470  * Return pointer to NameBuff, or NULL when not expanded.
5471  */
5472     static char_u *
5473 option_expand(int opt_idx, char_u *val)
5474 {
5475     /* if option doesn't need expansion nothing to do */
5476     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5477 	return NULL;
5478 
5479     /* If val is longer than MAXPATHL no meaningful expansion can be done,
5480      * expand_env() would truncate the string. */
5481     if (val != NULL && STRLEN(val) > MAXPATHL)
5482 	return NULL;
5483 
5484     if (val == NULL)
5485 	val = *(char_u **)options[opt_idx].var;
5486 
5487     /*
5488      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5489      * Escape spaces when expanding 'tags', they are used to separate file
5490      * names.
5491      * For 'spellsuggest' expand after "file:".
5492      */
5493     expand_env_esc(val, NameBuff, MAXPATHL,
5494 	    (char_u **)options[opt_idx].var == &p_tags, FALSE,
5495 #ifdef FEAT_SPELL
5496 	    (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5497 #endif
5498 				  NULL);
5499     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
5500 	return NULL;
5501 
5502     return NameBuff;
5503 }
5504 
5505 /*
5506  * After setting various option values: recompute variables that depend on
5507  * option values.
5508  */
5509     static void
5510 didset_options(void)
5511 {
5512     /* initialize the table for 'iskeyword' et.al. */
5513     (void)init_chartab();
5514 
5515 #ifdef FEAT_MBYTE
5516     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5517 #endif
5518     (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5519     (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
5520 #ifdef FEAT_SESSION
5521     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5522     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5523 #endif
5524 #ifdef FEAT_FOLDING
5525     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5526 #endif
5527     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5528     (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
5529 #ifdef FEAT_VIRTUALEDIT
5530     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5531 #endif
5532 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5533     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5534 #endif
5535 #ifdef FEAT_SPELL
5536     (void)spell_check_msm();
5537     (void)spell_check_sps();
5538     (void)compile_cap_prog(curwin->w_s);
5539     (void)did_set_spell_option(TRUE);
5540 #endif
5541 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5542     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5543 #endif
5544 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
5545     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5546 #endif
5547 #ifdef FEAT_CMDWIN
5548     /* set cedit_key */
5549     (void)check_cedit();
5550 #endif
5551 #ifdef FEAT_LINEBREAK
5552     briopt_check(curwin);
5553 #endif
5554 #ifdef FEAT_LINEBREAK
5555     /* initialize the table for 'breakat'. */
5556     fill_breakat_flags();
5557 #endif
5558 
5559 }
5560 
5561 /*
5562  * More side effects of setting options.
5563  */
5564     static void
5565 didset_options2(void)
5566 {
5567     /* Initialize the highlight_attr[] table. */
5568     (void)highlight_changed();
5569 
5570     /* Parse default for 'wildmode'  */
5571     check_opt_wim();
5572 
5573     (void)set_chars_option(&p_lcs);
5574     /* Parse default for 'fillchars'. */
5575     (void)set_chars_option(&p_fcs);
5576 
5577 #ifdef FEAT_CLIPBOARD
5578     /* Parse default for 'clipboard' */
5579     (void)check_clipboard_option();
5580 #endif
5581 }
5582 
5583 /*
5584  * Check for string options that are NULL (normally only termcap options).
5585  */
5586     void
5587 check_options(void)
5588 {
5589     int		opt_idx;
5590 
5591     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5592 	if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5593 	    check_string_option((char_u **)get_varp(&(options[opt_idx])));
5594 }
5595 
5596 /*
5597  * Check string options in a buffer for NULL value.
5598  */
5599     void
5600 check_buf_options(buf_T *buf)
5601 {
5602     check_string_option(&buf->b_p_bh);
5603     check_string_option(&buf->b_p_bt);
5604 #ifdef FEAT_MBYTE
5605     check_string_option(&buf->b_p_fenc);
5606 #endif
5607     check_string_option(&buf->b_p_ff);
5608 #ifdef FEAT_FIND_ID
5609     check_string_option(&buf->b_p_def);
5610     check_string_option(&buf->b_p_inc);
5611 # ifdef FEAT_EVAL
5612     check_string_option(&buf->b_p_inex);
5613 # endif
5614 #endif
5615 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5616     check_string_option(&buf->b_p_inde);
5617     check_string_option(&buf->b_p_indk);
5618 #endif
5619 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5620     check_string_option(&buf->b_p_bexpr);
5621 #endif
5622 #if defined(FEAT_CRYPT)
5623     check_string_option(&buf->b_p_cm);
5624 #endif
5625     check_string_option(&buf->b_p_fp);
5626 #if defined(FEAT_EVAL)
5627     check_string_option(&buf->b_p_fex);
5628 #endif
5629 #ifdef FEAT_CRYPT
5630     check_string_option(&buf->b_p_key);
5631 #endif
5632     check_string_option(&buf->b_p_kp);
5633     check_string_option(&buf->b_p_mps);
5634     check_string_option(&buf->b_p_fo);
5635     check_string_option(&buf->b_p_flp);
5636     check_string_option(&buf->b_p_isk);
5637 #ifdef FEAT_COMMENTS
5638     check_string_option(&buf->b_p_com);
5639 #endif
5640 #ifdef FEAT_FOLDING
5641     check_string_option(&buf->b_p_cms);
5642 #endif
5643     check_string_option(&buf->b_p_nf);
5644 #ifdef FEAT_TEXTOBJ
5645     check_string_option(&buf->b_p_qe);
5646 #endif
5647 #ifdef FEAT_SYN_HL
5648     check_string_option(&buf->b_p_syn);
5649     check_string_option(&buf->b_s.b_syn_isk);
5650 #endif
5651 #ifdef FEAT_SPELL
5652     check_string_option(&buf->b_s.b_p_spc);
5653     check_string_option(&buf->b_s.b_p_spf);
5654     check_string_option(&buf->b_s.b_p_spl);
5655 #endif
5656 #ifdef FEAT_SEARCHPATH
5657     check_string_option(&buf->b_p_sua);
5658 #endif
5659 #ifdef FEAT_CINDENT
5660     check_string_option(&buf->b_p_cink);
5661     check_string_option(&buf->b_p_cino);
5662     parse_cino(buf);
5663 #endif
5664 #ifdef FEAT_AUTOCMD
5665     check_string_option(&buf->b_p_ft);
5666 #endif
5667 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5668     check_string_option(&buf->b_p_cinw);
5669 #endif
5670 #ifdef FEAT_INS_EXPAND
5671     check_string_option(&buf->b_p_cpt);
5672 #endif
5673 #ifdef FEAT_COMPL_FUNC
5674     check_string_option(&buf->b_p_cfu);
5675     check_string_option(&buf->b_p_ofu);
5676 #endif
5677 #ifdef FEAT_KEYMAP
5678     check_string_option(&buf->b_p_keymap);
5679 #endif
5680 #ifdef FEAT_QUICKFIX
5681     check_string_option(&buf->b_p_gp);
5682     check_string_option(&buf->b_p_mp);
5683     check_string_option(&buf->b_p_efm);
5684 #endif
5685     check_string_option(&buf->b_p_ep);
5686     check_string_option(&buf->b_p_path);
5687     check_string_option(&buf->b_p_tags);
5688     check_string_option(&buf->b_p_tc);
5689 #ifdef FEAT_INS_EXPAND
5690     check_string_option(&buf->b_p_dict);
5691     check_string_option(&buf->b_p_tsr);
5692 #endif
5693 #ifdef FEAT_LISP
5694     check_string_option(&buf->b_p_lw);
5695 #endif
5696     check_string_option(&buf->b_p_bkc);
5697 #ifdef FEAT_MBYTE
5698     check_string_option(&buf->b_p_menc);
5699 #endif
5700 }
5701 
5702 /*
5703  * Free the string allocated for an option.
5704  * Checks for the string being empty_option. This may happen if we're out of
5705  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5706  * check_options().
5707  * Does NOT check for P_ALLOCED flag!
5708  */
5709     void
5710 free_string_option(char_u *p)
5711 {
5712     if (p != empty_option)
5713 	vim_free(p);
5714 }
5715 
5716     void
5717 clear_string_option(char_u **pp)
5718 {
5719     if (*pp != empty_option)
5720 	vim_free(*pp);
5721     *pp = empty_option;
5722 }
5723 
5724     static void
5725 check_string_option(char_u **pp)
5726 {
5727     if (*pp == NULL)
5728 	*pp = empty_option;
5729 }
5730 
5731 /*
5732  * Mark a terminal option as allocated, found by a pointer into term_strings[].
5733  */
5734     void
5735 set_term_option_alloced(char_u **p)
5736 {
5737     int		opt_idx;
5738 
5739     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5740 	if (options[opt_idx].var == (char_u *)p)
5741 	{
5742 	    options[opt_idx].flags |= P_ALLOCED;
5743 	    return;
5744 	}
5745     return; /* cannot happen: didn't find it! */
5746 }
5747 
5748 #if defined(FEAT_EVAL) || defined(PROTO)
5749 /*
5750  * Return TRUE when option "opt" was set from a modeline or in secure mode.
5751  * Return FALSE when it wasn't.
5752  * Return -1 for an unknown option.
5753  */
5754     int
5755 was_set_insecurely(char_u *opt, int opt_flags)
5756 {
5757     int	    idx = findoption(opt);
5758     long_u  *flagp;
5759 
5760     if (idx >= 0)
5761     {
5762 	flagp = insecure_flag(idx, opt_flags);
5763 	return (*flagp & P_INSECURE) != 0;
5764     }
5765     internal_error("was_set_insecurely()");
5766     return -1;
5767 }
5768 
5769 /*
5770  * Get a pointer to the flags used for the P_INSECURE flag of option
5771  * "opt_idx".  For some local options a local flags field is used.
5772  */
5773     static long_u *
5774 insecure_flag(int opt_idx, int opt_flags)
5775 {
5776     if (opt_flags & OPT_LOCAL)
5777 	switch ((int)options[opt_idx].indir)
5778 	{
5779 #ifdef FEAT_STL_OPT
5780 	    case PV_STL:	return &curwin->w_p_stl_flags;
5781 #endif
5782 #ifdef FEAT_EVAL
5783 # ifdef FEAT_FOLDING
5784 	    case PV_FDE:	return &curwin->w_p_fde_flags;
5785 	    case PV_FDT:	return &curwin->w_p_fdt_flags;
5786 # endif
5787 # ifdef FEAT_BEVAL
5788 	    case PV_BEXPR:	return &curbuf->b_p_bexpr_flags;
5789 # endif
5790 # if defined(FEAT_CINDENT)
5791 	    case PV_INDE:	return &curbuf->b_p_inde_flags;
5792 # endif
5793 	    case PV_FEX:	return &curbuf->b_p_fex_flags;
5794 # ifdef FEAT_FIND_ID
5795 	    case PV_INEX:	return &curbuf->b_p_inex_flags;
5796 # endif
5797 #endif
5798 	}
5799 
5800     /* Nothing special, return global flags field. */
5801     return &options[opt_idx].flags;
5802 }
5803 #endif
5804 
5805 #ifdef FEAT_TITLE
5806 static void redraw_titles(void);
5807 
5808 /*
5809  * Redraw the window title and/or tab page text later.
5810  */
5811 static void redraw_titles(void)
5812 {
5813     need_maketitle = TRUE;
5814     redraw_tabline = TRUE;
5815 }
5816 #endif
5817 
5818 /*
5819  * Set a string option to a new value (without checking the effect).
5820  * The string is copied into allocated memory.
5821  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5822  * When "set_sid" is zero set the scriptID to current_SID.  When "set_sid" is
5823  * SID_NONE don't set the scriptID.  Otherwise set the scriptID to "set_sid".
5824  */
5825     void
5826 set_string_option_direct(
5827     char_u	*name,
5828     int		opt_idx,
5829     char_u	*val,
5830     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5831     int		set_sid UNUSED)
5832 {
5833     char_u	*s;
5834     char_u	**varp;
5835     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5836     int		idx = opt_idx;
5837 
5838     if (idx == -1)		/* use name */
5839     {
5840 	idx = findoption(name);
5841 	if (idx < 0)	/* not found (should not happen) */
5842 	{
5843 	    EMSG2(_(e_intern2), "set_string_option_direct()");
5844 	    IEMSG2(_("For option %s"), name);
5845 	    return;
5846 	}
5847     }
5848 
5849     if (options[idx].var == NULL)	/* can't set hidden option */
5850 	return;
5851 
5852     s = vim_strsave(val);
5853     if (s != NULL)
5854     {
5855 	varp = (char_u **)get_varp_scope(&(options[idx]),
5856 					       both ? OPT_LOCAL : opt_flags);
5857 	if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5858 	    free_string_option(*varp);
5859 	*varp = s;
5860 
5861 	/* For buffer/window local option may also set the global value. */
5862 	if (both)
5863 	    set_string_option_global(idx, varp);
5864 
5865 	options[idx].flags |= P_ALLOCED;
5866 
5867 	/* When setting both values of a global option with a local value,
5868 	 * make the local value empty, so that the global value is used. */
5869 	if (((int)options[idx].indir & PV_BOTH) && both)
5870 	{
5871 	    free_string_option(*varp);
5872 	    *varp = empty_option;
5873 	}
5874 # ifdef FEAT_EVAL
5875 	if (set_sid != SID_NONE)
5876 	    set_option_scriptID_idx(idx, opt_flags,
5877 					set_sid == 0 ? current_SID : set_sid);
5878 # endif
5879     }
5880 }
5881 
5882 /*
5883  * Set global value for string option when it's a local option.
5884  */
5885     static void
5886 set_string_option_global(
5887     int		opt_idx,	/* option index */
5888     char_u	**varp)		/* pointer to option variable */
5889 {
5890     char_u	**p, *s;
5891 
5892     /* the global value is always allocated */
5893     if (options[opt_idx].var == VAR_WIN)
5894 	p = (char_u **)GLOBAL_WO(varp);
5895     else
5896 	p = (char_u **)options[opt_idx].var;
5897     if (options[opt_idx].indir != PV_NONE
5898 	    && p != varp
5899 	    && (s = vim_strsave(*varp)) != NULL)
5900     {
5901 	free_string_option(*p);
5902 	*p = s;
5903     }
5904 }
5905 
5906 /*
5907  * Set a string option to a new value, and handle the effects.
5908  *
5909  * Returns NULL on success or error message on error.
5910  */
5911     static char_u *
5912 set_string_option(
5913     int		opt_idx,
5914     char_u	*value,
5915     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5916 {
5917     char_u	*s;
5918     char_u	**varp;
5919     char_u	*oldval;
5920 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5921     char_u	*saved_oldval = NULL;
5922     char_u	*saved_newval = NULL;
5923 #endif
5924     char_u	*r = NULL;
5925 
5926     if (options[opt_idx].var == NULL)	/* don't set hidden option */
5927 	return NULL;
5928 
5929     s = vim_strsave(value);
5930     if (s != NULL)
5931     {
5932 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5933 		(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5934 		    ? (((int)options[opt_idx].indir & PV_BOTH)
5935 			? OPT_GLOBAL : OPT_LOCAL)
5936 		    : opt_flags);
5937 	oldval = *varp;
5938 	*varp = s;
5939 
5940 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5941 	if (!starting
5942 # ifdef FEAT_CRYPT
5943 		&& options[opt_idx].indir != PV_KEY
5944 # endif
5945 		)
5946 	{
5947 	    saved_oldval = vim_strsave(oldval);
5948 	    saved_newval = vim_strsave(s);
5949 	}
5950 #endif
5951 	if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5952 							   opt_flags)) == NULL)
5953 	    did_set_option(opt_idx, opt_flags, TRUE);
5954 
5955 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5956 	/* call autocommand after handling side effects */
5957 	if (r == NULL)
5958 	    trigger_optionsset_string(opt_idx, opt_flags,
5959 						   saved_oldval, saved_newval);
5960 	vim_free(saved_oldval);
5961 	vim_free(saved_newval);
5962 #endif
5963     }
5964     return r;
5965 }
5966 
5967 #if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
5968 /*
5969  * Return TRUE if "val" is a valid 'filetype' name.
5970  * Also used for 'syntax' and 'keymap'.
5971  */
5972     static int
5973 valid_filetype(char_u *val)
5974 {
5975     char_u *s;
5976 
5977     for (s = val; *s != NUL; ++s)
5978 	if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5979 	    return FALSE;
5980     return TRUE;
5981 }
5982 #endif
5983 
5984 /*
5985  * Handle string options that need some action to perform when changed.
5986  * Returns NULL for success, or an error message for an error.
5987  */
5988     static char_u *
5989 did_set_string_option(
5990     int		opt_idx,		/* index in options[] table */
5991     char_u	**varp,			/* pointer to the option variable */
5992     int		new_value_alloced,	/* new value was allocated */
5993     char_u	*oldval,		/* previous value of the option */
5994     char_u	*errbuf,		/* buffer for errors, or NULL */
5995     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
5996 {
5997     char_u	*errmsg = NULL;
5998     char_u	*s, *p;
5999     int		did_chartab = FALSE;
6000     char_u	**gvarp;
6001     long_u	free_oldval = (options[opt_idx].flags & P_ALLOCED);
6002 #ifdef FEAT_GUI
6003     /* set when changing an option that only requires a redraw in the GUI */
6004     int		redraw_gui_only = FALSE;
6005 #endif
6006 #ifdef FEAT_AUTOCMD
6007     int		ft_changed = FALSE;
6008 #endif
6009 
6010     /* Get the global option to compare with, otherwise we would have to check
6011      * two values for all local options. */
6012     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6013 
6014     /* Disallow changing some options from secure mode */
6015     if ((secure
6016 #ifdef HAVE_SANDBOX
6017 		|| sandbox != 0
6018 #endif
6019 		) && (options[opt_idx].flags & P_SECURE))
6020     {
6021 	errmsg = e_secure;
6022     }
6023 
6024     /* Check for a "normal" directory or file name in some options.  Disallow a
6025      * path separator (slash and/or backslash), wildcards and characters that
6026      * are often illegal in a file name. Be more permissive if "secure" is off.
6027      */
6028     else if (((options[opt_idx].flags & P_NFNAME)
6029 		    && vim_strpbrk(*varp, (char_u *)(secure
6030 			    ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
6031 	  || ((options[opt_idx].flags & P_NDNAME)
6032 		    && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
6033     {
6034 	errmsg = e_invarg;
6035     }
6036 
6037     /* 'term' */
6038     else if (varp == &T_NAME)
6039     {
6040 	if (T_NAME[0] == NUL)
6041 	    errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6042 #ifdef FEAT_GUI
6043 	if (gui.in_use)
6044 	    errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6045 	else if (term_is_gui(T_NAME))
6046 	    errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6047 #endif
6048 	else if (set_termname(T_NAME) == FAIL)
6049 	    errmsg = (char_u *)N_("E522: Not found in termcap");
6050 	else
6051 	{
6052 	    /* Screen colors may have changed. */
6053 	    redraw_later_clear();
6054 
6055 	    /* Both 'term' and 'ttytype' point to T_NAME, only set the
6056 	     * P_ALLOCED flag on 'term'. */
6057 	    opt_idx = findoption((char_u *)"term");
6058 	    free_oldval = (options[opt_idx].flags & P_ALLOCED);
6059 	}
6060     }
6061 
6062     /* 'backupcopy' */
6063     else if (gvarp == &p_bkc)
6064     {
6065 	char_u		*bkc = p_bkc;
6066 	unsigned int	*flags = &bkc_flags;
6067 
6068 	if (opt_flags & OPT_LOCAL)
6069 	{
6070 	    bkc = curbuf->b_p_bkc;
6071 	    flags = &curbuf->b_bkc_flags;
6072 	}
6073 
6074 	if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6075 	    /* make the local value empty: use the global value */
6076 	    *flags = 0;
6077 	else
6078 	{
6079 	    if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6080 		errmsg = e_invarg;
6081 	    if ((((int)*flags & BKC_AUTO) != 0)
6082 		    + (((int)*flags & BKC_YES) != 0)
6083 		    + (((int)*flags & BKC_NO) != 0) != 1)
6084 	    {
6085 		/* Must have exactly one of "auto", "yes"  and "no". */
6086 		(void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6087 		errmsg = e_invarg;
6088 	    }
6089 	}
6090     }
6091 
6092     /* 'backupext' and 'patchmode' */
6093     else if (varp == &p_bex || varp == &p_pm)
6094     {
6095 	if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6096 		     *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6097 	    errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6098     }
6099 #ifdef FEAT_LINEBREAK
6100     /* 'breakindentopt' */
6101     else if (varp == &curwin->w_p_briopt)
6102     {
6103 	if (briopt_check(curwin) == FAIL)
6104 	    errmsg = e_invarg;
6105     }
6106 #endif
6107 
6108     /*
6109      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
6110      * If the new option is invalid, use old value.  'lisp' option: refill
6111      * g_chartab[] for '-' char
6112      */
6113     else if (  varp == &p_isi
6114 	    || varp == &(curbuf->b_p_isk)
6115 	    || varp == &p_isp
6116 	    || varp == &p_isf)
6117     {
6118 	if (init_chartab() == FAIL)
6119 	{
6120 	    did_chartab = TRUE;	    /* need to restore it below */
6121 	    errmsg = e_invarg;	    /* error in value */
6122 	}
6123     }
6124 
6125     /* 'helpfile' */
6126     else if (varp == &p_hf)
6127     {
6128 	/* May compute new values for $VIM and $VIMRUNTIME */
6129 	if (didset_vim)
6130 	{
6131 	    vim_setenv((char_u *)"VIM", (char_u *)"");
6132 	    didset_vim = FALSE;
6133 	}
6134 	if (didset_vimruntime)
6135 	{
6136 	    vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6137 	    didset_vimruntime = FALSE;
6138 	}
6139     }
6140 
6141 #ifdef FEAT_SYN_HL
6142     /* 'colorcolumn' */
6143     else if (varp == &curwin->w_p_cc)
6144 	errmsg = check_colorcolumn(curwin);
6145 #endif
6146 
6147 #ifdef FEAT_MULTI_LANG
6148     /* 'helplang' */
6149     else if (varp == &p_hlg)
6150     {
6151 	/* Check for "", "ab", "ab,cd", etc. */
6152 	for (s = p_hlg; *s != NUL; s += 3)
6153 	{
6154 	    if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6155 	    {
6156 		errmsg = e_invarg;
6157 		break;
6158 	    }
6159 	    if (s[2] == NUL)
6160 		break;
6161 	}
6162     }
6163 #endif
6164 
6165     /* 'highlight' */
6166     else if (varp == &p_hl)
6167     {
6168 	if (highlight_changed() == FAIL)
6169 	    errmsg = e_invarg;	/* invalid flags */
6170     }
6171 
6172     /* 'nrformats' */
6173     else if (gvarp == &p_nf)
6174     {
6175 	if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6176 	    errmsg = e_invarg;
6177     }
6178 
6179 #ifdef FEAT_SESSION
6180     /* 'sessionoptions' */
6181     else if (varp == &p_ssop)
6182     {
6183 	if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6184 	    errmsg = e_invarg;
6185 	if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6186 	{
6187 	    /* Don't allow both "sesdir" and "curdir". */
6188 	    (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6189 	    errmsg = e_invarg;
6190 	}
6191     }
6192     /* 'viewoptions' */
6193     else if (varp == &p_vop)
6194     {
6195 	if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6196 	    errmsg = e_invarg;
6197     }
6198 #endif
6199 
6200     /* 'scrollopt' */
6201 #ifdef FEAT_SCROLLBIND
6202     else if (varp == &p_sbo)
6203     {
6204 	if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6205 	    errmsg = e_invarg;
6206     }
6207 #endif
6208 
6209     /* 'ambiwidth' */
6210 #ifdef FEAT_MBYTE
6211     else if (varp == &p_ambw || varp == &p_emoji)
6212     {
6213 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6214 	    errmsg = e_invarg;
6215 	else if (set_chars_option(&p_lcs) != NULL)
6216 	    errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6217 	else if (set_chars_option(&p_fcs) != NULL)
6218 	    errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6219     }
6220 #endif
6221 
6222     /* 'background' */
6223     else if (varp == &p_bg)
6224     {
6225 	if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6226 	{
6227 #ifdef FEAT_EVAL
6228 	    int dark = (*p_bg == 'd');
6229 #endif
6230 
6231 	    init_highlight(FALSE, FALSE);
6232 
6233 #ifdef FEAT_EVAL
6234 	    if (dark != (*p_bg == 'd')
6235 			  && get_var_value((char_u *)"g:colors_name") != NULL)
6236 	    {
6237 		/* The color scheme must have set 'background' back to another
6238 		 * value, that's not what we want here.  Disable the color
6239 		 * scheme and set the colors again. */
6240 		do_unlet((char_u *)"g:colors_name", TRUE);
6241 		free_string_option(p_bg);
6242 		p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6243 		check_string_option(&p_bg);
6244 		init_highlight(FALSE, FALSE);
6245 	    }
6246 #endif
6247 	}
6248 	else
6249 	    errmsg = e_invarg;
6250     }
6251 
6252     /* 'wildmode' */
6253     else if (varp == &p_wim)
6254     {
6255 	if (check_opt_wim() == FAIL)
6256 	    errmsg = e_invarg;
6257     }
6258 
6259 #ifdef FEAT_CMDL_COMPL
6260     /* 'wildoptions' */
6261     else if (varp == &p_wop)
6262     {
6263 	if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6264 	    errmsg = e_invarg;
6265     }
6266 #endif
6267 
6268 #ifdef FEAT_WAK
6269     /* 'winaltkeys' */
6270     else if (varp == &p_wak)
6271     {
6272 	if (*p_wak == NUL
6273 		|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6274 	    errmsg = e_invarg;
6275 # ifdef FEAT_MENU
6276 #  ifdef FEAT_GUI_MOTIF
6277 	else if (gui.in_use)
6278 	    gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6279 #  else
6280 #   ifdef FEAT_GUI_GTK
6281 	else if (gui.in_use)
6282 	    gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6283 #   endif
6284 #  endif
6285 # endif
6286     }
6287 #endif
6288 
6289 #ifdef FEAT_AUTOCMD
6290     /* 'eventignore' */
6291     else if (varp == &p_ei)
6292     {
6293 	if (check_ei() == FAIL)
6294 	    errmsg = e_invarg;
6295     }
6296 #endif
6297 
6298 #ifdef FEAT_MBYTE
6299     /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6300     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6301 							   || gvarp == &p_menc)
6302     {
6303 	if (gvarp == &p_fenc)
6304 	{
6305 	    if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
6306 		errmsg = e_modifiable;
6307 	    else if (vim_strchr(*varp, ',') != NULL)
6308 		/* No comma allowed in 'fileencoding'; catches confusing it
6309 		 * with 'fileencodings'. */
6310 		errmsg = e_invarg;
6311 	    else
6312 	    {
6313 # ifdef FEAT_TITLE
6314 		/* May show a "+" in the title now. */
6315 		redraw_titles();
6316 # endif
6317 		/* Add 'fileencoding' to the swap file. */
6318 		ml_setflags(curbuf);
6319 	    }
6320 	}
6321 	if (errmsg == NULL)
6322 	{
6323 	    /* canonize the value, so that STRCMP() can be used on it */
6324 	    p = enc_canonize(*varp);
6325 	    if (p != NULL)
6326 	    {
6327 		vim_free(*varp);
6328 		*varp = p;
6329 	    }
6330 	    if (varp == &p_enc)
6331 	    {
6332 		errmsg = mb_init();
6333 # ifdef FEAT_TITLE
6334 		redraw_titles();
6335 # endif
6336 	    }
6337 	}
6338 
6339 # if defined(FEAT_GUI_GTK)
6340 	if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6341 	{
6342 	    /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6343 	    if (STRCMP(p_tenc, "utf-8") != 0)
6344 		errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6345 	}
6346 # endif
6347 
6348 	if (errmsg == NULL)
6349 	{
6350 # ifdef FEAT_KEYMAP
6351 	    /* When 'keymap' is used and 'encoding' changes, reload the keymap
6352 	     * (with another encoding). */
6353 	    if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6354 		(void)keymap_init();
6355 # endif
6356 
6357 	    /* When 'termencoding' is not empty and 'encoding' changes or when
6358 	     * 'termencoding' changes, need to setup for keyboard input and
6359 	     * display output conversion. */
6360 	    if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6361 	    {
6362 		convert_setup(&input_conv, p_tenc, p_enc);
6363 		convert_setup(&output_conv, p_enc, p_tenc);
6364 	    }
6365 
6366 # if defined(WIN3264) && defined(FEAT_MBYTE)
6367 	    /* $HOME may have characters in active code page. */
6368 	    if (varp == &p_enc)
6369 		init_homedir();
6370 # endif
6371 	}
6372     }
6373 #endif
6374 
6375 #if defined(FEAT_POSTSCRIPT)
6376     else if (varp == &p_penc)
6377     {
6378 	/* Canonize printencoding if VIM standard one */
6379 	p = enc_canonize(p_penc);
6380 	if (p != NULL)
6381 	{
6382 	    vim_free(p_penc);
6383 	    p_penc = p;
6384 	}
6385 	else
6386 	{
6387 	    /* Ensure lower case and '-' for '_' */
6388 	    for (s = p_penc; *s != NUL; s++)
6389 	    {
6390 		if (*s == '_')
6391 		    *s = '-';
6392 		else
6393 		    *s = TOLOWER_ASC(*s);
6394 	    }
6395 	}
6396     }
6397 #endif
6398 
6399 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
6400     else if (varp == &p_imak)
6401     {
6402 	if (!im_xim_isvalid_imactivate())
6403 	    errmsg = e_invarg;
6404     }
6405 #endif
6406 
6407 #ifdef FEAT_KEYMAP
6408     else if (varp == &curbuf->b_p_keymap)
6409     {
6410 	if (!valid_filetype(*varp))
6411 	    errmsg = e_invarg;
6412 	else
6413 	    /* load or unload key mapping tables */
6414 	    errmsg = keymap_init();
6415 
6416 	if (errmsg == NULL)
6417 	{
6418 	    if (*curbuf->b_p_keymap != NUL)
6419 	    {
6420 		/* Installed a new keymap, switch on using it. */
6421 		curbuf->b_p_iminsert = B_IMODE_LMAP;
6422 		if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6423 		    curbuf->b_p_imsearch = B_IMODE_LMAP;
6424 	    }
6425 	    else
6426 	    {
6427 		/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6428 		if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6429 		    curbuf->b_p_iminsert = B_IMODE_NONE;
6430 		if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6431 		    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6432 	    }
6433 	    if ((opt_flags & OPT_LOCAL) == 0)
6434 	    {
6435 		set_iminsert_global();
6436 		set_imsearch_global();
6437 	    }
6438 	    status_redraw_curbuf();
6439 	}
6440     }
6441 #endif
6442 
6443     /* 'fileformat' */
6444     else if (gvarp == &p_ff)
6445     {
6446 	if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6447 	    errmsg = e_modifiable;
6448 	else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6449 	    errmsg = e_invarg;
6450 	else
6451 	{
6452 	    /* may also change 'textmode' */
6453 	    if (get_fileformat(curbuf) == EOL_DOS)
6454 		curbuf->b_p_tx = TRUE;
6455 	    else
6456 		curbuf->b_p_tx = FALSE;
6457 #ifdef FEAT_TITLE
6458 	    redraw_titles();
6459 #endif
6460 	    /* update flag in swap file */
6461 	    ml_setflags(curbuf);
6462 	    /* Redraw needed when switching to/from "mac": a CR in the text
6463 	     * will be displayed differently. */
6464 	    if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6465 		redraw_curbuf_later(NOT_VALID);
6466 	}
6467     }
6468 
6469     /* 'fileformats' */
6470     else if (varp == &p_ffs)
6471     {
6472 	if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6473 	    errmsg = e_invarg;
6474 	else
6475 	{
6476 	    /* also change 'textauto' */
6477 	    if (*p_ffs == NUL)
6478 		p_ta = FALSE;
6479 	    else
6480 		p_ta = TRUE;
6481 	}
6482     }
6483 
6484 #if defined(FEAT_CRYPT)
6485     /* 'cryptkey' */
6486     else if (gvarp == &p_key)
6487     {
6488 # if defined(FEAT_CMDHIST)
6489 	/* Make sure the ":set" command doesn't show the new value in the
6490 	 * history. */
6491 	remove_key_from_history();
6492 # endif
6493 	if (STRCMP(curbuf->b_p_key, oldval) != 0)
6494 	    /* Need to update the swapfile. */
6495 	    ml_set_crypt_key(curbuf, oldval,
6496 			      *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
6497     }
6498 
6499     else if (gvarp == &p_cm)
6500     {
6501 	if (opt_flags & OPT_LOCAL)
6502 	    p = curbuf->b_p_cm;
6503 	else
6504 	    p = p_cm;
6505 	if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6506 	    errmsg = e_invarg;
6507 	else if (crypt_self_test() == FAIL)
6508 	    errmsg = e_invarg;
6509 	else
6510 	{
6511 	    /* When setting the global value to empty, make it "zip". */
6512 	    if (*p_cm == NUL)
6513 	    {
6514 		if (new_value_alloced)
6515 		    free_string_option(p_cm);
6516 		p_cm = vim_strsave((char_u *)"zip");
6517 		new_value_alloced = TRUE;
6518 	    }
6519 	    /* When using ":set cm=name" the local value is going to be empty.
6520 	     * Do that here, otherwise the crypt functions will still use the
6521 	     * local value. */
6522 	    if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6523 	    {
6524 		free_string_option(curbuf->b_p_cm);
6525 		curbuf->b_p_cm = empty_option;
6526 	    }
6527 
6528 	    /* Need to update the swapfile when the effective method changed.
6529 	     * Set "s" to the effective old value, "p" to the effective new
6530 	     * method and compare. */
6531 	    if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6532 		s = p_cm;  /* was previously using the global value */
6533 	    else
6534 		s = oldval;
6535 	    if (*curbuf->b_p_cm == NUL)
6536 		p = p_cm;  /* is now using the global value */
6537 	    else
6538 		p = curbuf->b_p_cm;
6539 	    if (STRCMP(s, p) != 0)
6540 		ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
6541 
6542 	    /* If the global value changes need to update the swapfile for all
6543 	     * buffers using that value. */
6544 	    if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6545 	    {
6546 		buf_T	*buf;
6547 
6548 		FOR_ALL_BUFFERS(buf)
6549 		    if (buf != curbuf && *buf->b_p_cm == NUL)
6550 			ml_set_crypt_key(buf, buf->b_p_key, oldval);
6551 	    }
6552 	}
6553     }
6554 #endif
6555 
6556     /* 'matchpairs' */
6557     else if (gvarp == &p_mps)
6558     {
6559 #ifdef FEAT_MBYTE
6560 	if (has_mbyte)
6561 	{
6562 	    for (p = *varp; *p != NUL; ++p)
6563 	    {
6564 		int x2 = -1;
6565 		int x3 = -1;
6566 
6567 		if (*p != NUL)
6568 		    p += mb_ptr2len(p);
6569 		if (*p != NUL)
6570 		    x2 = *p++;
6571 		if (*p != NUL)
6572 		{
6573 		    x3 = mb_ptr2char(p);
6574 		    p += mb_ptr2len(p);
6575 		}
6576 		if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
6577 		{
6578 		    errmsg = e_invarg;
6579 		    break;
6580 		}
6581 		if (*p == NUL)
6582 		    break;
6583 	    }
6584 	}
6585 	else
6586 #endif
6587 	{
6588 	    /* Check for "x:y,x:y" */
6589 	    for (p = *varp; *p != NUL; p += 4)
6590 	    {
6591 		if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6592 		{
6593 		    errmsg = e_invarg;
6594 		    break;
6595 		}
6596 		if (p[3] == NUL)
6597 		    break;
6598 	    }
6599 	}
6600     }
6601 
6602 #ifdef FEAT_COMMENTS
6603     /* 'comments' */
6604     else if (gvarp == &p_com)
6605     {
6606 	for (s = *varp; *s; )
6607 	{
6608 	    while (*s && *s != ':')
6609 	    {
6610 		if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6611 					     && !VIM_ISDIGIT(*s) && *s != '-')
6612 		{
6613 		    errmsg = illegal_char(errbuf, *s);
6614 		    break;
6615 		}
6616 		++s;
6617 	    }
6618 	    if (*s++ == NUL)
6619 		errmsg = (char_u *)N_("E524: Missing colon");
6620 	    else if (*s == ',' || *s == NUL)
6621 		errmsg = (char_u *)N_("E525: Zero length string");
6622 	    if (errmsg != NULL)
6623 		break;
6624 	    while (*s && *s != ',')
6625 	    {
6626 		if (*s == '\\' && s[1] != NUL)
6627 		    ++s;
6628 		++s;
6629 	    }
6630 	    s = skip_to_option_part(s);
6631 	}
6632     }
6633 #endif
6634 
6635     /* 'listchars' */
6636     else if (varp == &p_lcs)
6637     {
6638 	errmsg = set_chars_option(varp);
6639     }
6640 
6641     /* 'fillchars' */
6642     else if (varp == &p_fcs)
6643     {
6644 	errmsg = set_chars_option(varp);
6645     }
6646 
6647 #ifdef FEAT_CMDWIN
6648     /* 'cedit' */
6649     else if (varp == &p_cedit)
6650     {
6651 	errmsg = check_cedit();
6652     }
6653 #endif
6654 
6655     /* 'verbosefile' */
6656     else if (varp == &p_vfile)
6657     {
6658 	verbose_stop();
6659 	if (*p_vfile != NUL && verbose_open() == FAIL)
6660 	    errmsg = e_invarg;
6661     }
6662 
6663 #ifdef FEAT_VIMINFO
6664     /* 'viminfo' */
6665     else if (varp == &p_viminfo)
6666     {
6667 	for (s = p_viminfo; *s;)
6668 	{
6669 	    /* Check it's a valid character */
6670 	    if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6671 	    {
6672 		errmsg = illegal_char(errbuf, *s);
6673 		break;
6674 	    }
6675 	    if (*s == 'n')	/* name is always last one */
6676 	    {
6677 		break;
6678 	    }
6679 	    else if (*s == 'r') /* skip until next ',' */
6680 	    {
6681 		while (*++s && *s != ',')
6682 		    ;
6683 	    }
6684 	    else if (*s == '%')
6685 	    {
6686 		/* optional number */
6687 		while (vim_isdigit(*++s))
6688 		    ;
6689 	    }
6690 	    else if (*s == '!' || *s == 'h' || *s == 'c')
6691 		++s;		/* no extra chars */
6692 	    else		/* must have a number */
6693 	    {
6694 		while (vim_isdigit(*++s))
6695 		    ;
6696 
6697 		if (!VIM_ISDIGIT(*(s - 1)))
6698 		{
6699 		    if (errbuf != NULL)
6700 		    {
6701 			sprintf((char *)errbuf,
6702 					 _("E526: Missing number after <%s>"),
6703 						    transchar_byte(*(s - 1)));
6704 			errmsg = errbuf;
6705 		    }
6706 		    else
6707 			errmsg = (char_u *)"";
6708 		    break;
6709 		}
6710 	    }
6711 	    if (*s == ',')
6712 		++s;
6713 	    else if (*s)
6714 	    {
6715 		if (errbuf != NULL)
6716 		    errmsg = (char_u *)N_("E527: Missing comma");
6717 		else
6718 		    errmsg = (char_u *)"";
6719 		break;
6720 	    }
6721 	}
6722 	if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6723 	    errmsg = (char_u *)N_("E528: Must specify a ' value");
6724     }
6725 #endif /* FEAT_VIMINFO */
6726 
6727     /* terminal options */
6728     else if (istermoption(&options[opt_idx]) && full_screen)
6729     {
6730 	/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6731 	if (varp == &T_CCO)
6732 	{
6733 	    int colors = atoi((char *)T_CCO);
6734 
6735 	    /* Only reinitialize colors if t_Co value has really changed to
6736 	     * avoid expensive reload of colorscheme if t_Co is set to the
6737 	     * same value multiple times. */
6738 	    if (colors != t_colors)
6739 	    {
6740 		t_colors = colors;
6741 		if (t_colors <= 1)
6742 		{
6743 		    if (new_value_alloced)
6744 			vim_free(T_CCO);
6745 		    T_CCO = empty_option;
6746 		}
6747 		/* We now have a different color setup, initialize it again. */
6748 		init_highlight(TRUE, FALSE);
6749 	    }
6750 	}
6751 	ttest(FALSE);
6752 	if (varp == &T_ME)
6753 	{
6754 	    out_str(T_ME);
6755 	    redraw_later(CLEAR);
6756 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
6757 	    /* Since t_me has been set, this probably means that the user
6758 	     * wants to use this as default colors.  Need to reset default
6759 	     * background/foreground colors. */
6760 	    mch_set_normal_colors();
6761 #endif
6762 	}
6763 	if (varp == &T_BE && termcap_active)
6764 	{
6765 	    if (*T_BE == NUL)
6766 		/* When clearing t_BE we assume the user no longer wants
6767 		 * bracketed paste, thus disable it by writing t_BD. */
6768 		out_str(T_BD);
6769 	    else
6770 		out_str(T_BE);
6771 	}
6772     }
6773 
6774 #ifdef FEAT_LINEBREAK
6775     /* 'showbreak' */
6776     else if (varp == &p_sbr)
6777     {
6778 	for (s = p_sbr; *s; )
6779 	{
6780 	    if (ptr2cells(s) != 1)
6781 		errmsg = (char_u *)N_("E595: contains unprintable or wide character");
6782 	    MB_PTR_ADV(s);
6783 	}
6784     }
6785 #endif
6786 
6787 #ifdef FEAT_GUI
6788     /* 'guifont' */
6789     else if (varp == &p_guifont)
6790     {
6791 	if (gui.in_use)
6792 	{
6793 	    p = p_guifont;
6794 # if defined(FEAT_GUI_GTK)
6795 	    /*
6796 	     * Put up a font dialog and let the user select a new value.
6797 	     * If this is cancelled go back to the old value but don't
6798 	     * give an error message.
6799 	     */
6800 	    if (STRCMP(p, "*") == 0)
6801 	    {
6802 		p = gui_mch_font_dialog(oldval);
6803 
6804 		if (new_value_alloced)
6805 		    free_string_option(p_guifont);
6806 
6807 		p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6808 		new_value_alloced = TRUE;
6809 	    }
6810 # endif
6811 	    if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6812 	    {
6813 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6814 		if (STRCMP(p_guifont, "*") == 0)
6815 		{
6816 		    /* Dialog was cancelled: Keep the old value without giving
6817 		     * an error message. */
6818 		    if (new_value_alloced)
6819 			free_string_option(p_guifont);
6820 		    p_guifont = vim_strsave(oldval);
6821 		    new_value_alloced = TRUE;
6822 		}
6823 		else
6824 # endif
6825 		    errmsg = (char_u *)N_("E596: Invalid font(s)");
6826 	    }
6827 	}
6828 	redraw_gui_only = TRUE;
6829     }
6830 # ifdef FEAT_XFONTSET
6831     else if (varp == &p_guifontset)
6832     {
6833 	if (STRCMP(p_guifontset, "*") == 0)
6834 	    errmsg = (char_u *)N_("E597: can't select fontset");
6835 	else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6836 	    errmsg = (char_u *)N_("E598: Invalid fontset");
6837 	redraw_gui_only = TRUE;
6838     }
6839 # endif
6840 # ifdef FEAT_MBYTE
6841     else if (varp == &p_guifontwide)
6842     {
6843 	if (STRCMP(p_guifontwide, "*") == 0)
6844 	    errmsg = (char_u *)N_("E533: can't select wide font");
6845 	else if (gui_get_wide_font() == FAIL)
6846 	    errmsg = (char_u *)N_("E534: Invalid wide font");
6847 	redraw_gui_only = TRUE;
6848     }
6849 # endif
6850 #endif
6851 
6852 #ifdef CURSOR_SHAPE
6853     /* 'guicursor' */
6854     else if (varp == &p_guicursor)
6855 	errmsg = parse_shape_opt(SHAPE_CURSOR);
6856 #endif
6857 
6858 #ifdef FEAT_MOUSESHAPE
6859     /* 'mouseshape' */
6860     else if (varp == &p_mouseshape)
6861     {
6862 	errmsg = parse_shape_opt(SHAPE_MOUSE);
6863 	update_mouseshape(-1);
6864     }
6865 #endif
6866 
6867 #ifdef FEAT_PRINTER
6868     else if (varp == &p_popt)
6869 	errmsg = parse_printoptions();
6870 # if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
6871     else if (varp == &p_pmfn)
6872 	errmsg = parse_printmbfont();
6873 # endif
6874 #endif
6875 
6876 #ifdef FEAT_LANGMAP
6877     /* 'langmap' */
6878     else if (varp == &p_langmap)
6879 	langmap_set();
6880 #endif
6881 
6882 #ifdef FEAT_LINEBREAK
6883     /* 'breakat' */
6884     else if (varp == &p_breakat)
6885 	fill_breakat_flags();
6886 #endif
6887 
6888 #ifdef FEAT_TITLE
6889     /* 'titlestring' and 'iconstring' */
6890     else if (varp == &p_titlestring || varp == &p_iconstring)
6891     {
6892 # ifdef FEAT_STL_OPT
6893 	int	flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6894 
6895 	/* NULL => statusline syntax */
6896 	if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6897 	    stl_syntax |= flagval;
6898 	else
6899 	    stl_syntax &= ~flagval;
6900 # endif
6901 	did_set_title(varp == &p_iconstring);
6902 
6903     }
6904 #endif
6905 
6906 #ifdef FEAT_GUI
6907     /* 'guioptions' */
6908     else if (varp == &p_go)
6909     {
6910 	gui_init_which_components(oldval);
6911 	redraw_gui_only = TRUE;
6912     }
6913 #endif
6914 
6915 #if defined(FEAT_GUI_TABLINE)
6916     /* 'guitablabel' */
6917     else if (varp == &p_gtl)
6918     {
6919 	redraw_tabline = TRUE;
6920 	redraw_gui_only = TRUE;
6921     }
6922     /* 'guitabtooltip' */
6923     else if (varp == &p_gtt)
6924     {
6925 	redraw_gui_only = TRUE;
6926     }
6927 #endif
6928 
6929 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6930     /* 'ttymouse' */
6931     else if (varp == &p_ttym)
6932     {
6933 	/* Switch the mouse off before changing the escape sequences used for
6934 	 * that. */
6935 	mch_setmouse(FALSE);
6936 	if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6937 	    errmsg = e_invarg;
6938 	else
6939 	    check_mouse_termcode();
6940 	if (termcap_active)
6941 	    setmouse();		/* may switch it on again */
6942     }
6943 #endif
6944 
6945     /* 'selection' */
6946     else if (varp == &p_sel)
6947     {
6948 	if (*p_sel == NUL
6949 		|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6950 	    errmsg = e_invarg;
6951     }
6952 
6953     /* 'selectmode' */
6954     else if (varp == &p_slm)
6955     {
6956 	if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6957 	    errmsg = e_invarg;
6958     }
6959 
6960 #ifdef FEAT_BROWSE
6961     /* 'browsedir' */
6962     else if (varp == &p_bsdir)
6963     {
6964 	if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6965 		&& !mch_isdir(p_bsdir))
6966 	    errmsg = e_invarg;
6967     }
6968 #endif
6969 
6970     /* 'keymodel' */
6971     else if (varp == &p_km)
6972     {
6973 	if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6974 	    errmsg = e_invarg;
6975 	else
6976 	{
6977 	    km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6978 	    km_startsel = (vim_strchr(p_km, 'a') != NULL);
6979 	}
6980     }
6981 
6982     /* 'mousemodel' */
6983     else if (varp == &p_mousem)
6984     {
6985 	if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6986 	    errmsg = e_invarg;
6987 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6988 	else if (*p_mousem != *oldval)
6989 	    /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6990 	     * to create or delete the popup menus. */
6991 	    gui_motif_update_mousemodel(root_menu);
6992 #endif
6993     }
6994 
6995     /* 'switchbuf' */
6996     else if (varp == &p_swb)
6997     {
6998 	if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
6999 	    errmsg = e_invarg;
7000     }
7001 
7002     /* 'debug' */
7003     else if (varp == &p_debug)
7004     {
7005 	if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
7006 	    errmsg = e_invarg;
7007     }
7008 
7009     /* 'display' */
7010     else if (varp == &p_dy)
7011     {
7012 	if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7013 	    errmsg = e_invarg;
7014 	else
7015 	    (void)init_chartab();
7016 
7017     }
7018 
7019     /* 'eadirection' */
7020     else if (varp == &p_ead)
7021     {
7022 	if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7023 	    errmsg = e_invarg;
7024     }
7025 
7026 #ifdef FEAT_CLIPBOARD
7027     /* 'clipboard' */
7028     else if (varp == &p_cb)
7029 	errmsg = check_clipboard_option();
7030 #endif
7031 
7032 #ifdef FEAT_SPELL
7033     /* When 'spelllang' or 'spellfile' is set and there is a window for this
7034      * buffer in which 'spell' is set load the wordlists. */
7035     else if (varp == &(curwin->w_s->b_p_spl)
7036 	    || varp == &(curwin->w_s->b_p_spf))
7037     {
7038 	errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
7039     }
7040     /* When 'spellcapcheck' is set compile the regexp program. */
7041     else if (varp == &(curwin->w_s->b_p_spc))
7042     {
7043 	errmsg = compile_cap_prog(curwin->w_s);
7044     }
7045     /* 'spellsuggest' */
7046     else if (varp == &p_sps)
7047     {
7048 	if (spell_check_sps() != OK)
7049 	    errmsg = e_invarg;
7050     }
7051     /* 'mkspellmem' */
7052     else if (varp == &p_msm)
7053     {
7054 	if (spell_check_msm() != OK)
7055 	    errmsg = e_invarg;
7056     }
7057 #endif
7058 
7059     /* When 'bufhidden' is set, check for valid value. */
7060     else if (gvarp == &p_bh)
7061     {
7062 	if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7063 	    errmsg = e_invarg;
7064     }
7065 
7066     /* When 'buftype' is set, check for valid value. */
7067     else if (gvarp == &p_bt)
7068     {
7069 	if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7070 	    errmsg = e_invarg;
7071 	else
7072 	{
7073 	    if (curwin->w_status_height)
7074 	    {
7075 		curwin->w_redr_status = TRUE;
7076 		redraw_later(VALID);
7077 	    }
7078 	    curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
7079 #ifdef FEAT_TITLE
7080 	    redraw_titles();
7081 #endif
7082 	}
7083     }
7084 
7085 #ifdef FEAT_STL_OPT
7086     /* 'statusline' or 'rulerformat' */
7087     else if (gvarp == &p_stl || varp == &p_ruf)
7088     {
7089 	int wid;
7090 
7091 	if (varp == &p_ruf)	/* reset ru_wid first */
7092 	    ru_wid = 0;
7093 	s = *varp;
7094 	if (varp == &p_ruf && *s == '%')
7095 	{
7096 	    /* set ru_wid if 'ruf' starts with "%99(" */
7097 	    if (*++s == '-')	/* ignore a '-' */
7098 		s++;
7099 	    wid = getdigits(&s);
7100 	    if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7101 		ru_wid = wid;
7102 	    else
7103 		errmsg = check_stl_option(p_ruf);
7104 	}
7105 	/* check 'statusline' only if it doesn't start with "%!" */
7106 	else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
7107 	    errmsg = check_stl_option(s);
7108 	if (varp == &p_ruf && errmsg == NULL)
7109 	    comp_col();
7110     }
7111 #endif
7112 
7113 #ifdef FEAT_INS_EXPAND
7114     /* check if it is a valid value for 'complete' -- Acevedo */
7115     else if (gvarp == &p_cpt)
7116     {
7117 	for (s = *varp; *s;)
7118 	{
7119 	    while (*s == ',' || *s == ' ')
7120 		s++;
7121 	    if (!*s)
7122 		break;
7123 	    if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7124 	    {
7125 		errmsg = illegal_char(errbuf, *s);
7126 		break;
7127 	    }
7128 	    if (*++s != NUL && *s != ',' && *s != ' ')
7129 	    {
7130 		if (s[-1] == 'k' || s[-1] == 's')
7131 		{
7132 		    /* skip optional filename after 'k' and 's' */
7133 		    while (*s && *s != ',' && *s != ' ')
7134 		    {
7135 			if (*s == '\\' && s[1] != NUL)
7136 			    ++s;
7137 			++s;
7138 		    }
7139 		}
7140 		else
7141 		{
7142 		    if (errbuf != NULL)
7143 		    {
7144 			sprintf((char *)errbuf,
7145 				     _("E535: Illegal character after <%c>"),
7146 				     *--s);
7147 			errmsg = errbuf;
7148 		    }
7149 		    else
7150 			errmsg = (char_u *)"";
7151 		    break;
7152 		}
7153 	    }
7154 	}
7155     }
7156 
7157     /* 'completeopt' */
7158     else if (varp == &p_cot)
7159     {
7160 	if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7161 	    errmsg = e_invarg;
7162 	else
7163 	    completeopt_was_set();
7164     }
7165 #endif /* FEAT_INS_EXPAND */
7166 
7167 #ifdef FEAT_SIGNS
7168     /* 'signcolumn' */
7169     else if (varp == &curwin->w_p_scl)
7170     {
7171 	if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7172 	    errmsg = e_invarg;
7173     }
7174 #endif
7175 
7176 
7177 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7178     /* 'toolbar' */
7179     else if (varp == &p_toolbar)
7180     {
7181 	if (opt_strings_flags(p_toolbar, p_toolbar_values,
7182 			      &toolbar_flags, TRUE) != OK)
7183 	    errmsg = e_invarg;
7184 	else
7185 	{
7186 	    out_flush();
7187 	    gui_mch_show_toolbar((toolbar_flags &
7188 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7189 	}
7190     }
7191 #endif
7192 
7193 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
7194     /* 'toolbariconsize': GTK+ 2 only */
7195     else if (varp == &p_tbis)
7196     {
7197 	if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7198 	    errmsg = e_invarg;
7199 	else
7200 	{
7201 	    out_flush();
7202 	    gui_mch_show_toolbar((toolbar_flags &
7203 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7204 	}
7205     }
7206 #endif
7207 
7208     /* 'pastetoggle': translate key codes like in a mapping */
7209     else if (varp == &p_pt)
7210     {
7211 	if (*p_pt)
7212 	{
7213 	    (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
7214 	    if (p != NULL)
7215 	    {
7216 		if (new_value_alloced)
7217 		    free_string_option(p_pt);
7218 		p_pt = p;
7219 		new_value_alloced = TRUE;
7220 	    }
7221 	}
7222     }
7223 
7224     /* 'backspace' */
7225     else if (varp == &p_bs)
7226     {
7227 	if (VIM_ISDIGIT(*p_bs))
7228 	{
7229 	    if (*p_bs > '2' || p_bs[1] != NUL)
7230 		errmsg = e_invarg;
7231 	}
7232 	else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7233 	    errmsg = e_invarg;
7234     }
7235     else if (varp == &p_bo)
7236     {
7237 	if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7238 	    errmsg = e_invarg;
7239     }
7240 
7241     /* 'tagcase' */
7242     else if (gvarp == &p_tc)
7243     {
7244 	unsigned int	*flags;
7245 
7246 	if (opt_flags & OPT_LOCAL)
7247 	{
7248 	    p = curbuf->b_p_tc;
7249 	    flags = &curbuf->b_tc_flags;
7250 	}
7251 	else
7252 	{
7253 	    p = p_tc;
7254 	    flags = &tc_flags;
7255 	}
7256 
7257 	if ((opt_flags & OPT_LOCAL) && *p == NUL)
7258 	    /* make the local value empty: use the global value */
7259 	    *flags = 0;
7260 	else if (*p == NUL
7261 		|| opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7262 	    errmsg = e_invarg;
7263     }
7264 
7265 #ifdef FEAT_MBYTE
7266     /* 'casemap' */
7267     else if (varp == &p_cmp)
7268     {
7269 	if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7270 	    errmsg = e_invarg;
7271     }
7272 #endif
7273 
7274 #ifdef FEAT_DIFF
7275     /* 'diffopt' */
7276     else if (varp == &p_dip)
7277     {
7278 	if (diffopt_changed() == FAIL)
7279 	    errmsg = e_invarg;
7280     }
7281 #endif
7282 
7283 #ifdef FEAT_FOLDING
7284     /* 'foldmethod' */
7285     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7286     {
7287 	if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7288 		|| *curwin->w_p_fdm == NUL)
7289 	    errmsg = e_invarg;
7290 	else
7291 	{
7292 	    foldUpdateAll(curwin);
7293 	    if (foldmethodIsDiff(curwin))
7294 		newFoldLevel();
7295 	}
7296     }
7297 # ifdef FEAT_EVAL
7298     /* 'foldexpr' */
7299     else if (varp == &curwin->w_p_fde)
7300     {
7301 	if (foldmethodIsExpr(curwin))
7302 	    foldUpdateAll(curwin);
7303     }
7304 # endif
7305     /* 'foldmarker' */
7306     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7307     {
7308 	p = vim_strchr(*varp, ',');
7309 	if (p == NULL)
7310 	    errmsg = (char_u *)N_("E536: comma required");
7311 	else if (p == *varp || p[1] == NUL)
7312 	    errmsg = e_invarg;
7313 	else if (foldmethodIsMarker(curwin))
7314 	    foldUpdateAll(curwin);
7315     }
7316     /* 'commentstring' */
7317     else if (gvarp == &p_cms)
7318     {
7319 	if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7320 	    errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7321     }
7322     /* 'foldopen' */
7323     else if (varp == &p_fdo)
7324     {
7325 	if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7326 	    errmsg = e_invarg;
7327     }
7328     /* 'foldclose' */
7329     else if (varp == &p_fcl)
7330     {
7331 	if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7332 	    errmsg = e_invarg;
7333     }
7334     /* 'foldignore' */
7335     else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7336     {
7337 	if (foldmethodIsIndent(curwin))
7338 	    foldUpdateAll(curwin);
7339     }
7340 #endif
7341 
7342 #ifdef FEAT_VIRTUALEDIT
7343     /* 'virtualedit' */
7344     else if (varp == &p_ve)
7345     {
7346 	if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7347 	    errmsg = e_invarg;
7348 	else if (STRCMP(p_ve, oldval) != 0)
7349 	{
7350 	    /* Recompute cursor position in case the new 've' setting
7351 	     * changes something. */
7352 	    validate_virtcol();
7353 	    coladvance(curwin->w_virtcol);
7354 	}
7355     }
7356 #endif
7357 
7358 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7359     else if (varp == &p_csqf)
7360     {
7361 	if (p_csqf != NULL)
7362 	{
7363 	    p = p_csqf;
7364 	    while (*p != NUL)
7365 	    {
7366 		if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7367 			|| p[1] == NUL
7368 			|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7369 			|| (p[2] != NUL && p[2] != ','))
7370 		{
7371 		    errmsg = e_invarg;
7372 		    break;
7373 		}
7374 		else if (p[2] == NUL)
7375 		    break;
7376 		else
7377 		    p += 3;
7378 	    }
7379 	}
7380     }
7381 #endif
7382 
7383 #ifdef FEAT_CINDENT
7384     /* 'cinoptions' */
7385     else if (gvarp == &p_cino)
7386     {
7387 	/* TODO: recognize errors */
7388 	parse_cino(curbuf);
7389     }
7390 #endif
7391 
7392 #if defined(FEAT_RENDER_OPTIONS)
7393     /* 'renderoptions' */
7394     else if (varp == &p_rop && gui.in_use)
7395     {
7396 	if (!gui_mch_set_rendering_options(p_rop))
7397 	    errmsg = e_invarg;
7398     }
7399 #endif
7400 
7401 #ifdef FEAT_AUTOCMD
7402     else if (gvarp == &p_ft)
7403     {
7404 	if (!valid_filetype(*varp))
7405 	    errmsg = e_invarg;
7406 	else
7407 	    ft_changed = STRCMP(oldval, *varp) != 0;
7408     }
7409 #endif
7410 
7411 #ifdef FEAT_SYN_HL
7412     else if (gvarp == &p_syn)
7413     {
7414 	if (!valid_filetype(*varp))
7415 	    errmsg = e_invarg;
7416     }
7417 #endif
7418 
7419 #ifdef FEAT_TERMINAL
7420     /* 'termkey' */
7421     else if (varp == &curwin->w_p_tk)
7422     {
7423 	if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7424 	    errmsg = e_invarg;
7425     }
7426     /* 'termsize' */
7427     else if (varp == &curwin->w_p_tms)
7428     {
7429 	if (*curwin->w_p_tms != NUL)
7430 	{
7431 	    p = skipdigits(curwin->w_p_tms);
7432 	    if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7433 		errmsg = e_invarg;
7434 	}
7435     }
7436 #endif
7437 
7438     /* Options that are a list of flags. */
7439     else
7440     {
7441 	p = NULL;
7442 	if (varp == &p_ww) /* 'whichwrap' */
7443 	    p = (char_u *)WW_ALL;
7444 	if (varp == &p_shm) /* 'shortmess' */
7445 	    p = (char_u *)SHM_ALL;
7446 	else if (varp == &(p_cpo)) /* 'cpoptions' */
7447 	    p = (char_u *)CPO_ALL;
7448 	else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
7449 	    p = (char_u *)FO_ALL;
7450 #ifdef FEAT_CONCEAL
7451 	else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
7452 	    p = (char_u *)COCU_ALL;
7453 #endif
7454 	else if (varp == &p_mouse) /* 'mouse' */
7455 	{
7456 #ifdef FEAT_MOUSE
7457 	    p = (char_u *)MOUSE_ALL;
7458 #else
7459 	    if (*p_mouse != NUL)
7460 		errmsg = (char_u *)N_("E538: No mouse support");
7461 #endif
7462 	}
7463 #if defined(FEAT_GUI)
7464 	else if (varp == &p_go) /* 'guioptions' */
7465 	    p = (char_u *)GO_ALL;
7466 #endif
7467 	if (p != NULL)
7468 	{
7469 	    for (s = *varp; *s; ++s)
7470 		if (vim_strchr(p, *s) == NULL)
7471 		{
7472 		    errmsg = illegal_char(errbuf, *s);
7473 		    break;
7474 		}
7475 	}
7476     }
7477 
7478     /*
7479      * If error detected, restore the previous value.
7480      */
7481     if (errmsg != NULL)
7482     {
7483 	if (new_value_alloced)
7484 	    free_string_option(*varp);
7485 	*varp = oldval;
7486 	/*
7487 	 * When resetting some values, need to act on it.
7488 	 */
7489 	if (did_chartab)
7490 	    (void)init_chartab();
7491 	if (varp == &p_hl)
7492 	    (void)highlight_changed();
7493     }
7494     else
7495     {
7496 #ifdef FEAT_EVAL
7497 	/* Remember where the option was set. */
7498 	set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7499 #endif
7500 	/*
7501 	 * Free string options that are in allocated memory.
7502 	 * Use "free_oldval", because recursiveness may change the flags under
7503 	 * our fingers (esp. init_highlight()).
7504 	 */
7505 	if (free_oldval)
7506 	    free_string_option(oldval);
7507 	if (new_value_alloced)
7508 	    options[opt_idx].flags |= P_ALLOCED;
7509 	else
7510 	    options[opt_idx].flags &= ~P_ALLOCED;
7511 
7512 	if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
7513 		&& ((int)options[opt_idx].indir & PV_BOTH))
7514 	{
7515 	    /* global option with local value set to use global value; free
7516 	     * the local value and make it empty */
7517 	    p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7518 	    free_string_option(*(char_u **)p);
7519 	    *(char_u **)p = empty_option;
7520 	}
7521 
7522 	/* May set global value for local option. */
7523 	else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7524 	    set_string_option_global(opt_idx, varp);
7525 
7526 #ifdef FEAT_AUTOCMD
7527 	/*
7528 	 * Trigger the autocommand only after setting the flags.
7529 	 */
7530 # ifdef FEAT_SYN_HL
7531 	/* When 'syntax' is set, load the syntax of that name */
7532 	if (varp == &(curbuf->b_p_syn))
7533 	{
7534 	    apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7535 					       curbuf->b_fname, TRUE, curbuf);
7536 	}
7537 # endif
7538 	else if (varp == &(curbuf->b_p_ft))
7539 	{
7540 	    /* 'filetype' is set, trigger the FileType autocommand.
7541 	     * Skip this when called from a modeline and the filetype was
7542 	     * already set to this value. */
7543 	    if (!(opt_flags & OPT_MODELINE) || ft_changed)
7544 	    {
7545 		did_filetype = TRUE;
7546 		apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7547 					       curbuf->b_fname, TRUE, curbuf);
7548 		/* Just in case the old "curbuf" is now invalid. */
7549 		if (varp != &(curbuf->b_p_ft))
7550 		    varp = NULL;
7551 	    }
7552 	}
7553 #endif
7554 #ifdef FEAT_SPELL
7555 	if (varp == &(curwin->w_s->b_p_spl))
7556 	{
7557 	    char_u	fname[200];
7558 	    char_u	*q = curwin->w_s->b_p_spl;
7559 
7560 	    /* Skip the first name if it is "cjk". */
7561 	    if (STRNCMP(q, "cjk,", 4) == 0)
7562 		q += 4;
7563 
7564 	    /*
7565 	     * Source the spell/LANG.vim in 'runtimepath'.
7566 	     * They could set 'spellcapcheck' depending on the language.
7567 	     * Use the first name in 'spelllang' up to '_region' or
7568 	     * '.encoding'.
7569 	     */
7570 	    for (p = q; *p != NUL; ++p)
7571 		if (vim_strchr((char_u *)"_.,", *p) != NULL)
7572 		    break;
7573 	    vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7574 	    source_runtime(fname, DIP_ALL);
7575 	}
7576 #endif
7577     }
7578 
7579 #ifdef FEAT_MOUSE
7580     if (varp == &p_mouse)
7581     {
7582 # ifdef FEAT_MOUSE_TTY
7583 	if (*p_mouse == NUL)
7584 	    mch_setmouse(FALSE);    /* switch mouse off */
7585 	else
7586 # endif
7587 	    setmouse();		    /* in case 'mouse' changed */
7588     }
7589 #endif
7590 
7591     if (curwin->w_curswant != MAXCOL
7592 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
7593 	curwin->w_set_curswant = TRUE;
7594 
7595 #ifdef FEAT_GUI
7596     /* check redraw when it's not a GUI option or the GUI is active. */
7597     if (!redraw_gui_only || gui.in_use)
7598 #endif
7599 	check_redraw(options[opt_idx].flags);
7600 
7601     return errmsg;
7602 }
7603 
7604 #if defined(FEAT_SYN_HL) || defined(PROTO)
7605 /*
7606  * Simple int comparison function for use with qsort()
7607  */
7608     static int
7609 int_cmp(const void *a, const void *b)
7610 {
7611     return *(const int *)a - *(const int *)b;
7612 }
7613 
7614 /*
7615  * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7616  * Returns error message, NULL if it's OK.
7617  */
7618     char_u *
7619 check_colorcolumn(win_T *wp)
7620 {
7621     char_u	*s;
7622     int		col;
7623     int		count = 0;
7624     int		color_cols[256];
7625     int		i;
7626     int		j = 0;
7627 
7628     if (wp->w_buffer == NULL)
7629 	return NULL;  /* buffer was closed */
7630 
7631     for (s = wp->w_p_cc; *s != NUL && count < 255;)
7632     {
7633 	if (*s == '-' || *s == '+')
7634 	{
7635 	    /* -N and +N: add to 'textwidth' */
7636 	    col = (*s == '-') ? -1 : 1;
7637 	    ++s;
7638 	    if (!VIM_ISDIGIT(*s))
7639 		return e_invarg;
7640 	    col = col * getdigits(&s);
7641 	    if (wp->w_buffer->b_p_tw == 0)
7642 		goto skip;  /* 'textwidth' not set, skip this item */
7643 	    col += wp->w_buffer->b_p_tw;
7644 	    if (col < 0)
7645 		goto skip;
7646 	}
7647 	else if (VIM_ISDIGIT(*s))
7648 	    col = getdigits(&s);
7649 	else
7650 	    return e_invarg;
7651 	color_cols[count++] = col - 1;  /* 1-based to 0-based */
7652 skip:
7653 	if (*s == NUL)
7654 	    break;
7655 	if (*s != ',')
7656 	    return e_invarg;
7657 	if (*++s == NUL)
7658 	    return e_invarg;  /* illegal trailing comma as in "set cc=80," */
7659     }
7660 
7661     vim_free(wp->w_p_cc_cols);
7662     if (count == 0)
7663 	wp->w_p_cc_cols = NULL;
7664     else
7665     {
7666 	wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7667 	if (wp->w_p_cc_cols != NULL)
7668 	{
7669 	    /* sort the columns for faster usage on screen redraw inside
7670 	     * win_line() */
7671 	    qsort(color_cols, count, sizeof(int), int_cmp);
7672 
7673 	    for (i = 0; i < count; ++i)
7674 		/* skip duplicates */
7675 		if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7676 		    wp->w_p_cc_cols[j++] = color_cols[i];
7677 	    wp->w_p_cc_cols[j] = -1;  /* end marker */
7678 	}
7679     }
7680 
7681     return NULL;  /* no error */
7682 }
7683 #endif
7684 
7685 /*
7686  * Handle setting 'listchars' or 'fillchars'.
7687  * Returns error message, NULL if it's OK.
7688  */
7689     static char_u *
7690 set_chars_option(char_u **varp)
7691 {
7692     int		round, i, len, entries;
7693     char_u	*p, *s;
7694     int		c1, c2 = 0;
7695     struct charstab
7696     {
7697 	int	*cp;
7698 	char	*name;
7699     };
7700     static struct charstab filltab[] =
7701     {
7702 	{&fill_stl,	"stl"},
7703 	{&fill_stlnc,	"stlnc"},
7704 	{&fill_vert,	"vert"},
7705 	{&fill_fold,	"fold"},
7706 	{&fill_diff,	"diff"},
7707     };
7708     static struct charstab lcstab[] =
7709     {
7710 	{&lcs_eol,	"eol"},
7711 	{&lcs_ext,	"extends"},
7712 	{&lcs_nbsp,	"nbsp"},
7713 	{&lcs_prec,	"precedes"},
7714 	{&lcs_space,	"space"},
7715 	{&lcs_tab2,	"tab"},
7716 	{&lcs_trail,	"trail"},
7717 #ifdef FEAT_CONCEAL
7718 	{&lcs_conceal,	"conceal"},
7719 #else
7720 	{NULL,		"conceal"},
7721 #endif
7722     };
7723     struct charstab *tab;
7724 
7725     if (varp == &p_lcs)
7726     {
7727 	tab = lcstab;
7728 	entries = sizeof(lcstab) / sizeof(struct charstab);
7729     }
7730     else
7731     {
7732 	tab = filltab;
7733 	entries = sizeof(filltab) / sizeof(struct charstab);
7734     }
7735 
7736     /* first round: check for valid value, second round: assign values */
7737     for (round = 0; round <= 1; ++round)
7738     {
7739 	if (round > 0)
7740 	{
7741 	    /* After checking that the value is valid: set defaults: space for
7742 	     * 'fillchars', NUL for 'listchars' */
7743 	    for (i = 0; i < entries; ++i)
7744 		if (tab[i].cp != NULL)
7745 		    *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7746 	    if (varp == &p_lcs)
7747 		lcs_tab1 = NUL;
7748 	    else
7749 		fill_diff = '-';
7750 	}
7751 	p = *varp;
7752 	while (*p)
7753 	{
7754 	    for (i = 0; i < entries; ++i)
7755 	    {
7756 		len = (int)STRLEN(tab[i].name);
7757 		if (STRNCMP(p, tab[i].name, len) == 0
7758 			&& p[len] == ':'
7759 			&& p[len + 1] != NUL)
7760 		{
7761 		    s = p + len + 1;
7762 #ifdef FEAT_MBYTE
7763 		    c1 = mb_ptr2char_adv(&s);
7764 		    if (mb_char2cells(c1) > 1)
7765 			continue;
7766 #else
7767 		    c1 = *s++;
7768 #endif
7769 		    if (tab[i].cp == &lcs_tab2)
7770 		    {
7771 			if (*s == NUL)
7772 			    continue;
7773 #ifdef FEAT_MBYTE
7774 			c2 = mb_ptr2char_adv(&s);
7775 			if (mb_char2cells(c2) > 1)
7776 			    continue;
7777 #else
7778 			c2 = *s++;
7779 #endif
7780 		    }
7781 		    if (*s == ',' || *s == NUL)
7782 		    {
7783 			if (round)
7784 			{
7785 			    if (tab[i].cp == &lcs_tab2)
7786 			    {
7787 				lcs_tab1 = c1;
7788 				lcs_tab2 = c2;
7789 			    }
7790 			    else if (tab[i].cp != NULL)
7791 				*(tab[i].cp) = c1;
7792 
7793 			}
7794 			p = s;
7795 			break;
7796 		    }
7797 		}
7798 	    }
7799 
7800 	    if (i == entries)
7801 		return e_invarg;
7802 	    if (*p == ',')
7803 		++p;
7804 	}
7805     }
7806 
7807     return NULL;	/* no error */
7808 }
7809 
7810 #ifdef FEAT_STL_OPT
7811 /*
7812  * Check validity of options with the 'statusline' format.
7813  * Return error message or NULL.
7814  */
7815     char_u *
7816 check_stl_option(char_u *s)
7817 {
7818     int		itemcnt = 0;
7819     int		groupdepth = 0;
7820     static char_u   errbuf[80];
7821 
7822     while (*s && itemcnt < STL_MAX_ITEM)
7823     {
7824 	/* Check for valid keys after % sequences */
7825 	while (*s && *s != '%')
7826 	    s++;
7827 	if (!*s)
7828 	    break;
7829 	s++;
7830 	if (*s != '%' && *s != ')')
7831 	    ++itemcnt;
7832 	if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7833 	{
7834 	    s++;
7835 	    continue;
7836 	}
7837 	if (*s == ')')
7838 	{
7839 	    s++;
7840 	    if (--groupdepth < 0)
7841 		break;
7842 	    continue;
7843 	}
7844 	if (*s == '-')
7845 	    s++;
7846 	while (VIM_ISDIGIT(*s))
7847 	    s++;
7848 	if (*s == STL_USER_HL)
7849 	    continue;
7850 	if (*s == '.')
7851 	{
7852 	    s++;
7853 	    while (*s && VIM_ISDIGIT(*s))
7854 		s++;
7855 	}
7856 	if (*s == '(')
7857 	{
7858 	    groupdepth++;
7859 	    continue;
7860 	}
7861 	if (vim_strchr(STL_ALL, *s) == NULL)
7862 	{
7863 	    return illegal_char(errbuf, *s);
7864 	}
7865 	if (*s == '{')
7866 	{
7867 	    s++;
7868 	    while (*s != '}' && *s)
7869 		s++;
7870 	    if (*s != '}')
7871 		return (char_u *)N_("E540: Unclosed expression sequence");
7872 	}
7873     }
7874     if (itemcnt >= STL_MAX_ITEM)
7875 	return (char_u *)N_("E541: too many items");
7876     if (groupdepth != 0)
7877 	return (char_u *)N_("E542: unbalanced groups");
7878     return NULL;
7879 }
7880 #endif
7881 
7882 #ifdef FEAT_CLIPBOARD
7883 /*
7884  * Extract the items in the 'clipboard' option and set global values.
7885  */
7886     static char_u *
7887 check_clipboard_option(void)
7888 {
7889     int		new_unnamed = 0;
7890     int		new_autoselect_star = FALSE;
7891     int		new_autoselect_plus = FALSE;
7892     int		new_autoselectml = FALSE;
7893     int		new_html = FALSE;
7894     regprog_T	*new_exclude_prog = NULL;
7895     char_u	*errmsg = NULL;
7896     char_u	*p;
7897 
7898     for (p = p_cb; *p != NUL; )
7899     {
7900 	if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7901 	{
7902 	    new_unnamed |= CLIP_UNNAMED;
7903 	    p += 7;
7904 	}
7905 	else if (STRNCMP(p, "unnamedplus", 11) == 0
7906 					    && (p[11] == ',' || p[11] == NUL))
7907 	{
7908 	    new_unnamed |= CLIP_UNNAMED_PLUS;
7909 	    p += 11;
7910 	}
7911 	else if (STRNCMP(p, "autoselect", 10) == 0
7912 					    && (p[10] == ',' || p[10] == NUL))
7913 	{
7914 	    new_autoselect_star = TRUE;
7915 	    p += 10;
7916 	}
7917 	else if (STRNCMP(p, "autoselectplus", 14) == 0
7918 					    && (p[14] == ',' || p[14] == NUL))
7919 	{
7920 	    new_autoselect_plus = TRUE;
7921 	    p += 14;
7922 	}
7923 	else if (STRNCMP(p, "autoselectml", 12) == 0
7924 					    && (p[12] == ',' || p[12] == NUL))
7925 	{
7926 	    new_autoselectml = TRUE;
7927 	    p += 12;
7928 	}
7929 	else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7930 	{
7931 	    new_html = TRUE;
7932 	    p += 4;
7933 	}
7934 	else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7935 	{
7936 	    p += 8;
7937 	    new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7938 	    if (new_exclude_prog == NULL)
7939 		errmsg = e_invarg;
7940 	    break;
7941 	}
7942 	else
7943 	{
7944 	    errmsg = e_invarg;
7945 	    break;
7946 	}
7947 	if (*p == ',')
7948 	    ++p;
7949     }
7950     if (errmsg == NULL)
7951     {
7952 	clip_unnamed = new_unnamed;
7953 	clip_autoselect_star = new_autoselect_star;
7954 	clip_autoselect_plus = new_autoselect_plus;
7955 	clip_autoselectml = new_autoselectml;
7956 	clip_html = new_html;
7957 	vim_regfree(clip_exclude_prog);
7958 	clip_exclude_prog = new_exclude_prog;
7959 #ifdef FEAT_GUI_GTK
7960 	if (gui.in_use)
7961 	{
7962 	    gui_gtk_set_selection_targets();
7963 	    gui_gtk_set_dnd_targets();
7964 	}
7965 #endif
7966     }
7967     else
7968 	vim_regfree(new_exclude_prog);
7969 
7970     return errmsg;
7971 }
7972 #endif
7973 
7974 #ifdef FEAT_SPELL
7975     static char_u *
7976 did_set_spell_option(int is_spellfile)
7977 {
7978     char_u  *errmsg = NULL;
7979     win_T   *wp;
7980     int	    l;
7981 
7982     if (is_spellfile)
7983     {
7984 	l = (int)STRLEN(curwin->w_s->b_p_spf);
7985 	if (l > 0 && (l < 4
7986 			|| STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7987 	    errmsg = e_invarg;
7988     }
7989 
7990     if (errmsg == NULL)
7991     {
7992 	FOR_ALL_WINDOWS(wp)
7993 	    if (wp->w_buffer == curbuf && wp->w_p_spell)
7994 	    {
7995 		errmsg = did_set_spelllang(wp);
7996 		break;
7997 	    }
7998     }
7999     return errmsg;
8000 }
8001 
8002 /*
8003  * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8004  * Return error message when failed, NULL when OK.
8005  */
8006     static char_u *
8007 compile_cap_prog(synblock_T *synblock)
8008 {
8009     regprog_T   *rp = synblock->b_cap_prog;
8010     char_u	*re;
8011 
8012     if (*synblock->b_p_spc == NUL)
8013 	synblock->b_cap_prog = NULL;
8014     else
8015     {
8016 	/* Prepend a ^ so that we only match at one column */
8017 	re = concat_str((char_u *)"^", synblock->b_p_spc);
8018 	if (re != NULL)
8019 	{
8020 	    synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
8021 	    vim_free(re);
8022 	    if (synblock->b_cap_prog == NULL)
8023 	    {
8024 		synblock->b_cap_prog = rp; /* restore the previous program */
8025 		return e_invarg;
8026 	    }
8027 	}
8028     }
8029 
8030     vim_regfree(rp);
8031     return NULL;
8032 }
8033 #endif
8034 
8035 #if defined(FEAT_EVAL) || defined(PROTO)
8036 /*
8037  * Set the scriptID for an option, taking care of setting the buffer- or
8038  * window-local value.
8039  */
8040     static void
8041 set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
8042 {
8043     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8044     int		indir = (int)options[opt_idx].indir;
8045 
8046     /* Remember where the option was set.  For local options need to do that
8047      * in the buffer or window structure. */
8048     if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
8049 	options[opt_idx].scriptID = id;
8050     if (both || (opt_flags & OPT_LOCAL))
8051     {
8052 	if (indir & PV_BUF)
8053 	    curbuf->b_p_scriptID[indir & PV_MASK] = id;
8054 	else if (indir & PV_WIN)
8055 	    curwin->w_p_scriptID[indir & PV_MASK] = id;
8056     }
8057 }
8058 #endif
8059 
8060 /*
8061  * Set the value of a boolean option, and take care of side effects.
8062  * Returns NULL for success, or an error message for an error.
8063  */
8064     static char_u *
8065 set_bool_option(
8066     int		opt_idx,		/* index in options[] table */
8067     char_u	*varp,			/* pointer to the option variable */
8068     int		value,			/* new value */
8069     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
8070 {
8071     int		old_value = *(int *)varp;
8072 
8073     /* Disallow changing some options from secure mode */
8074     if ((secure
8075 #ifdef HAVE_SANDBOX
8076 		|| sandbox != 0
8077 #endif
8078 		) && (options[opt_idx].flags & P_SECURE))
8079 	return e_secure;
8080 
8081     *(int *)varp = value;	    /* set the new value */
8082 #ifdef FEAT_EVAL
8083     /* Remember where the option was set. */
8084     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
8085 #endif
8086 
8087 #ifdef FEAT_GUI
8088     need_mouse_correct = TRUE;
8089 #endif
8090 
8091     /* May set global value for local option. */
8092     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8093 	*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8094 
8095     /*
8096      * Handle side effects of changing a bool option.
8097      */
8098 
8099     /* 'compatible' */
8100     if ((int *)varp == &p_cp)
8101     {
8102 	compatible_set();
8103     }
8104 
8105 #ifdef FEAT_LANGMAP
8106     if ((int *)varp == &p_lrm)
8107 	/* 'langremap' -> !'langnoremap' */
8108 	p_lnr = !p_lrm;
8109     else if ((int *)varp == &p_lnr)
8110 	/* 'langnoremap' -> !'langremap' */
8111 	p_lrm = !p_lnr;
8112 #endif
8113 
8114 #ifdef FEAT_PERSISTENT_UNDO
8115     /* 'undofile' */
8116     else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8117     {
8118 	/* Only take action when the option was set. When reset we do not
8119 	 * delete the undo file, the option may be set again without making
8120 	 * any changes in between. */
8121 	if (curbuf->b_p_udf || p_udf)
8122 	{
8123 	    char_u	hash[UNDO_HASH_SIZE];
8124 	    buf_T	*save_curbuf = curbuf;
8125 
8126 	    FOR_ALL_BUFFERS(curbuf)
8127 	    {
8128 		/* When 'undofile' is set globally: for every buffer, otherwise
8129 		 * only for the current buffer: Try to read in the undofile,
8130 		 * if one exists, the buffer wasn't changed and the buffer was
8131 		 * loaded */
8132 		if ((curbuf == save_curbuf
8133 				|| (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8134 			&& !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8135 		{
8136 		    u_compute_hash(hash);
8137 		    u_read_undo(NULL, hash, curbuf->b_fname);
8138 		}
8139 	    }
8140 	    curbuf = save_curbuf;
8141 	}
8142     }
8143 #endif
8144 
8145     else if ((int *)varp == &curbuf->b_p_ro)
8146     {
8147 	/* when 'readonly' is reset globally, also reset readonlymode */
8148 	if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8149 	    readonlymode = FALSE;
8150 
8151 	/* when 'readonly' is set may give W10 again */
8152 	if (curbuf->b_p_ro)
8153 	    curbuf->b_did_warn = FALSE;
8154 
8155 #ifdef FEAT_TITLE
8156 	redraw_titles();
8157 #endif
8158     }
8159 
8160 #ifdef FEAT_GUI
8161     else if ((int *)varp == &p_mh)
8162     {
8163 	if (!p_mh)
8164 	    gui_mch_mousehide(FALSE);
8165     }
8166 #endif
8167 
8168     /* when 'modifiable' is changed, redraw the window title */
8169     else if ((int *)varp == &curbuf->b_p_ma)
8170     {
8171 # ifdef FEAT_TERMINAL
8172 	/* Cannot set 'modifiable' when in Terminal mode. */
8173 	if (term_in_normal_mode()
8174 			 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
8175 	{
8176 	    curbuf->b_p_ma = FALSE;
8177 	    return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8178 	}
8179 # endif
8180 # ifdef FEAT_TITLE
8181 	redraw_titles();
8182 # endif
8183     }
8184 #ifdef FEAT_TITLE
8185     /* when 'endofline' is changed, redraw the window title */
8186     else if ((int *)varp == &curbuf->b_p_eol)
8187     {
8188 	redraw_titles();
8189     }
8190     /* when 'fixeol' is changed, redraw the window title */
8191     else if ((int *)varp == &curbuf->b_p_fixeol)
8192     {
8193 	redraw_titles();
8194     }
8195 # ifdef FEAT_MBYTE
8196     /* when 'bomb' is changed, redraw the window title and tab page text */
8197     else if ((int *)varp == &curbuf->b_p_bomb)
8198     {
8199 	redraw_titles();
8200     }
8201 # endif
8202 #endif
8203 
8204     /* when 'bin' is set also set some other options */
8205     else if ((int *)varp == &curbuf->b_p_bin)
8206     {
8207 	set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8208 #ifdef FEAT_TITLE
8209 	redraw_titles();
8210 #endif
8211     }
8212 
8213 #ifdef FEAT_AUTOCMD
8214     /* when 'buflisted' changes, trigger autocommands */
8215     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8216     {
8217 	apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8218 						    NULL, NULL, TRUE, curbuf);
8219     }
8220 #endif
8221 
8222     /* when 'swf' is set, create swapfile, when reset remove swapfile */
8223     else if ((int *)varp == &curbuf->b_p_swf)
8224     {
8225 	if (curbuf->b_p_swf && p_uc)
8226 	    ml_open_file(curbuf);		/* create the swap file */
8227 	else
8228 	    /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8229 	     * buf->b_p_swf */
8230 	    mf_close_file(curbuf, TRUE);	/* remove the swap file */
8231     }
8232 
8233     /* when 'terse' is set change 'shortmess' */
8234     else if ((int *)varp == &p_terse)
8235     {
8236 	char_u	*p;
8237 
8238 	p = vim_strchr(p_shm, SHM_SEARCH);
8239 
8240 	/* insert 's' in p_shm */
8241 	if (p_terse && p == NULL)
8242 	{
8243 	    STRCPY(IObuff, p_shm);
8244 	    STRCAT(IObuff, "s");
8245 	    set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
8246 	}
8247 	/* remove 's' from p_shm */
8248 	else if (!p_terse && p != NULL)
8249 	    STRMOVE(p, p + 1);
8250     }
8251 
8252     /* when 'paste' is set or reset also change other options */
8253     else if ((int *)varp == &p_paste)
8254     {
8255 	paste_option_changed();
8256     }
8257 
8258     /* when 'insertmode' is set from an autocommand need to do work here */
8259     else if ((int *)varp == &p_im)
8260     {
8261 	if (p_im)
8262 	{
8263 	    if ((State & INSERT) == 0)
8264 		need_start_insertmode = TRUE;
8265 	    stop_insert_mode = FALSE;
8266 	}
8267 	/* only reset if it was set previously */
8268 	else if (old_value)
8269 	{
8270 	    need_start_insertmode = FALSE;
8271 	    stop_insert_mode = TRUE;
8272 	    if (restart_edit != 0 && mode_displayed)
8273 		clear_cmdline = TRUE;	/* remove "(insert)" */
8274 	    restart_edit = 0;
8275 	}
8276     }
8277 
8278     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8279     else if ((int *)varp == &p_ic && p_hls)
8280     {
8281 	redraw_all_later(SOME_VALID);
8282     }
8283 
8284 #ifdef FEAT_SEARCH_EXTRA
8285     /* when 'hlsearch' is set or reset: reset no_hlsearch */
8286     else if ((int *)varp == &p_hls)
8287     {
8288 	SET_NO_HLSEARCH(FALSE);
8289     }
8290 #endif
8291 
8292 #ifdef FEAT_SCROLLBIND
8293     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8294      * at the end of normal_cmd() */
8295     else if ((int *)varp == &curwin->w_p_scb)
8296     {
8297 	if (curwin->w_p_scb)
8298 	{
8299 	    do_check_scrollbind(FALSE);
8300 	    curwin->w_scbind_pos = curwin->w_topline;
8301 	}
8302     }
8303 #endif
8304 
8305 #if defined(FEAT_QUICKFIX)
8306     /* There can be only one window with 'previewwindow' set. */
8307     else if ((int *)varp == &curwin->w_p_pvw)
8308     {
8309 	if (curwin->w_p_pvw)
8310 	{
8311 	    win_T	*win;
8312 
8313 	    FOR_ALL_WINDOWS(win)
8314 		if (win->w_p_pvw && win != curwin)
8315 		{
8316 		    curwin->w_p_pvw = FALSE;
8317 		    return (char_u *)N_("E590: A preview window already exists");
8318 		}
8319 	}
8320     }
8321 #endif
8322 
8323     /* when 'textmode' is set or reset also change 'fileformat' */
8324     else if ((int *)varp == &curbuf->b_p_tx)
8325     {
8326 	set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8327     }
8328 
8329     /* when 'textauto' is set or reset also change 'fileformats' */
8330     else if ((int *)varp == &p_ta)
8331 	set_string_option_direct((char_u *)"ffs", -1,
8332 				 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
8333 						     OPT_FREE | opt_flags, 0);
8334 
8335     /*
8336      * When 'lisp' option changes include/exclude '-' in
8337      * keyword characters.
8338      */
8339 #ifdef FEAT_LISP
8340     else if (varp == (char_u *)&(curbuf->b_p_lisp))
8341     {
8342 	(void)buf_init_chartab(curbuf, FALSE);	    /* ignore errors */
8343     }
8344 #endif
8345 
8346 #ifdef FEAT_TITLE
8347     /* when 'title' changed, may need to change the title; same for 'icon' */
8348     else if ((int *)varp == &p_title)
8349     {
8350 	did_set_title(FALSE);
8351     }
8352 
8353     else if ((int *)varp == &p_icon)
8354     {
8355 	did_set_title(TRUE);
8356     }
8357 #endif
8358 
8359     else if ((int *)varp == &curbuf->b_changed)
8360     {
8361 	if (!value)
8362 	    save_file_ff(curbuf);	/* Buffer is unchanged */
8363 #ifdef FEAT_TITLE
8364 	redraw_titles();
8365 #endif
8366 #ifdef FEAT_AUTOCMD
8367 	modified_was_set = value;
8368 #endif
8369     }
8370 
8371 #ifdef BACKSLASH_IN_FILENAME
8372     else if ((int *)varp == &p_ssl)
8373     {
8374 	if (p_ssl)
8375 	{
8376 	    psepc = '/';
8377 	    psepcN = '\\';
8378 	    pseps[0] = '/';
8379 	}
8380 	else
8381 	{
8382 	    psepc = '\\';
8383 	    psepcN = '/';
8384 	    pseps[0] = '\\';
8385 	}
8386 
8387 	/* need to adjust the file name arguments and buffer names. */
8388 	buflist_slash_adjust();
8389 	alist_slash_adjust();
8390 # ifdef FEAT_EVAL
8391 	scriptnames_slash_adjust();
8392 # endif
8393     }
8394 #endif
8395 
8396     /* If 'wrap' is set, set w_leftcol to zero. */
8397     else if ((int *)varp == &curwin->w_p_wrap)
8398     {
8399 	if (curwin->w_p_wrap)
8400 	    curwin->w_leftcol = 0;
8401     }
8402 
8403     else if ((int *)varp == &p_ea)
8404     {
8405 	if (p_ea && !old_value)
8406 	    win_equal(curwin, FALSE, 0);
8407     }
8408 
8409     else if ((int *)varp == &p_wiv)
8410     {
8411 	/*
8412 	 * When 'weirdinvert' changed, set/reset 't_xs'.
8413 	 * Then set 'weirdinvert' according to value of 't_xs'.
8414 	 */
8415 	if (p_wiv && !old_value)
8416 	    T_XS = (char_u *)"y";
8417 	else if (!p_wiv && old_value)
8418 	    T_XS = empty_option;
8419 	p_wiv = (*T_XS != NUL);
8420     }
8421 
8422 #ifdef FEAT_BEVAL
8423     else if ((int *)varp == &p_beval)
8424     {
8425 	if (p_beval && !old_value)
8426 	    gui_mch_enable_beval_area(balloonEval);
8427 	else if (!p_beval && old_value)
8428 	    gui_mch_disable_beval_area(balloonEval);
8429     }
8430 #endif
8431 
8432 #ifdef FEAT_AUTOCHDIR
8433     else if ((int *)varp == &p_acd)
8434     {
8435 	/* Change directories when the 'acd' option is set now. */
8436 	DO_AUTOCHDIR
8437     }
8438 #endif
8439 
8440 #ifdef FEAT_DIFF
8441     /* 'diff' */
8442     else if ((int *)varp == &curwin->w_p_diff)
8443     {
8444 	/* May add or remove the buffer from the list of diff buffers. */
8445 	diff_buf_adjust(curwin);
8446 # ifdef FEAT_FOLDING
8447 	if (foldmethodIsDiff(curwin))
8448 	    foldUpdateAll(curwin);
8449 # endif
8450     }
8451 #endif
8452 
8453 #ifdef USE_IM_CONTROL
8454     /* 'imdisable' */
8455     else if ((int *)varp == &p_imdisable)
8456     {
8457 	/* Only de-activate it here, it will be enabled when changing mode. */
8458 	if (p_imdisable)
8459 	    im_set_active(FALSE);
8460 	else if (State & INSERT)
8461 	    /* When the option is set from an autocommand, it may need to take
8462 	     * effect right away. */
8463 	    im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
8464     }
8465 #endif
8466 
8467 #ifdef FEAT_SPELL
8468     /* 'spell' */
8469     else if ((int *)varp == &curwin->w_p_spell)
8470     {
8471 	if (curwin->w_p_spell)
8472 	{
8473 	    char_u	*errmsg = did_set_spelllang(curwin);
8474 	    if (errmsg != NULL)
8475 		EMSG(_(errmsg));
8476 	}
8477     }
8478 #endif
8479 
8480 #ifdef FEAT_FKMAP
8481     else if ((int *)varp == &p_altkeymap)
8482     {
8483 	if (old_value != p_altkeymap)
8484 	{
8485 	    if (!p_altkeymap)
8486 	    {
8487 		p_hkmap = p_fkmap;
8488 		p_fkmap = 0;
8489 	    }
8490 	    else
8491 	    {
8492 		p_fkmap = p_hkmap;
8493 		p_hkmap = 0;
8494 	    }
8495 	    (void)init_chartab();
8496 	}
8497     }
8498 
8499     /*
8500      * In case some second language keymapping options have changed, check
8501      * and correct the setting in a consistent way.
8502      */
8503 
8504     /*
8505      * If hkmap or fkmap are set, reset Arabic keymapping.
8506      */
8507     if ((p_hkmap || p_fkmap) && p_altkeymap)
8508     {
8509 	p_altkeymap = p_fkmap;
8510 # ifdef FEAT_ARABIC
8511 	curwin->w_p_arab = FALSE;
8512 # endif
8513 	(void)init_chartab();
8514     }
8515 
8516     /*
8517      * If hkmap set, reset Farsi keymapping.
8518      */
8519     if (p_hkmap && p_altkeymap)
8520     {
8521 	p_altkeymap = 0;
8522 	p_fkmap = 0;
8523 # ifdef FEAT_ARABIC
8524 	curwin->w_p_arab = FALSE;
8525 # endif
8526 	(void)init_chartab();
8527     }
8528 
8529     /*
8530      * If fkmap set, reset Hebrew keymapping.
8531      */
8532     if (p_fkmap && !p_altkeymap)
8533     {
8534 	p_altkeymap = 1;
8535 	p_hkmap = 0;
8536 # ifdef FEAT_ARABIC
8537 	curwin->w_p_arab = FALSE;
8538 # endif
8539 	(void)init_chartab();
8540     }
8541 #endif
8542 
8543 #ifdef FEAT_ARABIC
8544     if ((int *)varp == &curwin->w_p_arab)
8545     {
8546 	if (curwin->w_p_arab)
8547 	{
8548 	    /*
8549 	     * 'arabic' is set, handle various sub-settings.
8550 	     */
8551 	    if (!p_tbidi)
8552 	    {
8553 		/* set rightleft mode */
8554 		if (!curwin->w_p_rl)
8555 		{
8556 		    curwin->w_p_rl = TRUE;
8557 		    changed_window_setting();
8558 		}
8559 
8560 		/* Enable Arabic shaping (major part of what Arabic requires) */
8561 		if (!p_arshape)
8562 		{
8563 		    p_arshape = TRUE;
8564 		    redraw_later_clear();
8565 		}
8566 	    }
8567 
8568 	    /* Arabic requires a utf-8 encoding, inform the user if its not
8569 	     * set. */
8570 	    if (STRCMP(p_enc, "utf-8") != 0)
8571 	    {
8572 		static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8573 
8574 		msg_source(HL_ATTR(HLF_W));
8575 		MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
8576 #ifdef FEAT_EVAL
8577 		set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8578 #endif
8579 	    }
8580 
8581 # ifdef FEAT_MBYTE
8582 	    /* set 'delcombine' */
8583 	    p_deco = TRUE;
8584 # endif
8585 
8586 # ifdef FEAT_KEYMAP
8587 	    /* Force-set the necessary keymap for arabic */
8588 	    set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8589 								   OPT_LOCAL);
8590 # endif
8591 # ifdef FEAT_FKMAP
8592 	    p_altkeymap = 0;
8593 	    p_hkmap = 0;
8594 	    p_fkmap = 0;
8595 	    (void)init_chartab();
8596 # endif
8597 	}
8598 	else
8599 	{
8600 	    /*
8601 	     * 'arabic' is reset, handle various sub-settings.
8602 	     */
8603 	    if (!p_tbidi)
8604 	    {
8605 		/* reset rightleft mode */
8606 		if (curwin->w_p_rl)
8607 		{
8608 		    curwin->w_p_rl = FALSE;
8609 		    changed_window_setting();
8610 		}
8611 
8612 		/* 'arabicshape' isn't reset, it is a global option and
8613 		 * another window may still need it "on". */
8614 	    }
8615 
8616 	    /* 'delcombine' isn't reset, it is a global option and another
8617 	     * window may still want it "on". */
8618 
8619 # ifdef FEAT_KEYMAP
8620 	    /* Revert to the default keymap */
8621 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8622 	    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8623 # endif
8624 	}
8625     }
8626 
8627 #endif
8628 
8629 #ifdef FEAT_TERMGUICOLORS
8630     /* 'termguicolors' */
8631     else if ((int *)varp == &p_tgc)
8632     {
8633 # ifdef FEAT_GUI
8634 	if (!gui.in_use && !gui.starting)
8635 # endif
8636 	    highlight_gui_started();
8637     }
8638 #endif
8639 
8640     /*
8641      * End of handling side effects for bool options.
8642      */
8643 
8644     /* after handling side effects, call autocommand */
8645 
8646     options[opt_idx].flags |= P_WAS_SET;
8647 
8648 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8649     if (!starting)
8650     {
8651 	char_u buf_old[2], buf_new[2], buf_type[7];
8652 	vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8653 	vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8654 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
8655 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8656 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8657 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8658 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8659 	reset_v_option_vars();
8660     }
8661 #endif
8662 
8663     comp_col();			    /* in case 'ruler' or 'showcmd' changed */
8664     if (curwin->w_curswant != MAXCOL
8665 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
8666 	curwin->w_set_curswant = TRUE;
8667     check_redraw(options[opt_idx].flags);
8668 
8669     return NULL;
8670 }
8671 
8672 /*
8673  * Set the value of a number option, and take care of side effects.
8674  * Returns NULL for success, or an error message for an error.
8675  */
8676     static char_u *
8677 set_num_option(
8678     int		opt_idx,		/* index in options[] table */
8679     char_u	*varp,			/* pointer to the option variable */
8680     long	value,			/* new value */
8681     char_u	*errbuf,		/* buffer for error messages */
8682     size_t	errbuflen,		/* length of "errbuf" */
8683     int		opt_flags)		/* OPT_LOCAL, OPT_GLOBAL and
8684 					   OPT_MODELINE */
8685 {
8686     char_u	*errmsg = NULL;
8687     long	old_value = *(long *)varp;
8688     long	old_Rows = Rows;	/* remember old Rows */
8689     long	old_Columns = Columns;	/* remember old Columns */
8690     long	*pp = (long *)varp;
8691 
8692     /* Disallow changing some options from secure mode. */
8693     if ((secure
8694 #ifdef HAVE_SANDBOX
8695 		|| sandbox != 0
8696 #endif
8697 		) && (options[opt_idx].flags & P_SECURE))
8698 	return e_secure;
8699 
8700     *pp = value;
8701 #ifdef FEAT_EVAL
8702     /* Remember where the option was set. */
8703     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
8704 #endif
8705 #ifdef FEAT_GUI
8706     need_mouse_correct = TRUE;
8707 #endif
8708 
8709     if (curbuf->b_p_sw < 0)
8710     {
8711 	errmsg = e_positive;
8712 	curbuf->b_p_sw = curbuf->b_p_ts;
8713     }
8714 
8715     /*
8716      * Number options that need some action when changed
8717      */
8718     if (pp == &p_wh || pp == &p_hh)
8719     {
8720 	if (p_wh < 1)
8721 	{
8722 	    errmsg = e_positive;
8723 	    p_wh = 1;
8724 	}
8725 	if (p_wmh > p_wh)
8726 	{
8727 	    errmsg = e_winheight;
8728 	    p_wh = p_wmh;
8729 	}
8730 	if (p_hh < 0)
8731 	{
8732 	    errmsg = e_positive;
8733 	    p_hh = 0;
8734 	}
8735 
8736 	/* Change window height NOW */
8737 	if (!ONE_WINDOW)
8738 	{
8739 	    if (pp == &p_wh && curwin->w_height < p_wh)
8740 		win_setheight((int)p_wh);
8741 	    if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8742 		win_setheight((int)p_hh);
8743 	}
8744     }
8745 
8746     /* 'winminheight' */
8747     else if (pp == &p_wmh)
8748     {
8749 	if (p_wmh < 0)
8750 	{
8751 	    errmsg = e_positive;
8752 	    p_wmh = 0;
8753 	}
8754 	if (p_wmh > p_wh)
8755 	{
8756 	    errmsg = e_winheight;
8757 	    p_wmh = p_wh;
8758 	}
8759 	win_setminheight();
8760     }
8761     else if (pp == &p_wiw)
8762     {
8763 	if (p_wiw < 1)
8764 	{
8765 	    errmsg = e_positive;
8766 	    p_wiw = 1;
8767 	}
8768 	if (p_wmw > p_wiw)
8769 	{
8770 	    errmsg = e_winwidth;
8771 	    p_wiw = p_wmw;
8772 	}
8773 
8774 	/* Change window width NOW */
8775 	if (!ONE_WINDOW && curwin->w_width < p_wiw)
8776 	    win_setwidth((int)p_wiw);
8777     }
8778 
8779     /* 'winminwidth' */
8780     else if (pp == &p_wmw)
8781     {
8782 	if (p_wmw < 0)
8783 	{
8784 	    errmsg = e_positive;
8785 	    p_wmw = 0;
8786 	}
8787 	if (p_wmw > p_wiw)
8788 	{
8789 	    errmsg = e_winwidth;
8790 	    p_wmw = p_wiw;
8791 	}
8792 	win_setminheight();
8793     }
8794 
8795     /* (re)set last window status line */
8796     else if (pp == &p_ls)
8797     {
8798 	last_status(FALSE);
8799     }
8800 
8801     /* (re)set tab page line */
8802     else if (pp == &p_stal)
8803     {
8804 	shell_new_rows();	/* recompute window positions and heights */
8805     }
8806 
8807 #ifdef FEAT_GUI
8808     else if (pp == &p_linespace)
8809     {
8810 	/* Recompute gui.char_height and resize the Vim window to keep the
8811 	 * same number of lines. */
8812 	if (gui.in_use && gui_mch_adjust_charheight() == OK)
8813 	    gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
8814     }
8815 #endif
8816 
8817 #ifdef FEAT_FOLDING
8818     /* 'foldlevel' */
8819     else if (pp == &curwin->w_p_fdl)
8820     {
8821 	if (curwin->w_p_fdl < 0)
8822 	    curwin->w_p_fdl = 0;
8823 	newFoldLevel();
8824     }
8825 
8826     /* 'foldminlines' */
8827     else if (pp == &curwin->w_p_fml)
8828     {
8829 	foldUpdateAll(curwin);
8830     }
8831 
8832     /* 'foldnestmax' */
8833     else if (pp == &curwin->w_p_fdn)
8834     {
8835 	if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8836 	    foldUpdateAll(curwin);
8837     }
8838 
8839     /* 'foldcolumn' */
8840     else if (pp == &curwin->w_p_fdc)
8841     {
8842 	if (curwin->w_p_fdc < 0)
8843 	{
8844 	    errmsg = e_positive;
8845 	    curwin->w_p_fdc = 0;
8846 	}
8847 	else if (curwin->w_p_fdc > 12)
8848 	{
8849 	    errmsg = e_invarg;
8850 	    curwin->w_p_fdc = 12;
8851 	}
8852     }
8853 #endif /* FEAT_FOLDING */
8854 
8855 #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
8856     /* 'shiftwidth' or 'tabstop' */
8857     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8858     {
8859 # ifdef FEAT_FOLDING
8860 	if (foldmethodIsIndent(curwin))
8861 	    foldUpdateAll(curwin);
8862 # endif
8863 # ifdef FEAT_CINDENT
8864 	/* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8865 	 * parse 'cinoptions'. */
8866 	if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8867 	    parse_cino(curbuf);
8868 # endif
8869     }
8870 #endif
8871 
8872 #ifdef FEAT_MBYTE
8873     /* 'maxcombine' */
8874     else if (pp == &p_mco)
8875     {
8876 	if (p_mco > MAX_MCO)
8877 	    p_mco = MAX_MCO;
8878 	else if (p_mco < 0)
8879 	    p_mco = 0;
8880 	screenclear();	    /* will re-allocate the screen */
8881     }
8882 #endif
8883 
8884     else if (pp == &curbuf->b_p_iminsert)
8885     {
8886 	if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8887 	{
8888 	    errmsg = e_invarg;
8889 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8890 	}
8891 	p_iminsert = curbuf->b_p_iminsert;
8892 	if (termcap_active)	/* don't do this in the alternate screen */
8893 	    showmode();
8894 #if defined(FEAT_KEYMAP)
8895 	/* Show/unshow value of 'keymap' in status lines. */
8896 	status_redraw_curbuf();
8897 #endif
8898     }
8899 
8900 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
8901     /* 'imstyle' */
8902     else if (pp == &p_imst)
8903     {
8904 	if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
8905 	    errmsg = e_invarg;
8906     }
8907 #endif
8908 
8909     else if (pp == &p_window)
8910     {
8911 	if (p_window < 1)
8912 	    p_window = 1;
8913 	else if (p_window >= Rows)
8914 	    p_window = Rows - 1;
8915     }
8916 
8917     else if (pp == &curbuf->b_p_imsearch)
8918     {
8919 	if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8920 	{
8921 	    errmsg = e_invarg;
8922 	    curbuf->b_p_imsearch = B_IMODE_NONE;
8923 	}
8924 	p_imsearch = curbuf->b_p_imsearch;
8925     }
8926 
8927 #ifdef FEAT_TITLE
8928     /* if 'titlelen' has changed, redraw the title */
8929     else if (pp == &p_titlelen)
8930     {
8931 	if (p_titlelen < 0)
8932 	{
8933 	    errmsg = e_positive;
8934 	    p_titlelen = 85;
8935 	}
8936 	if (starting != NO_SCREEN && old_value != p_titlelen)
8937 	    need_maketitle = TRUE;
8938     }
8939 #endif
8940 
8941     /* if p_ch changed value, change the command line height */
8942     else if (pp == &p_ch)
8943     {
8944 	if (p_ch < 1)
8945 	{
8946 	    errmsg = e_positive;
8947 	    p_ch = 1;
8948 	}
8949 	if (p_ch > Rows - min_rows() + 1)
8950 	    p_ch = Rows - min_rows() + 1;
8951 
8952 	/* Only compute the new window layout when startup has been
8953 	 * completed. Otherwise the frame sizes may be wrong. */
8954 	if (p_ch != old_value && full_screen
8955 #ifdef FEAT_GUI
8956 		&& !gui.starting
8957 #endif
8958 	   )
8959 	    command_height();
8960     }
8961 
8962     /* when 'updatecount' changes from zero to non-zero, open swap files */
8963     else if (pp == &p_uc)
8964     {
8965 	if (p_uc < 0)
8966 	{
8967 	    errmsg = e_positive;
8968 	    p_uc = 100;
8969 	}
8970 	if (p_uc && !old_value)
8971 	    ml_open_files();
8972     }
8973 #ifdef FEAT_CONCEAL
8974     else if (pp == &curwin->w_p_cole)
8975     {
8976 	if (curwin->w_p_cole < 0)
8977 	{
8978 	    errmsg = e_positive;
8979 	    curwin->w_p_cole = 0;
8980 	}
8981 	else if (curwin->w_p_cole > 3)
8982 	{
8983 	    errmsg = e_invarg;
8984 	    curwin->w_p_cole = 3;
8985 	}
8986     }
8987 #endif
8988 #ifdef MZSCHEME_GUI_THREADS
8989     else if (pp == &p_mzq)
8990 	mzvim_reset_timer();
8991 #endif
8992 
8993 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8994     /* 'pyxversion' */
8995     else if (pp == &p_pyx)
8996     {
8997 	if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8998 	    errmsg = e_invarg;
8999     }
9000 #endif
9001 
9002     /* sync undo before 'undolevels' changes */
9003     else if (pp == &p_ul)
9004     {
9005 	/* use the old value, otherwise u_sync() may not work properly */
9006 	p_ul = old_value;
9007 	u_sync(TRUE);
9008 	p_ul = value;
9009     }
9010     else if (pp == &curbuf->b_p_ul)
9011     {
9012 	/* use the old value, otherwise u_sync() may not work properly */
9013 	curbuf->b_p_ul = old_value;
9014 	u_sync(TRUE);
9015 	curbuf->b_p_ul = value;
9016     }
9017 
9018 #ifdef FEAT_LINEBREAK
9019     /* 'numberwidth' must be positive */
9020     else if (pp == &curwin->w_p_nuw)
9021     {
9022 	if (curwin->w_p_nuw < 1)
9023 	{
9024 	    errmsg = e_positive;
9025 	    curwin->w_p_nuw = 1;
9026 	}
9027 	if (curwin->w_p_nuw > 10)
9028 	{
9029 	    errmsg = e_invarg;
9030 	    curwin->w_p_nuw = 10;
9031 	}
9032 	curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
9033     }
9034 #endif
9035 
9036     else if (pp == &curbuf->b_p_tw)
9037     {
9038 	if (curbuf->b_p_tw < 0)
9039 	{
9040 	    errmsg = e_positive;
9041 	    curbuf->b_p_tw = 0;
9042 	}
9043 #ifdef FEAT_SYN_HL
9044 	{
9045 	    win_T	*wp;
9046 	    tabpage_T	*tp;
9047 
9048 	    FOR_ALL_TAB_WINDOWS(tp, wp)
9049 		check_colorcolumn(wp);
9050 	}
9051 #endif
9052     }
9053 
9054     /*
9055      * Check the bounds for numeric options here
9056      */
9057     if (Rows < min_rows() && full_screen)
9058     {
9059 	if (errbuf != NULL)
9060 	{
9061 	    vim_snprintf((char *)errbuf, errbuflen,
9062 			       _("E593: Need at least %d lines"), min_rows());
9063 	    errmsg = errbuf;
9064 	}
9065 	Rows = min_rows();
9066     }
9067     if (Columns < MIN_COLUMNS && full_screen)
9068     {
9069 	if (errbuf != NULL)
9070 	{
9071 	    vim_snprintf((char *)errbuf, errbuflen,
9072 			    _("E594: Need at least %d columns"), MIN_COLUMNS);
9073 	    errmsg = errbuf;
9074 	}
9075 	Columns = MIN_COLUMNS;
9076     }
9077     limit_screen_size();
9078 
9079     /*
9080      * If the screen (shell) height has been changed, assume it is the
9081      * physical screenheight.
9082      */
9083     if (old_Rows != Rows || old_Columns != Columns)
9084     {
9085 	/* Changing the screen size is not allowed while updating the screen. */
9086 	if (updating_screen)
9087 	    *pp = old_value;
9088 	else if (full_screen
9089 #ifdef FEAT_GUI
9090 		&& !gui.starting
9091 #endif
9092 	    )
9093 	    set_shellsize((int)Columns, (int)Rows, TRUE);
9094 	else
9095 	{
9096 	    /* Postpone the resizing; check the size and cmdline position for
9097 	     * messages. */
9098 	    check_shellsize();
9099 	    if (cmdline_row > Rows - p_ch && Rows > p_ch)
9100 		cmdline_row = Rows - p_ch;
9101 	}
9102 	if (p_window >= Rows || !option_was_set((char_u *)"window"))
9103 	    p_window = Rows - 1;
9104     }
9105 
9106     if (curbuf->b_p_ts <= 0)
9107     {
9108 	errmsg = e_positive;
9109 	curbuf->b_p_ts = 8;
9110     }
9111     if (p_tm < 0)
9112     {
9113 	errmsg = e_positive;
9114 	p_tm = 0;
9115     }
9116     if ((curwin->w_p_scr <= 0
9117 		|| (curwin->w_p_scr > curwin->w_height
9118 		    && curwin->w_height > 0))
9119 	    && full_screen)
9120     {
9121 	if (pp == &(curwin->w_p_scr))
9122 	{
9123 	    if (curwin->w_p_scr != 0)
9124 		errmsg = e_scroll;
9125 	    win_comp_scroll(curwin);
9126 	}
9127 	/* If 'scroll' became invalid because of a side effect silently adjust
9128 	 * it. */
9129 	else if (curwin->w_p_scr <= 0)
9130 	    curwin->w_p_scr = 1;
9131 	else /* curwin->w_p_scr > curwin->w_height */
9132 	    curwin->w_p_scr = curwin->w_height;
9133     }
9134     if (p_hi < 0)
9135     {
9136 	errmsg = e_positive;
9137 	p_hi = 0;
9138     }
9139     else if (p_hi > 10000)
9140     {
9141 	errmsg = e_invarg;
9142 	p_hi = 10000;
9143     }
9144     if (p_re < 0 || p_re > 2)
9145     {
9146 	errmsg = e_invarg;
9147 	p_re = 0;
9148     }
9149     if (p_report < 0)
9150     {
9151 	errmsg = e_positive;
9152 	p_report = 1;
9153     }
9154     if ((p_sj < -100 || p_sj >= Rows) && full_screen)
9155     {
9156 	if (Rows != old_Rows)	/* Rows changed, just adjust p_sj */
9157 	    p_sj = Rows / 2;
9158 	else
9159 	{
9160 	    errmsg = e_scroll;
9161 	    p_sj = 1;
9162 	}
9163     }
9164     if (p_so < 0 && full_screen)
9165     {
9166 	errmsg = e_scroll;
9167 	p_so = 0;
9168     }
9169     if (p_siso < 0 && full_screen)
9170     {
9171 	errmsg = e_positive;
9172 	p_siso = 0;
9173     }
9174 #ifdef FEAT_CMDWIN
9175     if (p_cwh < 1)
9176     {
9177 	errmsg = e_positive;
9178 	p_cwh = 1;
9179     }
9180 #endif
9181     if (p_ut < 0)
9182     {
9183 	errmsg = e_positive;
9184 	p_ut = 2000;
9185     }
9186     if (p_ss < 0)
9187     {
9188 	errmsg = e_positive;
9189 	p_ss = 0;
9190     }
9191 
9192     /* May set global value for local option. */
9193     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9194 	*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9195 
9196     options[opt_idx].flags |= P_WAS_SET;
9197 
9198 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9199     if (!starting && errmsg == NULL)
9200     {
9201 	char_u buf_old[11], buf_new[11], buf_type[7];
9202 	vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9203 	vim_snprintf((char *)buf_new, 10, "%ld", value);
9204 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
9205 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9206 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9207 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9208 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9209 	reset_v_option_vars();
9210     }
9211 #endif
9212 
9213     comp_col();			    /* in case 'columns' or 'ls' changed */
9214     if (curwin->w_curswant != MAXCOL
9215 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
9216 	curwin->w_set_curswant = TRUE;
9217     check_redraw(options[opt_idx].flags);
9218 
9219     return errmsg;
9220 }
9221 
9222 /*
9223  * Called after an option changed: check if something needs to be redrawn.
9224  */
9225     static void
9226 check_redraw(long_u flags)
9227 {
9228     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
9229     int		doclear = (flags & P_RCLR) == P_RCLR;
9230     int		all = ((flags & P_RALL) == P_RALL || doclear);
9231 
9232     if ((flags & P_RSTAT) || all)	/* mark all status lines dirty */
9233 	status_redraw_all();
9234 
9235     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9236 	changed_window_setting();
9237     if (flags & P_RBUF)
9238 	redraw_curbuf_later(NOT_VALID);
9239     if (flags & P_RWINONLY)
9240 	redraw_later(NOT_VALID);
9241     if (doclear)
9242 	redraw_all_later(CLEAR);
9243     else if (all)
9244 	redraw_all_later(NOT_VALID);
9245 }
9246 
9247 /*
9248  * Find index for option 'arg'.
9249  * Return -1 if not found.
9250  */
9251     static int
9252 findoption(char_u *arg)
9253 {
9254     int		    opt_idx;
9255     char	    *s, *p;
9256     static short    quick_tab[27] = {0, 0};	/* quick access table */
9257     int		    is_term_opt;
9258 
9259     /*
9260      * For first call: Initialize the quick-access table.
9261      * It contains the index for the first option that starts with a certain
9262      * letter.  There are 26 letters, plus the first "t_" option.
9263      */
9264     if (quick_tab[1] == 0)
9265     {
9266 	p = options[0].fullname;
9267 	for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9268 	{
9269 	    if (s[0] != p[0])
9270 	    {
9271 		if (s[0] == 't' && s[1] == '_')
9272 		    quick_tab[26] = opt_idx;
9273 		else
9274 		    quick_tab[CharOrdLow(s[0])] = opt_idx;
9275 	    }
9276 	    p = s;
9277 	}
9278     }
9279 
9280     /*
9281      * Check for name starting with an illegal character.
9282      */
9283 #ifdef EBCDIC
9284     if (!islower(arg[0]))
9285 #else
9286     if (arg[0] < 'a' || arg[0] > 'z')
9287 #endif
9288 	return -1;
9289 
9290     is_term_opt = (arg[0] == 't' && arg[1] == '_');
9291     if (is_term_opt)
9292 	opt_idx = quick_tab[26];
9293     else
9294 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9295     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9296     {
9297 	if (STRCMP(arg, s) == 0)		    /* match full name */
9298 	    break;
9299     }
9300     if (s == NULL && !is_term_opt)
9301     {
9302 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9303 	for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9304 	{
9305 	    s = options[opt_idx].shortname;
9306 	    if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
9307 		break;
9308 	    s = NULL;
9309 	}
9310     }
9311     if (s == NULL)
9312 	opt_idx = -1;
9313     return opt_idx;
9314 }
9315 
9316 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
9317 /*
9318  * Get the value for an option.
9319  *
9320  * Returns:
9321  * Number or Toggle option: 1, *numval gets value.
9322  *	     String option: 0, *stringval gets allocated string.
9323  * Hidden Number or Toggle option: -1.
9324  *	     hidden String option: -2.
9325  *		   unknown option: -3.
9326  */
9327     int
9328 get_option_value(
9329     char_u	*name,
9330     long	*numval,
9331     char_u	**stringval,	    /* NULL when only checking existence */
9332     int		opt_flags)
9333 {
9334     int		opt_idx;
9335     char_u	*varp;
9336 
9337     opt_idx = findoption(name);
9338     if (opt_idx < 0)		    /* unknown option */
9339     {
9340 	int key;
9341 
9342 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9343 		&& (key = find_key_option(name)) != 0)
9344 	{
9345 	    char_u key_name[2];
9346 	    char_u *p;
9347 
9348 	    if (key < 0)
9349 	    {
9350 		key_name[0] = KEY2TERMCAP0(key);
9351 		key_name[1] = KEY2TERMCAP1(key);
9352 	    }
9353 	    else
9354 	    {
9355 		key_name[0] = KS_KEY;
9356 		key_name[1] = (key & 0xff);
9357 	    }
9358 	    p = find_termcode(key_name);
9359 	    if (p != NULL)
9360 	    {
9361 		if (stringval != NULL)
9362 		    *stringval = vim_strsave(p);
9363 		return 0;
9364 	    }
9365 	}
9366 	return -3;
9367     }
9368 
9369     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9370 
9371     if (options[opt_idx].flags & P_STRING)
9372     {
9373 	if (varp == NULL)		    /* hidden option */
9374 	    return -2;
9375 	if (stringval != NULL)
9376 	{
9377 #ifdef FEAT_CRYPT
9378 	    /* never return the value of the crypt key */
9379 	    if ((char_u **)varp == &curbuf->b_p_key
9380 						&& **(char_u **)(varp) != NUL)
9381 		*stringval = vim_strsave((char_u *)"*****");
9382 	    else
9383 #endif
9384 		*stringval = vim_strsave(*(char_u **)(varp));
9385 	}
9386 	return 0;
9387     }
9388 
9389     if (varp == NULL)		    /* hidden option */
9390 	return -1;
9391     if (options[opt_idx].flags & P_NUM)
9392 	*numval = *(long *)varp;
9393     else
9394     {
9395 	/* Special case: 'modified' is b_changed, but we also want to consider
9396 	 * it set when 'ff' or 'fenc' changed. */
9397 	if ((int *)varp == &curbuf->b_changed)
9398 	    *numval = curbufIsChanged();
9399 	else
9400 	    *numval = (long) *(int *)varp;
9401     }
9402     return 1;
9403 }
9404 #endif
9405 
9406 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9407 /*
9408  * Returns the option attributes and its value. Unlike the above function it
9409  * will return either global value or local value of the option depending on
9410  * what was requested, but it will never return global value if it was
9411  * requested to return local one and vice versa. Neither it will return
9412  * buffer-local value if it was requested to return window-local one.
9413  *
9414  * Pretends that option is absent if it is not present in the requested scope
9415  * (i.e. has no global, window-local or buffer-local value depending on
9416  * opt_type). Uses
9417  *
9418  * Returned flags:
9419  *       0 hidden or unknown option, also option that does not have requested
9420  *	   type (see SREQ_* in vim.h)
9421  *  see SOPT_* in vim.h for other flags
9422  *
9423  * Possible opt_type values: see SREQ_* in vim.h
9424  */
9425     int
9426 get_option_value_strict(
9427     char_u	*name,
9428     long	*numval,
9429     char_u	**stringval,	    /* NULL when only obtaining attributes */
9430     int		opt_type,
9431     void	*from)
9432 {
9433     int		opt_idx;
9434     char_u	*varp = NULL;
9435     struct vimoption *p;
9436     int		r = 0;
9437 
9438     opt_idx = findoption(name);
9439     if (opt_idx < 0)
9440 	return 0;
9441 
9442     p = &(options[opt_idx]);
9443 
9444     /* Hidden option */
9445     if (p->var == NULL)
9446 	return 0;
9447 
9448     if (p->flags & P_BOOL)
9449 	r |= SOPT_BOOL;
9450     else if (p->flags & P_NUM)
9451 	r |= SOPT_NUM;
9452     else if (p->flags & P_STRING)
9453 	r |= SOPT_STRING;
9454 
9455     if (p->indir == PV_NONE)
9456     {
9457 	if (opt_type == SREQ_GLOBAL)
9458 	    r |= SOPT_GLOBAL;
9459 	else
9460 	    return 0; /* Did not request global-only option */
9461     }
9462     else
9463     {
9464 	if (p->indir & PV_BOTH)
9465 	    r |= SOPT_GLOBAL;
9466 	else if (opt_type == SREQ_GLOBAL)
9467 	    return 0; /* Requested global option */
9468 
9469 	if (p->indir & PV_WIN)
9470 	{
9471 	    if (opt_type == SREQ_BUF)
9472 		return 0; /* Did not request window-local option */
9473 	    else
9474 		r |= SOPT_WIN;
9475 	}
9476 	else if (p->indir & PV_BUF)
9477 	{
9478 	    if (opt_type == SREQ_WIN)
9479 		return 0; /* Did not request buffer-local option */
9480 	    else
9481 		r |= SOPT_BUF;
9482 	}
9483     }
9484 
9485     if (stringval == NULL)
9486 	return r;
9487 
9488     if (opt_type == SREQ_GLOBAL)
9489 	varp = p->var;
9490     else
9491     {
9492 	if (opt_type == SREQ_BUF)
9493 	{
9494 	    /* Special case: 'modified' is b_changed, but we also want to
9495 	     * consider it set when 'ff' or 'fenc' changed. */
9496 	    if (p->indir == PV_MOD)
9497 	    {
9498 		*numval = bufIsChanged((buf_T *) from);
9499 		varp = NULL;
9500 	    }
9501 #ifdef FEAT_CRYPT
9502 	    else if (p->indir == PV_KEY)
9503 	    {
9504 		/* never return the value of the crypt key */
9505 		*stringval = NULL;
9506 		varp = NULL;
9507 	    }
9508 #endif
9509 	    else
9510 	    {
9511 		aco_save_T	aco;
9512 		aucmd_prepbuf(&aco, (buf_T *) from);
9513 		varp = get_varp(p);
9514 		aucmd_restbuf(&aco);
9515 	    }
9516 	}
9517 	else if (opt_type == SREQ_WIN)
9518 	{
9519 	    win_T	*save_curwin;
9520 	    save_curwin = curwin;
9521 	    curwin = (win_T *) from;
9522 	    curbuf = curwin->w_buffer;
9523 	    varp = get_varp(p);
9524 	    curwin = save_curwin;
9525 	    curbuf = curwin->w_buffer;
9526 	}
9527 	if (varp == p->var)
9528 	    return (r | SOPT_UNSET);
9529     }
9530 
9531     if (varp != NULL)
9532     {
9533 	if (p->flags & P_STRING)
9534 	    *stringval = vim_strsave(*(char_u **)(varp));
9535 	else if (p->flags & P_NUM)
9536 	    *numval = *(long *) varp;
9537 	else
9538 	    *numval = *(int *)varp;
9539     }
9540 
9541     return r;
9542 }
9543 
9544 /*
9545  * Iterate over options. First argument is a pointer to a pointer to a
9546  * structure inside options[] array, second is option type like in the above
9547  * function.
9548  *
9549  * If first argument points to NULL it is assumed that iteration just started
9550  * and caller needs the very first value.
9551  * If first argument points to the end marker function returns NULL and sets
9552  * first argument to NULL.
9553  *
9554  * Returns full option name for current option on each call.
9555  */
9556     char_u *
9557 option_iter_next(void **option, int opt_type)
9558 {
9559     struct vimoption	*ret = NULL;
9560     do
9561     {
9562 	if (*option == NULL)
9563 	    *option = (void *) options;
9564 	else if (((struct vimoption *) (*option))->fullname == NULL)
9565 	{
9566 	    *option = NULL;
9567 	    return NULL;
9568 	}
9569 	else
9570 	    *option = (void *) (((struct vimoption *) (*option)) + 1);
9571 
9572 	ret = ((struct vimoption *) (*option));
9573 
9574 	/* Hidden option */
9575 	if (ret->var == NULL)
9576 	{
9577 	    ret = NULL;
9578 	    continue;
9579 	}
9580 
9581 	switch (opt_type)
9582 	{
9583 	    case SREQ_GLOBAL:
9584 		if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9585 		    ret = NULL;
9586 		break;
9587 	    case SREQ_BUF:
9588 		if (!(ret->indir & PV_BUF))
9589 		    ret = NULL;
9590 		break;
9591 	    case SREQ_WIN:
9592 		if (!(ret->indir & PV_WIN))
9593 		    ret = NULL;
9594 		break;
9595 	    default:
9596 		internal_error("option_iter_next()");
9597 		return NULL;
9598 	}
9599     }
9600     while (ret == NULL);
9601 
9602     return (char_u *)ret->fullname;
9603 }
9604 #endif
9605 
9606 /*
9607  * Set the value of option "name".
9608  * Use "string" for string options, use "number" for other options.
9609  *
9610  * Returns NULL on success or error message on error.
9611  */
9612     char_u *
9613 set_option_value(
9614     char_u	*name,
9615     long	number,
9616     char_u	*string,
9617     int		opt_flags)	/* OPT_LOCAL or 0 (both) */
9618 {
9619     int		opt_idx;
9620     char_u	*varp;
9621     long_u	flags;
9622 
9623     opt_idx = findoption(name);
9624     if (opt_idx < 0)
9625     {
9626 	int key;
9627 
9628 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9629 		&& (key = find_key_option(name)) != 0)
9630 	{
9631 	    char_u key_name[2];
9632 
9633 	    if (key < 0)
9634 	    {
9635 		key_name[0] = KEY2TERMCAP0(key);
9636 		key_name[1] = KEY2TERMCAP1(key);
9637 	    }
9638 	    else
9639 	    {
9640 		key_name[0] = KS_KEY;
9641 		key_name[1] = (key & 0xff);
9642 	    }
9643 	    add_termcode(key_name, string, FALSE);
9644 	    if (full_screen)
9645 		ttest(FALSE);
9646 	    redraw_all_later(CLEAR);
9647 	    return NULL;
9648 	}
9649 
9650 	EMSG2(_("E355: Unknown option: %s"), name);
9651     }
9652     else
9653     {
9654 	flags = options[opt_idx].flags;
9655 #ifdef HAVE_SANDBOX
9656 	/* Disallow changing some options in the sandbox */
9657 	if (sandbox > 0 && (flags & P_SECURE))
9658 	{
9659 	    EMSG(_(e_sandbox));
9660 	    return NULL;
9661 	}
9662 #endif
9663 	if (flags & P_STRING)
9664 	    return set_string_option(opt_idx, string, opt_flags);
9665 	else
9666 	{
9667 	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9668 	    if (varp != NULL)	/* hidden option is not changed */
9669 	    {
9670 		if (number == 0 && string != NULL)
9671 		{
9672 		    int idx;
9673 
9674 		    /* Either we are given a string or we are setting option
9675 		     * to zero. */
9676 		    for (idx = 0; string[idx] == '0'; ++idx)
9677 			;
9678 		    if (string[idx] != NUL || idx == 0)
9679 		    {
9680 			/* There's another character after zeros or the string
9681 			 * is empty.  In both cases, we are trying to set a
9682 			 * num option using a string. */
9683 			EMSG3(_("E521: Number required: &%s = '%s'"),
9684 								name, string);
9685 			return NULL;     /* do nothing as we hit an error */
9686 
9687 		    }
9688 		}
9689 		if (flags & P_NUM)
9690 		    return set_num_option(opt_idx, varp, number,
9691 							  NULL, 0, opt_flags);
9692 		else
9693 		    return set_bool_option(opt_idx, varp, (int)number,
9694 								   opt_flags);
9695 	    }
9696 	}
9697     }
9698     return NULL;
9699 }
9700 
9701 /*
9702  * Get the terminal code for a terminal option.
9703  * Returns NULL when not found.
9704  */
9705     char_u *
9706 get_term_code(char_u *tname)
9707 {
9708     int	    opt_idx;
9709     char_u  *varp;
9710 
9711     if (tname[0] != 't' || tname[1] != '_' ||
9712 	    tname[2] == NUL || tname[3] == NUL)
9713 	return NULL;
9714     if ((opt_idx = findoption(tname)) >= 0)
9715     {
9716 	varp = get_varp(&(options[opt_idx]));
9717 	if (varp != NULL)
9718 	    varp = *(char_u **)(varp);
9719 	return varp;
9720     }
9721     return find_termcode(tname + 2);
9722 }
9723 
9724     char_u *
9725 get_highlight_default(void)
9726 {
9727     int i;
9728 
9729     i = findoption((char_u *)"hl");
9730     if (i >= 0)
9731 	return options[i].def_val[VI_DEFAULT];
9732     return (char_u *)NULL;
9733 }
9734 
9735 #if defined(FEAT_MBYTE) || defined(PROTO)
9736     char_u *
9737 get_encoding_default(void)
9738 {
9739     int i;
9740 
9741     i = findoption((char_u *)"enc");
9742     if (i >= 0)
9743 	return options[i].def_val[VI_DEFAULT];
9744     return (char_u *)NULL;
9745 }
9746 #endif
9747 
9748 /*
9749  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9750  */
9751     static int
9752 find_key_option(char_u *arg)
9753 {
9754     int		key;
9755     int		modifiers;
9756 
9757     /*
9758      * Don't use get_special_key_code() for t_xx, we don't want it to call
9759      * add_termcap_entry().
9760      */
9761     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9762 	key = TERMCAP2KEY(arg[2], arg[3]);
9763     else
9764     {
9765 	--arg;			    /* put arg at the '<' */
9766 	modifiers = 0;
9767 	key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
9768 	if (modifiers)		    /* can't handle modifiers here */
9769 	    key = 0;
9770     }
9771     return key;
9772 }
9773 
9774 /*
9775  * if 'all' == 0: show changed options
9776  * if 'all' == 1: show all normal options
9777  * if 'all' == 2: show all terminal options
9778  */
9779     static void
9780 showoptions(
9781     int		all,
9782     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
9783 {
9784     struct vimoption	*p;
9785     int			col;
9786     int			isterm;
9787     char_u		*varp;
9788     struct vimoption	**items;
9789     int			item_count;
9790     int			run;
9791     int			row, rows;
9792     int			cols;
9793     int			i;
9794     int			len;
9795 
9796 #define INC 20
9797 #define GAP 3
9798 
9799     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9800 								PARAM_COUNT));
9801     if (items == NULL)
9802 	return;
9803 
9804     /* Highlight title */
9805     if (all == 2)
9806 	MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9807     else if (opt_flags & OPT_GLOBAL)
9808 	MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9809     else if (opt_flags & OPT_LOCAL)
9810 	MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9811     else
9812 	MSG_PUTS_TITLE(_("\n--- Options ---"));
9813 
9814     /*
9815      * do the loop two times:
9816      * 1. display the short items
9817      * 2. display the long items (only strings and numbers)
9818      */
9819     for (run = 1; run <= 2 && !got_int; ++run)
9820     {
9821 	/*
9822 	 * collect the items in items[]
9823 	 */
9824 	item_count = 0;
9825 	for (p = &options[0]; p->fullname != NULL; p++)
9826 	{
9827 	    varp = NULL;
9828 	    isterm = istermoption(p);
9829 	    if (opt_flags != 0)
9830 	    {
9831 		if (p->indir != PV_NONE && !isterm)
9832 		    varp = get_varp_scope(p, opt_flags);
9833 	    }
9834 	    else
9835 		varp = get_varp(p);
9836 	    if (varp != NULL
9837 		    && ((all == 2 && isterm)
9838 			|| (all == 1 && !isterm)
9839 			|| (all == 0 && !optval_default(p, varp))))
9840 	    {
9841 		if (p->flags & P_BOOL)
9842 		    len = 1;		/* a toggle option fits always */
9843 		else
9844 		{
9845 		    option_value2string(p, opt_flags);
9846 		    len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9847 		}
9848 		if ((len <= INC - GAP && run == 1) ||
9849 						(len > INC - GAP && run == 2))
9850 		    items[item_count++] = p;
9851 	    }
9852 	}
9853 
9854 	/*
9855 	 * display the items
9856 	 */
9857 	if (run == 1)
9858 	{
9859 	    cols = (Columns + GAP - 3) / INC;
9860 	    if (cols == 0)
9861 		cols = 1;
9862 	    rows = (item_count + cols - 1) / cols;
9863 	}
9864 	else	/* run == 2 */
9865 	    rows = item_count;
9866 	for (row = 0; row < rows && !got_int; ++row)
9867 	{
9868 	    msg_putchar('\n');			/* go to next line */
9869 	    if (got_int)			/* 'q' typed in more */
9870 		break;
9871 	    col = 0;
9872 	    for (i = row; i < item_count; i += rows)
9873 	    {
9874 		msg_col = col;			/* make columns */
9875 		showoneopt(items[i], opt_flags);
9876 		col += INC;
9877 	    }
9878 	    out_flush();
9879 	    ui_breakcheck();
9880 	}
9881     }
9882     vim_free(items);
9883 }
9884 
9885 /*
9886  * Return TRUE if option "p" has its default value.
9887  */
9888     static int
9889 optval_default(struct vimoption *p, char_u *varp)
9890 {
9891     int		dvi;
9892 
9893     if (varp == NULL)
9894 	return TRUE;	    /* hidden option is always at default */
9895     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9896     if (p->flags & P_NUM)
9897 	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
9898     if (p->flags & P_BOOL)
9899 			/* the cast to long is required for Manx C, long_i is
9900 			 * needed for MSVC */
9901 	return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
9902     /* P_STRING */
9903     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9904 }
9905 
9906 /*
9907  * showoneopt: show the value of one option
9908  * must not be called with a hidden option!
9909  */
9910     static void
9911 showoneopt(
9912     struct vimoption	*p,
9913     int			opt_flags)	/* OPT_LOCAL or OPT_GLOBAL */
9914 {
9915     char_u	*varp;
9916     int		save_silent = silent_mode;
9917 
9918     silent_mode = FALSE;
9919     info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
9920 
9921     varp = get_varp_scope(p, opt_flags);
9922 
9923     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9924     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9925 					? !curbufIsChanged() : !*(int *)varp))
9926 	MSG_PUTS("no");
9927     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9928 	MSG_PUTS("--");
9929     else
9930 	MSG_PUTS("  ");
9931     MSG_PUTS(p->fullname);
9932     if (!(p->flags & P_BOOL))
9933     {
9934 	msg_putchar('=');
9935 	/* put value string in NameBuff */
9936 	option_value2string(p, opt_flags);
9937 	msg_outtrans(NameBuff);
9938     }
9939 
9940     silent_mode = save_silent;
9941     info_message = FALSE;
9942 }
9943 
9944 /*
9945  * Write modified options as ":set" commands to a file.
9946  *
9947  * There are three values for "opt_flags":
9948  * OPT_GLOBAL:		   Write global option values and fresh values of
9949  *			   buffer-local options (used for start of a session
9950  *			   file).
9951  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9952  *			   curwin (used for a vimrc file).
9953  * OPT_LOCAL:		   Write buffer-local option values for curbuf, fresh
9954  *			   and local values for window-local options of
9955  *			   curwin.  Local values are also written when at the
9956  *			   default value, because a modeline or autocommand
9957  *			   may have set them when doing ":edit file" and the
9958  *			   user has set them back at the default or fresh
9959  *			   value.
9960  *			   When "local_only" is TRUE, don't write fresh
9961  *			   values, only local values (for ":mkview").
9962  * (fresh value = value used for a new buffer or window for a local option).
9963  *
9964  * Return FAIL on error, OK otherwise.
9965  */
9966     int
9967 makeset(FILE *fd, int opt_flags, int local_only)
9968 {
9969     struct vimoption	*p;
9970     char_u		*varp;			/* currently used value */
9971     char_u		*varp_fresh;		/* local value */
9972     char_u		*varp_local = NULL;	/* fresh value */
9973     char		*cmd;
9974     int			round;
9975     int			pri;
9976 
9977     /*
9978      * The options that don't have a default (terminal name, columns, lines)
9979      * are never written.  Terminal options are also not written.
9980      * Do the loop over "options[]" twice: once for options with the
9981      * P_PRI_MKRC flag and once without.
9982      */
9983     for (pri = 1; pri >= 0; --pri)
9984     {
9985       for (p = &options[0]; !istermoption(p); p++)
9986 	if (!(p->flags & P_NO_MKRC)
9987 		&& !istermoption(p)
9988 		&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
9989 	{
9990 	    /* skip global option when only doing locals */
9991 	    if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9992 		continue;
9993 
9994 	    /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9995 	     * file, they are always buffer-specific. */
9996 	    if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9997 		continue;
9998 
9999 	    /* Global values are only written when not at the default value. */
10000 	    varp = get_varp_scope(p, opt_flags);
10001 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10002 		continue;
10003 
10004 	    round = 2;
10005 	    if (p->indir != PV_NONE)
10006 	    {
10007 		if (p->var == VAR_WIN)
10008 		{
10009 		    /* skip window-local option when only doing globals */
10010 		    if (!(opt_flags & OPT_LOCAL))
10011 			continue;
10012 		    /* When fresh value of window-local option is not at the
10013 		     * default, need to write it too. */
10014 		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
10015 		    {
10016 			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10017 			if (!optval_default(p, varp_fresh))
10018 			{
10019 			    round = 1;
10020 			    varp_local = varp;
10021 			    varp = varp_fresh;
10022 			}
10023 		    }
10024 		}
10025 	    }
10026 
10027 	    /* Round 1: fresh value for window-local options.
10028 	     * Round 2: other values */
10029 	    for ( ; round <= 2; varp = varp_local, ++round)
10030 	    {
10031 		if (round == 1 || (opt_flags & OPT_GLOBAL))
10032 		    cmd = "set";
10033 		else
10034 		    cmd = "setlocal";
10035 
10036 		if (p->flags & P_BOOL)
10037 		{
10038 		    if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10039 			return FAIL;
10040 		}
10041 		else if (p->flags & P_NUM)
10042 		{
10043 		    if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10044 			return FAIL;
10045 		}
10046 		else    /* P_STRING */
10047 		{
10048 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10049 		    int		do_endif = FALSE;
10050 
10051 		    /* Don't set 'syntax' and 'filetype' again if the value is
10052 		     * already right, avoids reloading the syntax file. */
10053 		    if (
10054 # if defined(FEAT_SYN_HL)
10055 			    p->indir == PV_SYN
10056 #  if defined(FEAT_AUTOCMD)
10057 			    ||
10058 #  endif
10059 # endif
10060 # if defined(FEAT_AUTOCMD)
10061 			    p->indir == PV_FT
10062 # endif
10063 			    )
10064 		    {
10065 			if (fprintf(fd, "if &%s != '%s'", p->fullname,
10066 						       *(char_u **)(varp)) < 0
10067 				|| put_eol(fd) < 0)
10068 			    return FAIL;
10069 			do_endif = TRUE;
10070 		    }
10071 #endif
10072 		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10073 					  (p->flags & P_EXPAND) != 0) == FAIL)
10074 			return FAIL;
10075 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10076 		    if (do_endif)
10077 		    {
10078 			if (put_line(fd, "endif") == FAIL)
10079 			    return FAIL;
10080 		    }
10081 #endif
10082 		}
10083 	    }
10084 	}
10085     }
10086     return OK;
10087 }
10088 
10089 #if defined(FEAT_FOLDING) || defined(PROTO)
10090 /*
10091  * Generate set commands for the local fold options only.  Used when
10092  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10093  */
10094     int
10095 makefoldset(FILE *fd)
10096 {
10097     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10098 # ifdef FEAT_EVAL
10099 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10100 								       == FAIL
10101 # endif
10102 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10103 								       == FAIL
10104 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10105 								       == FAIL
10106 	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10107 	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10108 	    || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10109 	    || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10110 	    )
10111 	return FAIL;
10112 
10113     return OK;
10114 }
10115 #endif
10116 
10117     static int
10118 put_setstring(
10119     FILE	*fd,
10120     char	*cmd,
10121     char	*name,
10122     char_u	**valuep,
10123     int		expand)
10124 {
10125     char_u	*s;
10126     char_u	*buf;
10127 
10128     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10129 	return FAIL;
10130     if (*valuep != NULL)
10131     {
10132 	/* Output 'pastetoggle' as key names.  For other
10133 	 * options some characters have to be escaped with
10134 	 * CTRL-V or backslash */
10135 	if (valuep == &p_pt)
10136 	{
10137 	    s = *valuep;
10138 	    while (*s != NUL)
10139 		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
10140 		    return FAIL;
10141 	}
10142 	else if (expand)
10143 	{
10144 	    buf = alloc(MAXPATHL);
10145 	    if (buf == NULL)
10146 		return FAIL;
10147 	    home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10148 	    if (put_escstr(fd, buf, 2) == FAIL)
10149 	    {
10150 		vim_free(buf);
10151 		return FAIL;
10152 	    }
10153 	    vim_free(buf);
10154 	}
10155 	else if (put_escstr(fd, *valuep, 2) == FAIL)
10156 	    return FAIL;
10157     }
10158     if (put_eol(fd) < 0)
10159 	return FAIL;
10160     return OK;
10161 }
10162 
10163     static int
10164 put_setnum(
10165     FILE	*fd,
10166     char	*cmd,
10167     char	*name,
10168     long	*valuep)
10169 {
10170     long	wc;
10171 
10172     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10173 	return FAIL;
10174     if (wc_use_keyname((char_u *)valuep, &wc))
10175     {
10176 	/* print 'wildchar' and 'wildcharm' as a key name */
10177 	if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10178 	    return FAIL;
10179     }
10180     else if (fprintf(fd, "%ld", *valuep) < 0)
10181 	return FAIL;
10182     if (put_eol(fd) < 0)
10183 	return FAIL;
10184     return OK;
10185 }
10186 
10187     static int
10188 put_setbool(
10189     FILE	*fd,
10190     char	*cmd,
10191     char	*name,
10192     int		value)
10193 {
10194     if (value < 0)	/* global/local option using global value */
10195 	return OK;
10196     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10197 	    || put_eol(fd) < 0)
10198 	return FAIL;
10199     return OK;
10200 }
10201 
10202 /*
10203  * Clear all the terminal options.
10204  * If the option has been allocated, free the memory.
10205  * Terminal options are never hidden or indirect.
10206  */
10207     void
10208 clear_termoptions(void)
10209 {
10210     /*
10211      * Reset a few things before clearing the old options. This may cause
10212      * outputting a few things that the terminal doesn't understand, but the
10213      * screen will be cleared later, so this is OK.
10214      */
10215 #ifdef FEAT_MOUSE_TTY
10216     mch_setmouse(FALSE);	    /* switch mouse off */
10217 #endif
10218 #ifdef FEAT_TITLE
10219     mch_restore_title(3);	    /* restore window titles */
10220 #endif
10221 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10222     /* When starting the GUI close the display opened for the clipboard.
10223      * After restoring the title, because that will need the display. */
10224     if (gui.starting)
10225 	clear_xterm_clip();
10226 #endif
10227     stoptermcap();			/* stop termcap mode */
10228 
10229     free_termoptions();
10230 }
10231 
10232     void
10233 free_termoptions(void)
10234 {
10235     struct vimoption   *p;
10236 
10237     for (p = &options[0]; p->fullname != NULL; p++)
10238 	if (istermoption(p))
10239 	{
10240 	    if (p->flags & P_ALLOCED)
10241 		free_string_option(*(char_u **)(p->var));
10242 	    if (p->flags & P_DEF_ALLOCED)
10243 		free_string_option(p->def_val[VI_DEFAULT]);
10244 	    *(char_u **)(p->var) = empty_option;
10245 	    p->def_val[VI_DEFAULT] = empty_option;
10246 	    p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10247 	}
10248     clear_termcodes();
10249 }
10250 
10251 /*
10252  * Free the string for one term option, if it was allocated.
10253  * Set the string to empty_option and clear allocated flag.
10254  * "var" points to the option value.
10255  */
10256     void
10257 free_one_termoption(char_u *var)
10258 {
10259     struct vimoption   *p;
10260 
10261     for (p = &options[0]; p->fullname != NULL; p++)
10262 	if (p->var == var)
10263 	{
10264 	    if (p->flags & P_ALLOCED)
10265 		free_string_option(*(char_u **)(p->var));
10266 	    *(char_u **)(p->var) = empty_option;
10267 	    p->flags &= ~P_ALLOCED;
10268 	    break;
10269 	}
10270 }
10271 
10272 /*
10273  * Set the terminal option defaults to the current value.
10274  * Used after setting the terminal name.
10275  */
10276     void
10277 set_term_defaults(void)
10278 {
10279     struct vimoption   *p;
10280 
10281     for (p = &options[0]; p->fullname != NULL; p++)
10282     {
10283 	if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10284 	{
10285 	    if (p->flags & P_DEF_ALLOCED)
10286 	    {
10287 		free_string_option(p->def_val[VI_DEFAULT]);
10288 		p->flags &= ~P_DEF_ALLOCED;
10289 	    }
10290 	    p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10291 	    if (p->flags & P_ALLOCED)
10292 	    {
10293 		p->flags |= P_DEF_ALLOCED;
10294 		p->flags &= ~P_ALLOCED;	 /* don't free the value now */
10295 	    }
10296 	}
10297     }
10298 }
10299 
10300 /*
10301  * return TRUE if 'p' starts with 't_'
10302  */
10303     static int
10304 istermoption(struct vimoption *p)
10305 {
10306     return (p->fullname[0] == 't' && p->fullname[1] == '_');
10307 }
10308 
10309 /*
10310  * Compute columns for ruler and shown command. 'sc_col' is also used to
10311  * decide what the maximum length of a message on the status line can be.
10312  * If there is a status line for the last window, 'sc_col' is independent
10313  * of 'ru_col'.
10314  */
10315 
10316 #define COL_RULER 17	    /* columns needed by standard ruler */
10317 
10318     void
10319 comp_col(void)
10320 {
10321 #if defined(FEAT_CMDL_INFO)
10322     int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
10323 
10324     sc_col = 0;
10325     ru_col = 0;
10326     if (p_ru)
10327     {
10328 # ifdef FEAT_STL_OPT
10329 	ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10330 # else
10331 	ru_col = COL_RULER + 1;
10332 # endif
10333 	/* no last status line, adjust sc_col */
10334 	if (!last_has_status)
10335 	    sc_col = ru_col;
10336     }
10337     if (p_sc)
10338     {
10339 	sc_col += SHOWCMD_COLS;
10340 	if (!p_ru || last_has_status)	    /* no need for separating space */
10341 	    ++sc_col;
10342     }
10343     sc_col = Columns - sc_col;
10344     ru_col = Columns - ru_col;
10345     if (sc_col <= 0)		/* screen too narrow, will become a mess */
10346 	sc_col = 1;
10347     if (ru_col <= 0)
10348 	ru_col = 1;
10349 #else
10350     sc_col = Columns;
10351     ru_col = Columns;
10352 #endif
10353 }
10354 
10355 /*
10356  * Unset local option value, similar to ":set opt<".
10357  */
10358     void
10359 unset_global_local_option(char_u *name, void *from)
10360 {
10361     struct vimoption *p;
10362     int		opt_idx;
10363     buf_T	*buf = (buf_T *)from;
10364 
10365     opt_idx = findoption(name);
10366     if (opt_idx < 0)
10367 	return;
10368     p = &(options[opt_idx]);
10369 
10370     switch ((int)p->indir)
10371     {
10372 	/* global option with local value: use local value if it's been set */
10373 	case PV_EP:
10374 	    clear_string_option(&buf->b_p_ep);
10375 	    break;
10376 	case PV_KP:
10377 	    clear_string_option(&buf->b_p_kp);
10378 	    break;
10379 	case PV_PATH:
10380 	    clear_string_option(&buf->b_p_path);
10381 	    break;
10382 	case PV_AR:
10383 	    buf->b_p_ar = -1;
10384 	    break;
10385 	case PV_BKC:
10386 	    clear_string_option(&buf->b_p_bkc);
10387 	    buf->b_bkc_flags = 0;
10388 	    break;
10389 	case PV_TAGS:
10390 	    clear_string_option(&buf->b_p_tags);
10391 	    break;
10392 	case PV_TC:
10393 	    clear_string_option(&buf->b_p_tc);
10394 	    buf->b_tc_flags = 0;
10395 	    break;
10396 #ifdef FEAT_FIND_ID
10397 	case PV_DEF:
10398 	    clear_string_option(&buf->b_p_def);
10399 	    break;
10400 	case PV_INC:
10401 	    clear_string_option(&buf->b_p_inc);
10402 	    break;
10403 #endif
10404 #ifdef FEAT_INS_EXPAND
10405 	case PV_DICT:
10406 	    clear_string_option(&buf->b_p_dict);
10407 	    break;
10408 	case PV_TSR:
10409 	    clear_string_option(&buf->b_p_tsr);
10410 	    break;
10411 #endif
10412 	case PV_FP:
10413 	    clear_string_option(&buf->b_p_fp);
10414 	    break;
10415 #ifdef FEAT_QUICKFIX
10416 	case PV_EFM:
10417 	    clear_string_option(&buf->b_p_efm);
10418 	    break;
10419 	case PV_GP:
10420 	    clear_string_option(&buf->b_p_gp);
10421 	    break;
10422 	case PV_MP:
10423 	    clear_string_option(&buf->b_p_mp);
10424 	    break;
10425 #endif
10426 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10427 	case PV_BEXPR:
10428 	    clear_string_option(&buf->b_p_bexpr);
10429 	    break;
10430 #endif
10431 #if defined(FEAT_CRYPT)
10432 	case PV_CM:
10433 	    clear_string_option(&buf->b_p_cm);
10434 	    break;
10435 #endif
10436 #ifdef FEAT_STL_OPT
10437 	case PV_STL:
10438 	    clear_string_option(&((win_T *)from)->w_p_stl);
10439 	    break;
10440 #endif
10441 	case PV_UL:
10442 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10443 	    break;
10444 #ifdef FEAT_LISP
10445 	case PV_LW:
10446 	    clear_string_option(&buf->b_p_lw);
10447 	    break;
10448 #endif
10449 #ifdef FEAT_MBYTE
10450 	case PV_MENC:
10451 	    clear_string_option(&buf->b_p_menc);
10452 	    break;
10453 #endif
10454     }
10455 }
10456 
10457 /*
10458  * Get pointer to option variable, depending on local or global scope.
10459  */
10460     static char_u *
10461 get_varp_scope(struct vimoption *p, int opt_flags)
10462 {
10463     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10464     {
10465 	if (p->var == VAR_WIN)
10466 	    return (char_u *)GLOBAL_WO(get_varp(p));
10467 	return p->var;
10468     }
10469     if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
10470     {
10471 	switch ((int)p->indir)
10472 	{
10473 	    case PV_FP:   return (char_u *)&(curbuf->b_p_fp);
10474 #ifdef FEAT_QUICKFIX
10475 	    case PV_EFM:  return (char_u *)&(curbuf->b_p_efm);
10476 	    case PV_GP:   return (char_u *)&(curbuf->b_p_gp);
10477 	    case PV_MP:   return (char_u *)&(curbuf->b_p_mp);
10478 #endif
10479 	    case PV_EP:   return (char_u *)&(curbuf->b_p_ep);
10480 	    case PV_KP:   return (char_u *)&(curbuf->b_p_kp);
10481 	    case PV_PATH: return (char_u *)&(curbuf->b_p_path);
10482 	    case PV_AR:   return (char_u *)&(curbuf->b_p_ar);
10483 	    case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
10484 	    case PV_TC:   return (char_u *)&(curbuf->b_p_tc);
10485 #ifdef FEAT_FIND_ID
10486 	    case PV_DEF:  return (char_u *)&(curbuf->b_p_def);
10487 	    case PV_INC:  return (char_u *)&(curbuf->b_p_inc);
10488 #endif
10489 #ifdef FEAT_INS_EXPAND
10490 	    case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10491 	    case PV_TSR:  return (char_u *)&(curbuf->b_p_tsr);
10492 #endif
10493 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10494 	    case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10495 #endif
10496 #if defined(FEAT_CRYPT)
10497 	    case PV_CM:	  return (char_u *)&(curbuf->b_p_cm);
10498 #endif
10499 #ifdef FEAT_STL_OPT
10500 	    case PV_STL:  return (char_u *)&(curwin->w_p_stl);
10501 #endif
10502 	    case PV_UL:   return (char_u *)&(curbuf->b_p_ul);
10503 #ifdef FEAT_LISP
10504 	    case PV_LW:   return (char_u *)&(curbuf->b_p_lw);
10505 #endif
10506 	    case PV_BKC:  return (char_u *)&(curbuf->b_p_bkc);
10507 #ifdef FEAT_MBYTE
10508 	    case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10509 #endif
10510 	}
10511 	return NULL; /* "cannot happen" */
10512     }
10513     return get_varp(p);
10514 }
10515 
10516 /*
10517  * Get pointer to option variable.
10518  */
10519     static char_u *
10520 get_varp(struct vimoption *p)
10521 {
10522     /* hidden option, always return NULL */
10523     if (p->var == NULL)
10524 	return NULL;
10525 
10526     switch ((int)p->indir)
10527     {
10528 	case PV_NONE:	return p->var;
10529 
10530 	/* global option with local value: use local value if it's been set */
10531 	case PV_EP:	return *curbuf->b_p_ep != NUL
10532 				    ? (char_u *)&curbuf->b_p_ep : p->var;
10533 	case PV_KP:	return *curbuf->b_p_kp != NUL
10534 				    ? (char_u *)&curbuf->b_p_kp : p->var;
10535 	case PV_PATH:	return *curbuf->b_p_path != NUL
10536 				    ? (char_u *)&(curbuf->b_p_path) : p->var;
10537 	case PV_AR:	return curbuf->b_p_ar >= 0
10538 				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
10539 	case PV_TAGS:	return *curbuf->b_p_tags != NUL
10540 				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
10541 	case PV_TC:	return *curbuf->b_p_tc != NUL
10542 				    ? (char_u *)&(curbuf->b_p_tc) : p->var;
10543 	case PV_BKC:	return *curbuf->b_p_bkc != NUL
10544 				    ? (char_u *)&(curbuf->b_p_bkc) : p->var;
10545 #ifdef FEAT_FIND_ID
10546 	case PV_DEF:	return *curbuf->b_p_def != NUL
10547 				    ? (char_u *)&(curbuf->b_p_def) : p->var;
10548 	case PV_INC:	return *curbuf->b_p_inc != NUL
10549 				    ? (char_u *)&(curbuf->b_p_inc) : p->var;
10550 #endif
10551 #ifdef FEAT_INS_EXPAND
10552 	case PV_DICT:	return *curbuf->b_p_dict != NUL
10553 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
10554 	case PV_TSR:	return *curbuf->b_p_tsr != NUL
10555 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10556 #endif
10557 	case PV_FP:	return *curbuf->b_p_fp != NUL
10558 				    ? (char_u *)&(curbuf->b_p_fp) : p->var;
10559 #ifdef FEAT_QUICKFIX
10560 	case PV_EFM:	return *curbuf->b_p_efm != NUL
10561 				    ? (char_u *)&(curbuf->b_p_efm) : p->var;
10562 	case PV_GP:	return *curbuf->b_p_gp != NUL
10563 				    ? (char_u *)&(curbuf->b_p_gp) : p->var;
10564 	case PV_MP:	return *curbuf->b_p_mp != NUL
10565 				    ? (char_u *)&(curbuf->b_p_mp) : p->var;
10566 #endif
10567 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10568 	case PV_BEXPR:	return *curbuf->b_p_bexpr != NUL
10569 				    ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10570 #endif
10571 #if defined(FEAT_CRYPT)
10572 	case PV_CM:	return *curbuf->b_p_cm != NUL
10573 				    ? (char_u *)&(curbuf->b_p_cm) : p->var;
10574 #endif
10575 #ifdef FEAT_STL_OPT
10576 	case PV_STL:	return *curwin->w_p_stl != NUL
10577 				    ? (char_u *)&(curwin->w_p_stl) : p->var;
10578 #endif
10579 	case PV_UL:	return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10580 				    ? (char_u *)&(curbuf->b_p_ul) : p->var;
10581 #ifdef FEAT_LISP
10582 	case PV_LW:	return *curbuf->b_p_lw != NUL
10583 				    ? (char_u *)&(curbuf->b_p_lw) : p->var;
10584 #endif
10585 #ifdef FEAT_MBYTE
10586 	case PV_MENC:	return *curbuf->b_p_menc != NUL
10587 				    ? (char_u *)&(curbuf->b_p_menc) : p->var;
10588 #endif
10589 
10590 #ifdef FEAT_ARABIC
10591 	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
10592 #endif
10593 	case PV_LIST:	return (char_u *)&(curwin->w_p_list);
10594 #ifdef FEAT_SPELL
10595 	case PV_SPELL:	return (char_u *)&(curwin->w_p_spell);
10596 #endif
10597 #ifdef FEAT_SYN_HL
10598 	case PV_CUC:	return (char_u *)&(curwin->w_p_cuc);
10599 	case PV_CUL:	return (char_u *)&(curwin->w_p_cul);
10600 	case PV_CC:	return (char_u *)&(curwin->w_p_cc);
10601 #endif
10602 #ifdef FEAT_DIFF
10603 	case PV_DIFF:	return (char_u *)&(curwin->w_p_diff);
10604 #endif
10605 #ifdef FEAT_FOLDING
10606 	case PV_FDC:	return (char_u *)&(curwin->w_p_fdc);
10607 	case PV_FEN:	return (char_u *)&(curwin->w_p_fen);
10608 	case PV_FDI:	return (char_u *)&(curwin->w_p_fdi);
10609 	case PV_FDL:	return (char_u *)&(curwin->w_p_fdl);
10610 	case PV_FDM:	return (char_u *)&(curwin->w_p_fdm);
10611 	case PV_FML:	return (char_u *)&(curwin->w_p_fml);
10612 	case PV_FDN:	return (char_u *)&(curwin->w_p_fdn);
10613 # ifdef FEAT_EVAL
10614 	case PV_FDE:	return (char_u *)&(curwin->w_p_fde);
10615 	case PV_FDT:	return (char_u *)&(curwin->w_p_fdt);
10616 # endif
10617 	case PV_FMR:	return (char_u *)&(curwin->w_p_fmr);
10618 #endif
10619 	case PV_NU:	return (char_u *)&(curwin->w_p_nu);
10620 	case PV_RNU:	return (char_u *)&(curwin->w_p_rnu);
10621 #ifdef FEAT_LINEBREAK
10622 	case PV_NUW:	return (char_u *)&(curwin->w_p_nuw);
10623 #endif
10624 	case PV_WFH:	return (char_u *)&(curwin->w_p_wfh);
10625 	case PV_WFW:	return (char_u *)&(curwin->w_p_wfw);
10626 #if defined(FEAT_QUICKFIX)
10627 	case PV_PVW:	return (char_u *)&(curwin->w_p_pvw);
10628 #endif
10629 #ifdef FEAT_RIGHTLEFT
10630 	case PV_RL:	return (char_u *)&(curwin->w_p_rl);
10631 	case PV_RLC:	return (char_u *)&(curwin->w_p_rlc);
10632 #endif
10633 	case PV_SCROLL:	return (char_u *)&(curwin->w_p_scr);
10634 	case PV_WRAP:	return (char_u *)&(curwin->w_p_wrap);
10635 #ifdef FEAT_LINEBREAK
10636 	case PV_LBR:	return (char_u *)&(curwin->w_p_lbr);
10637 	case PV_BRI:	return (char_u *)&(curwin->w_p_bri);
10638 	case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
10639 #endif
10640 #ifdef FEAT_SCROLLBIND
10641 	case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10642 #endif
10643 #ifdef FEAT_CURSORBIND
10644 	case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10645 #endif
10646 #ifdef FEAT_CONCEAL
10647 	case PV_COCU:   return (char_u *)&(curwin->w_p_cocu);
10648 	case PV_COLE:   return (char_u *)&(curwin->w_p_cole);
10649 #endif
10650 #ifdef FEAT_TERMINAL
10651 	case PV_TK:     return (char_u *)&(curwin->w_p_tk);
10652 	case PV_TMS:    return (char_u *)&(curwin->w_p_tms);
10653 #endif
10654 
10655 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
10656 	case PV_BIN:	return (char_u *)&(curbuf->b_p_bin);
10657 #ifdef FEAT_MBYTE
10658 	case PV_BOMB:	return (char_u *)&(curbuf->b_p_bomb);
10659 #endif
10660 	case PV_BH:	return (char_u *)&(curbuf->b_p_bh);
10661 	case PV_BT:	return (char_u *)&(curbuf->b_p_bt);
10662 	case PV_BL:	return (char_u *)&(curbuf->b_p_bl);
10663 	case PV_CI:	return (char_u *)&(curbuf->b_p_ci);
10664 #ifdef FEAT_CINDENT
10665 	case PV_CIN:	return (char_u *)&(curbuf->b_p_cin);
10666 	case PV_CINK:	return (char_u *)&(curbuf->b_p_cink);
10667 	case PV_CINO:	return (char_u *)&(curbuf->b_p_cino);
10668 #endif
10669 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10670 	case PV_CINW:	return (char_u *)&(curbuf->b_p_cinw);
10671 #endif
10672 #ifdef FEAT_COMMENTS
10673 	case PV_COM:	return (char_u *)&(curbuf->b_p_com);
10674 #endif
10675 #ifdef FEAT_FOLDING
10676 	case PV_CMS:	return (char_u *)&(curbuf->b_p_cms);
10677 #endif
10678 #ifdef FEAT_INS_EXPAND
10679 	case PV_CPT:	return (char_u *)&(curbuf->b_p_cpt);
10680 #endif
10681 #ifdef FEAT_COMPL_FUNC
10682 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
10683 	case PV_OFU:	return (char_u *)&(curbuf->b_p_ofu);
10684 #endif
10685 	case PV_EOL:	return (char_u *)&(curbuf->b_p_eol);
10686 	case PV_FIXEOL:	return (char_u *)&(curbuf->b_p_fixeol);
10687 	case PV_ET:	return (char_u *)&(curbuf->b_p_et);
10688 #ifdef FEAT_MBYTE
10689 	case PV_FENC:	return (char_u *)&(curbuf->b_p_fenc);
10690 #endif
10691 	case PV_FF:	return (char_u *)&(curbuf->b_p_ff);
10692 #ifdef FEAT_AUTOCMD
10693 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
10694 #endif
10695 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
10696 	case PV_FLP:	return (char_u *)&(curbuf->b_p_flp);
10697 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
10698 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
10699 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
10700 	case PV_ISK:	return (char_u *)&(curbuf->b_p_isk);
10701 #ifdef FEAT_FIND_ID
10702 # ifdef FEAT_EVAL
10703 	case PV_INEX:	return (char_u *)&(curbuf->b_p_inex);
10704 # endif
10705 #endif
10706 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10707 	case PV_INDE:	return (char_u *)&(curbuf->b_p_inde);
10708 	case PV_INDK:	return (char_u *)&(curbuf->b_p_indk);
10709 #endif
10710 #ifdef FEAT_EVAL
10711 	case PV_FEX:	return (char_u *)&(curbuf->b_p_fex);
10712 #endif
10713 #ifdef FEAT_CRYPT
10714 	case PV_KEY:	return (char_u *)&(curbuf->b_p_key);
10715 #endif
10716 #ifdef FEAT_LISP
10717 	case PV_LISP:	return (char_u *)&(curbuf->b_p_lisp);
10718 #endif
10719 	case PV_ML:	return (char_u *)&(curbuf->b_p_ml);
10720 	case PV_MPS:	return (char_u *)&(curbuf->b_p_mps);
10721 	case PV_MA:	return (char_u *)&(curbuf->b_p_ma);
10722 	case PV_MOD:	return (char_u *)&(curbuf->b_changed);
10723 	case PV_NF:	return (char_u *)&(curbuf->b_p_nf);
10724 	case PV_PI:	return (char_u *)&(curbuf->b_p_pi);
10725 #ifdef FEAT_TEXTOBJ
10726 	case PV_QE:	return (char_u *)&(curbuf->b_p_qe);
10727 #endif
10728 	case PV_RO:	return (char_u *)&(curbuf->b_p_ro);
10729 #ifdef FEAT_SMARTINDENT
10730 	case PV_SI:	return (char_u *)&(curbuf->b_p_si);
10731 #endif
10732 	case PV_SN:	return (char_u *)&(curbuf->b_p_sn);
10733 	case PV_STS:	return (char_u *)&(curbuf->b_p_sts);
10734 #ifdef FEAT_SEARCHPATH
10735 	case PV_SUA:	return (char_u *)&(curbuf->b_p_sua);
10736 #endif
10737 	case PV_SWF:	return (char_u *)&(curbuf->b_p_swf);
10738 #ifdef FEAT_SYN_HL
10739 	case PV_SMC:	return (char_u *)&(curbuf->b_p_smc);
10740 	case PV_SYN:	return (char_u *)&(curbuf->b_p_syn);
10741 #endif
10742 #ifdef FEAT_SPELL
10743 	case PV_SPC:	return (char_u *)&(curwin->w_s->b_p_spc);
10744 	case PV_SPF:	return (char_u *)&(curwin->w_s->b_p_spf);
10745 	case PV_SPL:	return (char_u *)&(curwin->w_s->b_p_spl);
10746 #endif
10747 	case PV_SW:	return (char_u *)&(curbuf->b_p_sw);
10748 	case PV_TS:	return (char_u *)&(curbuf->b_p_ts);
10749 	case PV_TW:	return (char_u *)&(curbuf->b_p_tw);
10750 	case PV_TX:	return (char_u *)&(curbuf->b_p_tx);
10751 #ifdef FEAT_PERSISTENT_UNDO
10752 	case PV_UDF:	return (char_u *)&(curbuf->b_p_udf);
10753 #endif
10754 	case PV_WM:	return (char_u *)&(curbuf->b_p_wm);
10755 #ifdef FEAT_KEYMAP
10756 	case PV_KMAP:	return (char_u *)&(curbuf->b_p_keymap);
10757 #endif
10758 #ifdef FEAT_SIGNS
10759 	case PV_SCL:	return (char_u *)&(curwin->w_p_scl);
10760 #endif
10761 	default:	IEMSG(_("E356: get_varp ERROR"));
10762     }
10763     /* always return a valid pointer to avoid a crash! */
10764     return (char_u *)&(curbuf->b_p_wm);
10765 }
10766 
10767 /*
10768  * Get the value of 'equalprg', either the buffer-local one or the global one.
10769  */
10770     char_u *
10771 get_equalprg(void)
10772 {
10773     if (*curbuf->b_p_ep == NUL)
10774 	return p_ep;
10775     return curbuf->b_p_ep;
10776 }
10777 
10778 /*
10779  * Copy options from one window to another.
10780  * Used when splitting a window.
10781  */
10782     void
10783 win_copy_options(win_T *wp_from, win_T *wp_to)
10784 {
10785     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10786     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10787 # ifdef FEAT_RIGHTLEFT
10788 #  ifdef FEAT_FKMAP
10789     /* Is this right? */
10790     wp_to->w_farsi = wp_from->w_farsi;
10791 #  endif
10792 # endif
10793 #if defined(FEAT_LINEBREAK)
10794     briopt_check(wp_to);
10795 #endif
10796 }
10797 
10798 /*
10799  * Copy the options from one winopt_T to another.
10800  * Doesn't free the old option values in "to", use clear_winopt() for that.
10801  * The 'scroll' option is not copied, because it depends on the window height.
10802  * The 'previewwindow' option is reset, there can be only one preview window.
10803  */
10804     void
10805 copy_winopt(winopt_T *from, winopt_T *to)
10806 {
10807 #ifdef FEAT_ARABIC
10808     to->wo_arab = from->wo_arab;
10809 #endif
10810     to->wo_list = from->wo_list;
10811     to->wo_nu = from->wo_nu;
10812     to->wo_rnu = from->wo_rnu;
10813 #ifdef FEAT_LINEBREAK
10814     to->wo_nuw = from->wo_nuw;
10815 #endif
10816 #ifdef FEAT_RIGHTLEFT
10817     to->wo_rl  = from->wo_rl;
10818     to->wo_rlc = vim_strsave(from->wo_rlc);
10819 #endif
10820 #ifdef FEAT_STL_OPT
10821     to->wo_stl = vim_strsave(from->wo_stl);
10822 #endif
10823     to->wo_wrap = from->wo_wrap;
10824 #ifdef FEAT_DIFF
10825     to->wo_wrap_save = from->wo_wrap_save;
10826 #endif
10827 #ifdef FEAT_LINEBREAK
10828     to->wo_lbr = from->wo_lbr;
10829     to->wo_bri = from->wo_bri;
10830     to->wo_briopt = vim_strsave(from->wo_briopt);
10831 #endif
10832 #ifdef FEAT_SCROLLBIND
10833     to->wo_scb = from->wo_scb;
10834     to->wo_scb_save = from->wo_scb_save;
10835 #endif
10836 #ifdef FEAT_CURSORBIND
10837     to->wo_crb = from->wo_crb;
10838     to->wo_crb_save = from->wo_crb_save;
10839 #endif
10840 #ifdef FEAT_SPELL
10841     to->wo_spell = from->wo_spell;
10842 #endif
10843 #ifdef FEAT_SYN_HL
10844     to->wo_cuc = from->wo_cuc;
10845     to->wo_cul = from->wo_cul;
10846     to->wo_cc = vim_strsave(from->wo_cc);
10847 #endif
10848 #ifdef FEAT_DIFF
10849     to->wo_diff = from->wo_diff;
10850     to->wo_diff_saved = from->wo_diff_saved;
10851 #endif
10852 #ifdef FEAT_CONCEAL
10853     to->wo_cocu = vim_strsave(from->wo_cocu);
10854     to->wo_cole = from->wo_cole;
10855 #endif
10856 #ifdef FEAT_TERMINAL
10857     to->wo_tk = vim_strsave(from->wo_tk);
10858     to->wo_tms = vim_strsave(from->wo_tms);
10859 #endif
10860 #ifdef FEAT_FOLDING
10861     to->wo_fdc = from->wo_fdc;
10862     to->wo_fdc_save = from->wo_fdc_save;
10863     to->wo_fen = from->wo_fen;
10864     to->wo_fen_save = from->wo_fen_save;
10865     to->wo_fdi = vim_strsave(from->wo_fdi);
10866     to->wo_fml = from->wo_fml;
10867     to->wo_fdl = from->wo_fdl;
10868     to->wo_fdl_save = from->wo_fdl_save;
10869     to->wo_fdm = vim_strsave(from->wo_fdm);
10870     to->wo_fdm_save = from->wo_diff_saved
10871 			      ? vim_strsave(from->wo_fdm_save) : empty_option;
10872     to->wo_fdn = from->wo_fdn;
10873 # ifdef FEAT_EVAL
10874     to->wo_fde = vim_strsave(from->wo_fde);
10875     to->wo_fdt = vim_strsave(from->wo_fdt);
10876 # endif
10877     to->wo_fmr = vim_strsave(from->wo_fmr);
10878 #endif
10879 #ifdef FEAT_SIGNS
10880     to->wo_scl = vim_strsave(from->wo_scl);
10881 #endif
10882     check_winopt(to);		/* don't want NULL pointers */
10883 }
10884 
10885 /*
10886  * Check string options in a window for a NULL value.
10887  */
10888     void
10889 check_win_options(win_T *win)
10890 {
10891     check_winopt(&win->w_onebuf_opt);
10892     check_winopt(&win->w_allbuf_opt);
10893 }
10894 
10895 /*
10896  * Check for NULL pointers in a winopt_T and replace them with empty_option.
10897  */
10898     static void
10899 check_winopt(winopt_T *wop UNUSED)
10900 {
10901 #ifdef FEAT_FOLDING
10902     check_string_option(&wop->wo_fdi);
10903     check_string_option(&wop->wo_fdm);
10904     check_string_option(&wop->wo_fdm_save);
10905 # ifdef FEAT_EVAL
10906     check_string_option(&wop->wo_fde);
10907     check_string_option(&wop->wo_fdt);
10908 # endif
10909     check_string_option(&wop->wo_fmr);
10910 #endif
10911 #ifdef FEAT_SIGNS
10912     check_string_option(&wop->wo_scl);
10913 #endif
10914 #ifdef FEAT_RIGHTLEFT
10915     check_string_option(&wop->wo_rlc);
10916 #endif
10917 #ifdef FEAT_STL_OPT
10918     check_string_option(&wop->wo_stl);
10919 #endif
10920 #ifdef FEAT_SYN_HL
10921     check_string_option(&wop->wo_cc);
10922 #endif
10923 #ifdef FEAT_CONCEAL
10924     check_string_option(&wop->wo_cocu);
10925 #endif
10926 #ifdef FEAT_TERMINAL
10927     check_string_option(&wop->wo_tk);
10928     check_string_option(&wop->wo_tms);
10929 #endif
10930 #ifdef FEAT_LINEBREAK
10931     check_string_option(&wop->wo_briopt);
10932 #endif
10933 }
10934 
10935 /*
10936  * Free the allocated memory inside a winopt_T.
10937  */
10938     void
10939 clear_winopt(winopt_T *wop UNUSED)
10940 {
10941 #ifdef FEAT_FOLDING
10942     clear_string_option(&wop->wo_fdi);
10943     clear_string_option(&wop->wo_fdm);
10944     clear_string_option(&wop->wo_fdm_save);
10945 # ifdef FEAT_EVAL
10946     clear_string_option(&wop->wo_fde);
10947     clear_string_option(&wop->wo_fdt);
10948 # endif
10949     clear_string_option(&wop->wo_fmr);
10950 #endif
10951 #ifdef FEAT_SIGNS
10952     clear_string_option(&wop->wo_scl);
10953 #endif
10954 #ifdef FEAT_LINEBREAK
10955     clear_string_option(&wop->wo_briopt);
10956 #endif
10957 #ifdef FEAT_RIGHTLEFT
10958     clear_string_option(&wop->wo_rlc);
10959 #endif
10960 #ifdef FEAT_STL_OPT
10961     clear_string_option(&wop->wo_stl);
10962 #endif
10963 #ifdef FEAT_SYN_HL
10964     clear_string_option(&wop->wo_cc);
10965 #endif
10966 #ifdef FEAT_CONCEAL
10967     clear_string_option(&wop->wo_cocu);
10968 #endif
10969 #ifdef FEAT_TERMINAL
10970     clear_string_option(&wop->wo_tk);
10971     clear_string_option(&wop->wo_tms);
10972 #endif
10973 }
10974 
10975 /*
10976  * Copy global option values to local options for one buffer.
10977  * Used when creating a new buffer and sometimes when entering a buffer.
10978  * flags:
10979  * BCO_ENTER	We will enter the buf buffer.
10980  * BCO_ALWAYS	Always copy the options, but only set b_p_initialized when
10981  *		appropriate.
10982  * BCO_NOHELP	Don't copy the values to a help buffer.
10983  */
10984     void
10985 buf_copy_options(buf_T *buf, int flags)
10986 {
10987     int		should_copy = TRUE;
10988     char_u	*save_p_isk = NULL;	    /* init for GCC */
10989     int		dont_do_help;
10990     int		did_isk = FALSE;
10991 
10992     /*
10993      * Skip this when the option defaults have not been set yet.  Happens when
10994      * main() allocates the first buffer.
10995      */
10996     if (p_cpo != NULL)
10997     {
10998 	/*
10999 	 * Always copy when entering and 'cpo' contains 'S'.
11000 	 * Don't copy when already initialized.
11001 	 * Don't copy when 'cpo' contains 's' and not entering.
11002 	 * 'S'	BCO_ENTER  initialized	's'  should_copy
11003 	 * yes	  yes	       X	 X	TRUE
11004 	 * yes	  no	      yes	 X	FALSE
11005 	 * no	   X	      yes	 X	FALSE
11006 	 *  X	  no	      no	yes	FALSE
11007 	 *  X	  no	      no	no	TRUE
11008 	 * no	  yes	      no	 X	TRUE
11009 	 */
11010 	if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11011 		&& (buf->b_p_initialized
11012 		    || (!(flags & BCO_ENTER)
11013 			&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11014 	    should_copy = FALSE;
11015 
11016 	if (should_copy || (flags & BCO_ALWAYS))
11017 	{
11018 	    /* Don't copy the options specific to a help buffer when
11019 	     * BCO_NOHELP is given or the options were initialized already
11020 	     * (jumping back to a help file with CTRL-T or CTRL-O) */
11021 	    dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11022 						       || buf->b_p_initialized;
11023 	    if (dont_do_help)		/* don't free b_p_isk */
11024 	    {
11025 		save_p_isk = buf->b_p_isk;
11026 		buf->b_p_isk = NULL;
11027 	    }
11028 	    /*
11029 	     * Always free the allocated strings.
11030 	     * If not already initialized, set 'readonly' and copy 'fileformat'.
11031 	     */
11032 	    if (!buf->b_p_initialized)
11033 	    {
11034 		free_buf_options(buf, TRUE);
11035 		buf->b_p_ro = FALSE;		/* don't copy readonly */
11036 		buf->b_p_tx = p_tx;
11037 #ifdef FEAT_MBYTE
11038 		buf->b_p_fenc = vim_strsave(p_fenc);
11039 #endif
11040 		switch (*p_ffs)
11041 		{
11042 		    case 'm':
11043 			buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11044 		    case 'd':
11045 			buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11046 		    case 'u':
11047 			buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11048 		    default:
11049 			buf->b_p_ff = vim_strsave(p_ff);
11050 		}
11051 		if (buf->b_p_ff != NULL)
11052 		    buf->b_start_ffc = *buf->b_p_ff;
11053 		buf->b_p_bh = empty_option;
11054 		buf->b_p_bt = empty_option;
11055 	    }
11056 	    else
11057 		free_buf_options(buf, FALSE);
11058 
11059 	    buf->b_p_ai = p_ai;
11060 	    buf->b_p_ai_nopaste = p_ai_nopaste;
11061 	    buf->b_p_sw = p_sw;
11062 	    buf->b_p_tw = p_tw;
11063 	    buf->b_p_tw_nopaste = p_tw_nopaste;
11064 	    buf->b_p_tw_nobin = p_tw_nobin;
11065 	    buf->b_p_wm = p_wm;
11066 	    buf->b_p_wm_nopaste = p_wm_nopaste;
11067 	    buf->b_p_wm_nobin = p_wm_nobin;
11068 	    buf->b_p_bin = p_bin;
11069 #ifdef FEAT_MBYTE
11070 	    buf->b_p_bomb = p_bomb;
11071 #endif
11072 	    buf->b_p_fixeol = p_fixeol;
11073 	    buf->b_p_et = p_et;
11074 	    buf->b_p_et_nobin = p_et_nobin;
11075 	    buf->b_p_et_nopaste = p_et_nopaste;
11076 	    buf->b_p_ml = p_ml;
11077 	    buf->b_p_ml_nobin = p_ml_nobin;
11078 	    buf->b_p_inf = p_inf;
11079 	    buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
11080 #ifdef FEAT_INS_EXPAND
11081 	    buf->b_p_cpt = vim_strsave(p_cpt);
11082 #endif
11083 #ifdef FEAT_COMPL_FUNC
11084 	    buf->b_p_cfu = vim_strsave(p_cfu);
11085 	    buf->b_p_ofu = vim_strsave(p_ofu);
11086 #endif
11087 	    buf->b_p_sts = p_sts;
11088 	    buf->b_p_sts_nopaste = p_sts_nopaste;
11089 	    buf->b_p_sn = p_sn;
11090 #ifdef FEAT_COMMENTS
11091 	    buf->b_p_com = vim_strsave(p_com);
11092 #endif
11093 #ifdef FEAT_FOLDING
11094 	    buf->b_p_cms = vim_strsave(p_cms);
11095 #endif
11096 	    buf->b_p_fo = vim_strsave(p_fo);
11097 	    buf->b_p_flp = vim_strsave(p_flp);
11098 	    buf->b_p_nf = vim_strsave(p_nf);
11099 	    buf->b_p_mps = vim_strsave(p_mps);
11100 #ifdef FEAT_SMARTINDENT
11101 	    buf->b_p_si = p_si;
11102 #endif
11103 	    buf->b_p_ci = p_ci;
11104 #ifdef FEAT_CINDENT
11105 	    buf->b_p_cin = p_cin;
11106 	    buf->b_p_cink = vim_strsave(p_cink);
11107 	    buf->b_p_cino = vim_strsave(p_cino);
11108 #endif
11109 #ifdef FEAT_AUTOCMD
11110 	    /* Don't copy 'filetype', it must be detected */
11111 	    buf->b_p_ft = empty_option;
11112 #endif
11113 	    buf->b_p_pi = p_pi;
11114 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11115 	    buf->b_p_cinw = vim_strsave(p_cinw);
11116 #endif
11117 #ifdef FEAT_LISP
11118 	    buf->b_p_lisp = p_lisp;
11119 #endif
11120 #ifdef FEAT_SYN_HL
11121 	    /* Don't copy 'syntax', it must be set */
11122 	    buf->b_p_syn = empty_option;
11123 	    buf->b_p_smc = p_smc;
11124 	    buf->b_s.b_syn_isk = empty_option;
11125 #endif
11126 #ifdef FEAT_SPELL
11127 	    buf->b_s.b_p_spc = vim_strsave(p_spc);
11128 	    (void)compile_cap_prog(&buf->b_s);
11129 	    buf->b_s.b_p_spf = vim_strsave(p_spf);
11130 	    buf->b_s.b_p_spl = vim_strsave(p_spl);
11131 #endif
11132 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11133 	    buf->b_p_inde = vim_strsave(p_inde);
11134 	    buf->b_p_indk = vim_strsave(p_indk);
11135 #endif
11136 	    buf->b_p_fp = empty_option;
11137 #if defined(FEAT_EVAL)
11138 	    buf->b_p_fex = vim_strsave(p_fex);
11139 #endif
11140 #ifdef FEAT_CRYPT
11141 	    buf->b_p_key = vim_strsave(p_key);
11142 #endif
11143 #ifdef FEAT_SEARCHPATH
11144 	    buf->b_p_sua = vim_strsave(p_sua);
11145 #endif
11146 #ifdef FEAT_KEYMAP
11147 	    buf->b_p_keymap = vim_strsave(p_keymap);
11148 	    buf->b_kmap_state |= KEYMAP_INIT;
11149 #endif
11150 	    /* This isn't really an option, but copying the langmap and IME
11151 	     * state from the current buffer is better than resetting it. */
11152 	    buf->b_p_iminsert = p_iminsert;
11153 	    buf->b_p_imsearch = p_imsearch;
11154 
11155 	    /* options that are normally global but also have a local value
11156 	     * are not copied, start using the global value */
11157 	    buf->b_p_ar = -1;
11158 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11159 	    buf->b_p_bkc = empty_option;
11160 	    buf->b_bkc_flags = 0;
11161 #ifdef FEAT_QUICKFIX
11162 	    buf->b_p_gp = empty_option;
11163 	    buf->b_p_mp = empty_option;
11164 	    buf->b_p_efm = empty_option;
11165 #endif
11166 	    buf->b_p_ep = empty_option;
11167 	    buf->b_p_kp = empty_option;
11168 	    buf->b_p_path = empty_option;
11169 	    buf->b_p_tags = empty_option;
11170 	    buf->b_p_tc = empty_option;
11171 	    buf->b_tc_flags = 0;
11172 #ifdef FEAT_FIND_ID
11173 	    buf->b_p_def = empty_option;
11174 	    buf->b_p_inc = empty_option;
11175 # ifdef FEAT_EVAL
11176 	    buf->b_p_inex = vim_strsave(p_inex);
11177 # endif
11178 #endif
11179 #ifdef FEAT_INS_EXPAND
11180 	    buf->b_p_dict = empty_option;
11181 	    buf->b_p_tsr = empty_option;
11182 #endif
11183 #ifdef FEAT_TEXTOBJ
11184 	    buf->b_p_qe = vim_strsave(p_qe);
11185 #endif
11186 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11187 	    buf->b_p_bexpr = empty_option;
11188 #endif
11189 #if defined(FEAT_CRYPT)
11190 	    buf->b_p_cm = empty_option;
11191 #endif
11192 #ifdef FEAT_PERSISTENT_UNDO
11193 	    buf->b_p_udf = p_udf;
11194 #endif
11195 #ifdef FEAT_LISP
11196 	    buf->b_p_lw = empty_option;
11197 #endif
11198 #ifdef FEAT_MBYTE
11199 	    buf->b_p_menc = empty_option;
11200 #endif
11201 
11202 	    /*
11203 	     * Don't copy the options set by ex_help(), use the saved values,
11204 	     * when going from a help buffer to a non-help buffer.
11205 	     * Don't touch these at all when BCO_NOHELP is used and going from
11206 	     * or to a help buffer.
11207 	     */
11208 	    if (dont_do_help)
11209 		buf->b_p_isk = save_p_isk;
11210 	    else
11211 	    {
11212 		buf->b_p_isk = vim_strsave(p_isk);
11213 		did_isk = TRUE;
11214 		buf->b_p_ts = p_ts;
11215 		buf->b_help = FALSE;
11216 		if (buf->b_p_bt[0] == 'h')
11217 		    clear_string_option(&buf->b_p_bt);
11218 		buf->b_p_ma = p_ma;
11219 	    }
11220 	}
11221 
11222 	/*
11223 	 * When the options should be copied (ignoring BCO_ALWAYS), set the
11224 	 * flag that indicates that the options have been initialized.
11225 	 */
11226 	if (should_copy)
11227 	    buf->b_p_initialized = TRUE;
11228     }
11229 
11230     check_buf_options(buf);	    /* make sure we don't have NULLs */
11231     if (did_isk)
11232 	(void)buf_init_chartab(buf, FALSE);
11233 }
11234 
11235 /*
11236  * Reset the 'modifiable' option and its default value.
11237  */
11238     void
11239 reset_modifiable(void)
11240 {
11241     int		opt_idx;
11242 
11243     curbuf->b_p_ma = FALSE;
11244     p_ma = FALSE;
11245     opt_idx = findoption((char_u *)"ma");
11246     if (opt_idx >= 0)
11247 	options[opt_idx].def_val[VI_DEFAULT] = FALSE;
11248 }
11249 
11250 /*
11251  * Set the global value for 'iminsert' to the local value.
11252  */
11253     void
11254 set_iminsert_global(void)
11255 {
11256     p_iminsert = curbuf->b_p_iminsert;
11257 }
11258 
11259 /*
11260  * Set the global value for 'imsearch' to the local value.
11261  */
11262     void
11263 set_imsearch_global(void)
11264 {
11265     p_imsearch = curbuf->b_p_imsearch;
11266 }
11267 
11268 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11269 static int expand_option_idx = -1;
11270 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11271 static int expand_option_flags = 0;
11272 
11273     void
11274 set_context_in_set_cmd(
11275     expand_T	*xp,
11276     char_u	*arg,
11277     int		opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11278 {
11279     int		nextchar;
11280     long_u	flags = 0;	/* init for GCC */
11281     int		opt_idx = 0;	/* init for GCC */
11282     char_u	*p;
11283     char_u	*s;
11284     int		is_term_option = FALSE;
11285     int		key;
11286 
11287     expand_option_flags = opt_flags;
11288 
11289     xp->xp_context = EXPAND_SETTINGS;
11290     if (*arg == NUL)
11291     {
11292 	xp->xp_pattern = arg;
11293 	return;
11294     }
11295     p = arg + STRLEN(arg) - 1;
11296     if (*p == ' ' && *(p - 1) != '\\')
11297     {
11298 	xp->xp_pattern = p + 1;
11299 	return;
11300     }
11301     while (p > arg)
11302     {
11303 	s = p;
11304 	/* count number of backslashes before ' ' or ',' */
11305 	if (*p == ' ' || *p == ',')
11306 	{
11307 	    while (s > arg && *(s - 1) == '\\')
11308 		--s;
11309 	}
11310 	/* break at a space with an even number of backslashes */
11311 	if (*p == ' ' && ((p - s) & 1) == 0)
11312 	{
11313 	    ++p;
11314 	    break;
11315 	}
11316 	--p;
11317     }
11318     if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
11319     {
11320 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11321 	p += 2;
11322     }
11323     if (STRNCMP(p, "inv", 3) == 0)
11324     {
11325 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11326 	p += 3;
11327     }
11328     xp->xp_pattern = arg = p;
11329     if (*arg == '<')
11330     {
11331 	while (*p != '>')
11332 	    if (*p++ == NUL)	    /* expand terminal option name */
11333 		return;
11334 	key = get_special_key_code(arg + 1);
11335 	if (key == 0)		    /* unknown name */
11336 	{
11337 	    xp->xp_context = EXPAND_NOTHING;
11338 	    return;
11339 	}
11340 	nextchar = *++p;
11341 	is_term_option = TRUE;
11342 	expand_option_name[2] = KEY2TERMCAP0(key);
11343 	expand_option_name[3] = KEY2TERMCAP1(key);
11344     }
11345     else
11346     {
11347 	if (p[0] == 't' && p[1] == '_')
11348 	{
11349 	    p += 2;
11350 	    if (*p != NUL)
11351 		++p;
11352 	    if (*p == NUL)
11353 		return;		/* expand option name */
11354 	    nextchar = *++p;
11355 	    is_term_option = TRUE;
11356 	    expand_option_name[2] = p[-2];
11357 	    expand_option_name[3] = p[-1];
11358 	}
11359 	else
11360 	{
11361 		/* Allow * wildcard */
11362 	    while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11363 		p++;
11364 	    if (*p == NUL)
11365 		return;
11366 	    nextchar = *p;
11367 	    *p = NUL;
11368 	    opt_idx = findoption(arg);
11369 	    *p = nextchar;
11370 	    if (opt_idx == -1 || options[opt_idx].var == NULL)
11371 	    {
11372 		xp->xp_context = EXPAND_NOTHING;
11373 		return;
11374 	    }
11375 	    flags = options[opt_idx].flags;
11376 	    if (flags & P_BOOL)
11377 	    {
11378 		xp->xp_context = EXPAND_NOTHING;
11379 		return;
11380 	    }
11381 	}
11382     }
11383     /* handle "-=" and "+=" */
11384     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11385     {
11386 	++p;
11387 	nextchar = '=';
11388     }
11389     if ((nextchar != '=' && nextchar != ':')
11390 				    || xp->xp_context == EXPAND_BOOL_SETTINGS)
11391     {
11392 	xp->xp_context = EXPAND_UNSUCCESSFUL;
11393 	return;
11394     }
11395     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11396     {
11397 	xp->xp_context = EXPAND_OLD_SETTING;
11398 	if (is_term_option)
11399 	    expand_option_idx = -1;
11400 	else
11401 	    expand_option_idx = opt_idx;
11402 	xp->xp_pattern = p + 1;
11403 	return;
11404     }
11405     xp->xp_context = EXPAND_NOTHING;
11406     if (is_term_option || (flags & P_NUM))
11407 	return;
11408 
11409     xp->xp_pattern = p + 1;
11410 
11411     if (flags & P_EXPAND)
11412     {
11413 	p = options[opt_idx].var;
11414 	if (p == (char_u *)&p_bdir
11415 		|| p == (char_u *)&p_dir
11416 		|| p == (char_u *)&p_path
11417 		|| p == (char_u *)&p_pp
11418 		|| p == (char_u *)&p_rtp
11419 #ifdef FEAT_SEARCHPATH
11420 		|| p == (char_u *)&p_cdpath
11421 #endif
11422 #ifdef FEAT_SESSION
11423 		|| p == (char_u *)&p_vdir
11424 #endif
11425 		)
11426 	{
11427 	    xp->xp_context = EXPAND_DIRECTORIES;
11428 	    if (p == (char_u *)&p_path
11429 #ifdef FEAT_SEARCHPATH
11430 		    || p == (char_u *)&p_cdpath
11431 #endif
11432 		   )
11433 		xp->xp_backslash = XP_BS_THREE;
11434 	    else
11435 		xp->xp_backslash = XP_BS_ONE;
11436 	}
11437 	else
11438 	{
11439 	    xp->xp_context = EXPAND_FILES;
11440 	    /* for 'tags' need three backslashes for a space */
11441 	    if (p == (char_u *)&p_tags)
11442 		xp->xp_backslash = XP_BS_THREE;
11443 	    else
11444 		xp->xp_backslash = XP_BS_ONE;
11445 	}
11446     }
11447 
11448     /* For an option that is a list of file names, find the start of the
11449      * last file name. */
11450     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11451     {
11452 	/* count number of backslashes before ' ' or ',' */
11453 	if (*p == ' ' || *p == ',')
11454 	{
11455 	    s = p;
11456 	    while (s > xp->xp_pattern && *(s - 1) == '\\')
11457 		--s;
11458 	    if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11459 		    || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11460 	    {
11461 		xp->xp_pattern = p + 1;
11462 		break;
11463 	    }
11464 	}
11465 
11466 #ifdef FEAT_SPELL
11467 	/* for 'spellsuggest' start at "file:" */
11468 	if (options[opt_idx].var == (char_u *)&p_sps
11469 					       && STRNCMP(p, "file:", 5) == 0)
11470 	{
11471 	    xp->xp_pattern = p + 5;
11472 	    break;
11473 	}
11474 #endif
11475     }
11476 
11477     return;
11478 }
11479 
11480     int
11481 ExpandSettings(
11482     expand_T	*xp,
11483     regmatch_T	*regmatch,
11484     int		*num_file,
11485     char_u	***file)
11486 {
11487     int		num_normal = 0;	    /* Nr of matching non-term-code settings */
11488     int		num_term = 0;	    /* Nr of matching terminal code settings */
11489     int		opt_idx;
11490     int		match;
11491     int		count = 0;
11492     char_u	*str;
11493     int		loop;
11494     int		is_term_opt;
11495     char_u	name_buf[MAX_KEY_NAME_LEN];
11496     static char *(names[]) = {"all", "termcap"};
11497     int		ic = regmatch->rm_ic;	/* remember the ignore-case flag */
11498 
11499     /* do this loop twice:
11500      * loop == 0: count the number of matching options
11501      * loop == 1: copy the matching options into allocated memory
11502      */
11503     for (loop = 0; loop <= 1; ++loop)
11504     {
11505 	regmatch->rm_ic = ic;
11506 	if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11507 	{
11508 	    for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11509 								      ++match)
11510 		if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11511 		{
11512 		    if (loop == 0)
11513 			num_normal++;
11514 		    else
11515 			(*file)[count++] = vim_strsave((char_u *)names[match]);
11516 		}
11517 	}
11518 	for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11519 								    opt_idx++)
11520 	{
11521 	    if (options[opt_idx].var == NULL)
11522 		continue;
11523 	    if (xp->xp_context == EXPAND_BOOL_SETTINGS
11524 	      && !(options[opt_idx].flags & P_BOOL))
11525 		continue;
11526 	    is_term_opt = istermoption(&options[opt_idx]);
11527 	    if (is_term_opt && num_normal > 0)
11528 		continue;
11529 	    match = FALSE;
11530 	    if (vim_regexec(regmatch, str, (colnr_T)0)
11531 		    || (options[opt_idx].shortname != NULL
11532 			&& vim_regexec(regmatch,
11533 			   (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11534 		match = TRUE;
11535 	    else if (is_term_opt)
11536 	    {
11537 		name_buf[0] = '<';
11538 		name_buf[1] = 't';
11539 		name_buf[2] = '_';
11540 		name_buf[3] = str[2];
11541 		name_buf[4] = str[3];
11542 		name_buf[5] = '>';
11543 		name_buf[6] = NUL;
11544 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11545 		{
11546 		    match = TRUE;
11547 		    str = name_buf;
11548 		}
11549 	    }
11550 	    if (match)
11551 	    {
11552 		if (loop == 0)
11553 		{
11554 		    if (is_term_opt)
11555 			num_term++;
11556 		    else
11557 			num_normal++;
11558 		}
11559 		else
11560 		    (*file)[count++] = vim_strsave(str);
11561 	    }
11562 	}
11563 	/*
11564 	 * Check terminal key codes, these are not in the option table
11565 	 */
11566 	if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
11567 	{
11568 	    for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11569 	    {
11570 		if (!isprint(str[0]) || !isprint(str[1]))
11571 		    continue;
11572 
11573 		name_buf[0] = 't';
11574 		name_buf[1] = '_';
11575 		name_buf[2] = str[0];
11576 		name_buf[3] = str[1];
11577 		name_buf[4] = NUL;
11578 
11579 		match = FALSE;
11580 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11581 		    match = TRUE;
11582 		else
11583 		{
11584 		    name_buf[0] = '<';
11585 		    name_buf[1] = 't';
11586 		    name_buf[2] = '_';
11587 		    name_buf[3] = str[0];
11588 		    name_buf[4] = str[1];
11589 		    name_buf[5] = '>';
11590 		    name_buf[6] = NUL;
11591 
11592 		    if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11593 			match = TRUE;
11594 		}
11595 		if (match)
11596 		{
11597 		    if (loop == 0)
11598 			num_term++;
11599 		    else
11600 			(*file)[count++] = vim_strsave(name_buf);
11601 		}
11602 	    }
11603 
11604 	    /*
11605 	     * Check special key names.
11606 	     */
11607 	    regmatch->rm_ic = TRUE;		/* ignore case here */
11608 	    for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11609 	    {
11610 		name_buf[0] = '<';
11611 		STRCPY(name_buf + 1, str);
11612 		STRCAT(name_buf, ">");
11613 
11614 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11615 		{
11616 		    if (loop == 0)
11617 			num_term++;
11618 		    else
11619 			(*file)[count++] = vim_strsave(name_buf);
11620 		}
11621 	    }
11622 	}
11623 	if (loop == 0)
11624 	{
11625 	    if (num_normal > 0)
11626 		*num_file = num_normal;
11627 	    else if (num_term > 0)
11628 		*num_file = num_term;
11629 	    else
11630 		return OK;
11631 	    *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11632 	    if (*file == NULL)
11633 	    {
11634 		*file = (char_u **)"";
11635 		return FAIL;
11636 	    }
11637 	}
11638     }
11639     return OK;
11640 }
11641 
11642     int
11643 ExpandOldSetting(int *num_file, char_u ***file)
11644 {
11645     char_u  *var = NULL;	/* init for GCC */
11646     char_u  *buf;
11647 
11648     *num_file = 0;
11649     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11650     if (*file == NULL)
11651 	return FAIL;
11652 
11653     /*
11654      * For a terminal key code expand_option_idx is < 0.
11655      */
11656     if (expand_option_idx < 0)
11657     {
11658 	var = find_termcode(expand_option_name + 2);
11659 	if (var == NULL)
11660 	    expand_option_idx = findoption(expand_option_name);
11661     }
11662 
11663     if (expand_option_idx >= 0)
11664     {
11665 	/* put string of option value in NameBuff */
11666 	option_value2string(&options[expand_option_idx], expand_option_flags);
11667 	var = NameBuff;
11668     }
11669     else if (var == NULL)
11670 	var = (char_u *)"";
11671 
11672     /* A backslash is required before some characters.  This is the reverse of
11673      * what happens in do_set(). */
11674     buf = vim_strsave_escaped(var, escape_chars);
11675 
11676     if (buf == NULL)
11677     {
11678 	vim_free(*file);
11679 	*file = NULL;
11680 	return FAIL;
11681     }
11682 
11683 #ifdef BACKSLASH_IN_FILENAME
11684     /* For MS-Windows et al. we don't double backslashes at the start and
11685      * before a file name character. */
11686     for (var = buf; *var != NUL; MB_PTR_ADV(var))
11687 	if (var[0] == '\\' && var[1] == '\\'
11688 		&& expand_option_idx >= 0
11689 		&& (options[expand_option_idx].flags & P_EXPAND)
11690 		&& vim_isfilec(var[2])
11691 		&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
11692 	    STRMOVE(var, var + 1);
11693 #endif
11694 
11695     *file[0] = buf;
11696     *num_file = 1;
11697     return OK;
11698 }
11699 #endif
11700 
11701 /*
11702  * Get the value for the numeric or string option *opp in a nice format into
11703  * NameBuff[].  Must not be called with a hidden option!
11704  */
11705     static void
11706 option_value2string(
11707     struct vimoption	*opp,
11708     int			opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11709 {
11710     char_u	*varp;
11711 
11712     varp = get_varp_scope(opp, opt_flags);
11713 
11714     if (opp->flags & P_NUM)
11715     {
11716 	long wc = 0;
11717 
11718 	if (wc_use_keyname(varp, &wc))
11719 	    STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11720 	else if (wc != 0)
11721 	    STRCPY(NameBuff, transchar((int)wc));
11722 	else
11723 	    sprintf((char *)NameBuff, "%ld", *(long *)varp);
11724     }
11725     else    /* P_STRING */
11726     {
11727 	varp = *(char_u **)(varp);
11728 	if (varp == NULL)		    /* just in case */
11729 	    NameBuff[0] = NUL;
11730 #ifdef FEAT_CRYPT
11731 	/* don't show the actual value of 'key', only that it's set */
11732 	else if (opp->var == (char_u *)&p_key && *varp)
11733 	    STRCPY(NameBuff, "*****");
11734 #endif
11735 	else if (opp->flags & P_EXPAND)
11736 	    home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11737 	/* Translate 'pastetoggle' into special key names */
11738 	else if ((char_u **)opp->var == &p_pt)
11739 	    str2specialbuf(p_pt, NameBuff, MAXPATHL);
11740 	else
11741 	    vim_strncpy(NameBuff, varp, MAXPATHL - 1);
11742     }
11743 }
11744 
11745 /*
11746  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11747  * printed as a keyname.
11748  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11749  */
11750     static int
11751 wc_use_keyname(char_u *varp, long *wcp)
11752 {
11753     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11754     {
11755 	*wcp = *(long *)varp;
11756 	if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11757 	    return TRUE;
11758     }
11759     return FALSE;
11760 }
11761 
11762 #if defined(FEAT_LANGMAP) || defined(PROTO)
11763 /*
11764  * Any character has an equivalent 'langmap' character.  This is used for
11765  * keyboards that have a special language mode that sends characters above
11766  * 128 (although other characters can be translated too).  The "to" field is a
11767  * Vim command character.  This avoids having to switch the keyboard back to
11768  * ASCII mode when leaving Insert mode.
11769  *
11770  * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11771  * commands.
11772  * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11773  * langmap_entry_T.  This does the same as langmap_mapchar[] for characters >=
11774  * 256.
11775  */
11776 # if defined(FEAT_MBYTE) || defined(PROTO)
11777 /*
11778  * With multi-byte support use growarray for 'langmap' chars >= 256
11779  */
11780 typedef struct
11781 {
11782     int	    from;
11783     int     to;
11784 } langmap_entry_T;
11785 
11786 static garray_T langmap_mapga;
11787 static void langmap_set_entry(int from, int to);
11788 
11789 /*
11790  * Search for an entry in "langmap_mapga" for "from".  If found set the "to"
11791  * field.  If not found insert a new entry at the appropriate location.
11792  */
11793     static void
11794 langmap_set_entry(int from, int to)
11795 {
11796     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11797     int		    a = 0;
11798     int		    b = langmap_mapga.ga_len;
11799 
11800     /* Do a binary search for an existing entry. */
11801     while (a != b)
11802     {
11803 	int i = (a + b) / 2;
11804 	int d = entries[i].from - from;
11805 
11806 	if (d == 0)
11807 	{
11808 	    entries[i].to = to;
11809 	    return;
11810 	}
11811 	if (d < 0)
11812 	    a = i + 1;
11813 	else
11814 	    b = i;
11815     }
11816 
11817     if (ga_grow(&langmap_mapga, 1) != OK)
11818 	return;  /* out of memory */
11819 
11820     /* insert new entry at position "a" */
11821     entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11822     mch_memmove(entries + 1, entries,
11823 			(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11824     ++langmap_mapga.ga_len;
11825     entries[0].from = from;
11826     entries[0].to = to;
11827 }
11828 
11829 /*
11830  * Apply 'langmap' to multi-byte character "c" and return the result.
11831  */
11832     int
11833 langmap_adjust_mb(int c)
11834 {
11835     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11836     int a = 0;
11837     int b = langmap_mapga.ga_len;
11838 
11839     while (a != b)
11840     {
11841 	int i = (a + b) / 2;
11842 	int d = entries[i].from - c;
11843 
11844 	if (d == 0)
11845 	    return entries[i].to;  /* found matching entry */
11846 	if (d < 0)
11847 	    a = i + 1;
11848 	else
11849 	    b = i;
11850     }
11851     return c;  /* no entry found, return "c" unmodified */
11852 }
11853 # endif
11854 
11855     static void
11856 langmap_init(void)
11857 {
11858     int i;
11859 
11860     for (i = 0; i < 256; i++)
11861 	langmap_mapchar[i] = i;	 /* we init with a one-to-one map */
11862 # ifdef FEAT_MBYTE
11863     ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11864 # endif
11865 }
11866 
11867 /*
11868  * Called when langmap option is set; the language map can be
11869  * changed at any time!
11870  */
11871     static void
11872 langmap_set(void)
11873 {
11874     char_u  *p;
11875     char_u  *p2;
11876     int	    from, to;
11877 
11878 #ifdef FEAT_MBYTE
11879     ga_clear(&langmap_mapga);		    /* clear the previous map first */
11880 #endif
11881     langmap_init();			    /* back to one-to-one map */
11882 
11883     for (p = p_langmap; p[0] != NUL; )
11884     {
11885 	for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11886 							       MB_PTR_ADV(p2))
11887 	{
11888 	    if (p2[0] == '\\' && p2[1] != NUL)
11889 		++p2;
11890 	}
11891 	if (p2[0] == ';')
11892 	    ++p2;	    /* abcd;ABCD form, p2 points to A */
11893 	else
11894 	    p2 = NULL;	    /* aAbBcCdD form, p2 is NULL */
11895 	while (p[0])
11896 	{
11897 	    if (p[0] == ',')
11898 	    {
11899 		++p;
11900 		break;
11901 	    }
11902 	    if (p[0] == '\\' && p[1] != NUL)
11903 		++p;
11904 #ifdef FEAT_MBYTE
11905 	    from = (*mb_ptr2char)(p);
11906 #else
11907 	    from = p[0];
11908 #endif
11909 	    to = NUL;
11910 	    if (p2 == NULL)
11911 	    {
11912 		MB_PTR_ADV(p);
11913 		if (p[0] != ',')
11914 		{
11915 		    if (p[0] == '\\')
11916 			++p;
11917 #ifdef FEAT_MBYTE
11918 		    to = (*mb_ptr2char)(p);
11919 #else
11920 		    to = p[0];
11921 #endif
11922 		}
11923 	    }
11924 	    else
11925 	    {
11926 		if (p2[0] != ',')
11927 		{
11928 		    if (p2[0] == '\\')
11929 			++p2;
11930 #ifdef FEAT_MBYTE
11931 		    to = (*mb_ptr2char)(p2);
11932 #else
11933 		    to = p2[0];
11934 #endif
11935 		}
11936 	    }
11937 	    if (to == NUL)
11938 	    {
11939 		EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11940 							     transchar(from));
11941 		return;
11942 	    }
11943 
11944 #ifdef FEAT_MBYTE
11945 	    if (from >= 256)
11946 		langmap_set_entry(from, to);
11947 	    else
11948 #endif
11949 		langmap_mapchar[from & 255] = to;
11950 
11951 	    /* Advance to next pair */
11952 	    MB_PTR_ADV(p);
11953 	    if (p2 != NULL)
11954 	    {
11955 		MB_PTR_ADV(p2);
11956 		if (*p == ';')
11957 		{
11958 		    p = p2;
11959 		    if (p[0] != NUL)
11960 		    {
11961 			if (p[0] != ',')
11962 			{
11963 			    EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11964 			    return;
11965 			}
11966 			++p;
11967 		    }
11968 		    break;
11969 		}
11970 	    }
11971 	}
11972     }
11973 }
11974 #endif
11975 
11976 /*
11977  * Return TRUE if format option 'x' is in effect.
11978  * Take care of no formatting when 'paste' is set.
11979  */
11980     int
11981 has_format_option(int x)
11982 {
11983     if (p_paste)
11984 	return FALSE;
11985     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11986 }
11987 
11988 /*
11989  * Return TRUE if "x" is present in 'shortmess' option, or
11990  * 'shortmess' contains 'a' and "x" is present in SHM_A.
11991  */
11992     int
11993 shortmess(int x)
11994 {
11995     return p_shm != NULL &&
11996 	    (   vim_strchr(p_shm, x) != NULL
11997 	    || (vim_strchr(p_shm, 'a') != NULL
11998 		&& vim_strchr((char_u *)SHM_A, x) != NULL));
11999 }
12000 
12001 /*
12002  * paste_option_changed() - Called after p_paste was set or reset.
12003  */
12004     static void
12005 paste_option_changed(void)
12006 {
12007     static int	old_p_paste = FALSE;
12008     static int	save_sm = 0;
12009     static int	save_sta = 0;
12010 #ifdef FEAT_CMDL_INFO
12011     static int	save_ru = 0;
12012 #endif
12013 #ifdef FEAT_RIGHTLEFT
12014     static int	save_ri = 0;
12015     static int	save_hkmap = 0;
12016 #endif
12017     buf_T	*buf;
12018 
12019     if (p_paste)
12020     {
12021 	/*
12022 	 * Paste switched from off to on.
12023 	 * Save the current values, so they can be restored later.
12024 	 */
12025 	if (!old_p_paste)
12026 	{
12027 	    /* save options for each buffer */
12028 	    FOR_ALL_BUFFERS(buf)
12029 	    {
12030 		buf->b_p_tw_nopaste = buf->b_p_tw;
12031 		buf->b_p_wm_nopaste = buf->b_p_wm;
12032 		buf->b_p_sts_nopaste = buf->b_p_sts;
12033 		buf->b_p_ai_nopaste = buf->b_p_ai;
12034 		buf->b_p_et_nopaste = buf->b_p_et;
12035 	    }
12036 
12037 	    /* save global options */
12038 	    save_sm = p_sm;
12039 	    save_sta = p_sta;
12040 #ifdef FEAT_CMDL_INFO
12041 	    save_ru = p_ru;
12042 #endif
12043 #ifdef FEAT_RIGHTLEFT
12044 	    save_ri = p_ri;
12045 	    save_hkmap = p_hkmap;
12046 #endif
12047 	    /* save global values for local buffer options */
12048 	    p_ai_nopaste = p_ai;
12049 	    p_et_nopaste = p_et;
12050 	    p_sts_nopaste = p_sts;
12051 	    p_tw_nopaste = p_tw;
12052 	    p_wm_nopaste = p_wm;
12053 	}
12054 
12055 	/*
12056 	 * Always set the option values, also when 'paste' is set when it is
12057 	 * already on.
12058 	 */
12059 	/* set options for each buffer */
12060 	FOR_ALL_BUFFERS(buf)
12061 	{
12062 	    buf->b_p_tw = 0;	    /* textwidth is 0 */
12063 	    buf->b_p_wm = 0;	    /* wrapmargin is 0 */
12064 	    buf->b_p_sts = 0;	    /* softtabstop is 0 */
12065 	    buf->b_p_ai = 0;	    /* no auto-indent */
12066 	    buf->b_p_et = 0;	    /* no expandtab */
12067 	}
12068 
12069 	/* set global options */
12070 	p_sm = 0;		    /* no showmatch */
12071 	p_sta = 0;		    /* no smarttab */
12072 #ifdef FEAT_CMDL_INFO
12073 	if (p_ru)
12074 	    status_redraw_all();    /* redraw to remove the ruler */
12075 	p_ru = 0;		    /* no ruler */
12076 #endif
12077 #ifdef FEAT_RIGHTLEFT
12078 	p_ri = 0;		    /* no reverse insert */
12079 	p_hkmap = 0;		    /* no Hebrew keyboard */
12080 #endif
12081 	/* set global values for local buffer options */
12082 	p_tw = 0;
12083 	p_wm = 0;
12084 	p_sts = 0;
12085 	p_ai = 0;
12086     }
12087 
12088     /*
12089      * Paste switched from on to off: Restore saved values.
12090      */
12091     else if (old_p_paste)
12092     {
12093 	/* restore options for each buffer */
12094 	FOR_ALL_BUFFERS(buf)
12095 	{
12096 	    buf->b_p_tw = buf->b_p_tw_nopaste;
12097 	    buf->b_p_wm = buf->b_p_wm_nopaste;
12098 	    buf->b_p_sts = buf->b_p_sts_nopaste;
12099 	    buf->b_p_ai = buf->b_p_ai_nopaste;
12100 	    buf->b_p_et = buf->b_p_et_nopaste;
12101 	}
12102 
12103 	/* restore global options */
12104 	p_sm = save_sm;
12105 	p_sta = save_sta;
12106 #ifdef FEAT_CMDL_INFO
12107 	if (p_ru != save_ru)
12108 	    status_redraw_all();    /* redraw to draw the ruler */
12109 	p_ru = save_ru;
12110 #endif
12111 #ifdef FEAT_RIGHTLEFT
12112 	p_ri = save_ri;
12113 	p_hkmap = save_hkmap;
12114 #endif
12115 	/* set global values for local buffer options */
12116 	p_ai = p_ai_nopaste;
12117 	p_et = p_et_nopaste;
12118 	p_sts = p_sts_nopaste;
12119 	p_tw = p_tw_nopaste;
12120 	p_wm = p_wm_nopaste;
12121     }
12122 
12123     old_p_paste = p_paste;
12124 }
12125 
12126 /*
12127  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12128  *
12129  * Reset 'compatible' and set the values for options that didn't get set yet
12130  * to the Vim defaults.
12131  * Don't do this if the 'compatible' option has been set or reset before.
12132  * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
12133  */
12134     void
12135 vimrc_found(char_u *fname, char_u *envname)
12136 {
12137     int		opt_idx;
12138     int		dofree = FALSE;
12139     char_u	*p;
12140 
12141     if (!option_was_set((char_u *)"cp"))
12142     {
12143 	p_cp = FALSE;
12144 	for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12145 	    if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12146 		set_option_default(opt_idx, OPT_FREE, FALSE);
12147 	didset_options();
12148 	didset_options2();
12149     }
12150 
12151     if (fname != NULL)
12152     {
12153 	p = vim_getenv(envname, &dofree);
12154 	if (p == NULL)
12155 	{
12156 	    /* Set $MYVIMRC to the first vimrc file found. */
12157 	    p = FullName_save(fname, FALSE);
12158 	    if (p != NULL)
12159 	    {
12160 		vim_setenv(envname, p);
12161 		vim_free(p);
12162 	    }
12163 	}
12164 	else if (dofree)
12165 	    vim_free(p);
12166     }
12167 }
12168 
12169 /*
12170  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
12171  */
12172     void
12173 change_compatible(int on)
12174 {
12175     int	    opt_idx;
12176 
12177     if (p_cp != on)
12178     {
12179 	p_cp = on;
12180 	compatible_set();
12181     }
12182     opt_idx = findoption((char_u *)"cp");
12183     if (opt_idx >= 0)
12184 	options[opt_idx].flags |= P_WAS_SET;
12185 }
12186 
12187 /*
12188  * Return TRUE when option "name" has been set.
12189  * Only works correctly for global options.
12190  */
12191     int
12192 option_was_set(char_u *name)
12193 {
12194     int idx;
12195 
12196     idx = findoption(name);
12197     if (idx < 0)	/* unknown option */
12198 	return FALSE;
12199     if (options[idx].flags & P_WAS_SET)
12200 	return TRUE;
12201     return FALSE;
12202 }
12203 
12204 /*
12205  * Reset the flag indicating option "name" was set.
12206  */
12207     void
12208 reset_option_was_set(char_u *name)
12209 {
12210     int idx = findoption(name);
12211 
12212     if (idx >= 0)
12213 	options[idx].flags &= ~P_WAS_SET;
12214 }
12215 
12216 /*
12217  * compatible_set() - Called when 'compatible' has been set or unset.
12218  *
12219  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12220  * flag) to a Vi compatible value.
12221  * When 'compatible' is unset: Set all options that have a different default
12222  * for Vim (without the P_VI_DEF flag) to that default.
12223  */
12224     static void
12225 compatible_set(void)
12226 {
12227     int	    opt_idx;
12228 
12229     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12230 	if (	   ((options[opt_idx].flags & P_VIM) && p_cp)
12231 		|| (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12232 	    set_option_default(opt_idx, OPT_FREE, p_cp);
12233     didset_options();
12234     didset_options2();
12235 }
12236 
12237 #ifdef FEAT_LINEBREAK
12238 
12239 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12240    /* Borland C++ screws up loop optimisation here (negri) */
12241   #pragma option -O-l
12242 # endif
12243 
12244 /*
12245  * fill_breakat_flags() -- called when 'breakat' changes value.
12246  */
12247     static void
12248 fill_breakat_flags(void)
12249 {
12250     char_u	*p;
12251     int		i;
12252 
12253     for (i = 0; i < 256; i++)
12254 	breakat_flags[i] = FALSE;
12255 
12256     if (p_breakat != NULL)
12257 	for (p = p_breakat; *p; p++)
12258 	    breakat_flags[*p] = TRUE;
12259 }
12260 
12261 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12262   #pragma option -O.l
12263 # endif
12264 
12265 #endif
12266 
12267 /*
12268  * Check an option that can be a range of string values.
12269  *
12270  * Return OK for correct value, FAIL otherwise.
12271  * Empty is always OK.
12272  */
12273     static int
12274 check_opt_strings(
12275     char_u	*val,
12276     char	**values,
12277     int		list)	    /* when TRUE: accept a list of values */
12278 {
12279     return opt_strings_flags(val, values, NULL, list);
12280 }
12281 
12282 /*
12283  * Handle an option that can be a range of string values.
12284  * Set a flag in "*flagp" for each string present.
12285  *
12286  * Return OK for correct value, FAIL otherwise.
12287  * Empty is always OK.
12288  */
12289     static int
12290 opt_strings_flags(
12291     char_u	*val,		/* new value */
12292     char	**values,	/* array of valid string values */
12293     unsigned	*flagp,
12294     int		list)		/* when TRUE: accept a list of values */
12295 {
12296     int		i;
12297     int		len;
12298     unsigned	new_flags = 0;
12299 
12300     while (*val)
12301     {
12302 	for (i = 0; ; ++i)
12303 	{
12304 	    if (values[i] == NULL)	/* val not found in values[] */
12305 		return FAIL;
12306 
12307 	    len = (int)STRLEN(values[i]);
12308 	    if (STRNCMP(values[i], val, len) == 0
12309 		    && ((list && val[len] == ',') || val[len] == NUL))
12310 	    {
12311 		val += len + (val[len] == ',');
12312 		new_flags |= (1 << i);
12313 		break;		/* check next item in val list */
12314 	    }
12315 	}
12316     }
12317     if (flagp != NULL)
12318 	*flagp = new_flags;
12319 
12320     return OK;
12321 }
12322 
12323 /*
12324  * Read the 'wildmode' option, fill wim_flags[].
12325  */
12326     static int
12327 check_opt_wim(void)
12328 {
12329     char_u	new_wim_flags[4];
12330     char_u	*p;
12331     int		i;
12332     int		idx = 0;
12333 
12334     for (i = 0; i < 4; ++i)
12335 	new_wim_flags[i] = 0;
12336 
12337     for (p = p_wim; *p; ++p)
12338     {
12339 	for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12340 	    ;
12341 	if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12342 	    return FAIL;
12343 	if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12344 	    new_wim_flags[idx] |= WIM_LONGEST;
12345 	else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12346 	    new_wim_flags[idx] |= WIM_FULL;
12347 	else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12348 	    new_wim_flags[idx] |= WIM_LIST;
12349 	else
12350 	    return FAIL;
12351 	p += i;
12352 	if (*p == NUL)
12353 	    break;
12354 	if (*p == ',')
12355 	{
12356 	    if (idx == 3)
12357 		return FAIL;
12358 	    ++idx;
12359 	}
12360     }
12361 
12362     /* fill remaining entries with last flag */
12363     while (idx < 3)
12364     {
12365 	new_wim_flags[idx + 1] = new_wim_flags[idx];
12366 	++idx;
12367     }
12368 
12369     /* only when there are no errors, wim_flags[] is changed */
12370     for (i = 0; i < 4; ++i)
12371 	wim_flags[i] = new_wim_flags[i];
12372     return OK;
12373 }
12374 
12375 /*
12376  * Check if backspacing over something is allowed.
12377  */
12378     int
12379 can_bs(
12380     int		what)	    /* BS_INDENT, BS_EOL or BS_START */
12381 {
12382     switch (*p_bs)
12383     {
12384 	case '2':	return TRUE;
12385 	case '1':	return (what != BS_START);
12386 	case '0':	return FALSE;
12387     }
12388     return vim_strchr(p_bs, what) != NULL;
12389 }
12390 
12391 /*
12392  * Save the current values of 'fileformat' and 'fileencoding', so that we know
12393  * the file must be considered changed when the value is different.
12394  */
12395     void
12396 save_file_ff(buf_T *buf)
12397 {
12398     buf->b_start_ffc = *buf->b_p_ff;
12399     buf->b_start_eol = buf->b_p_eol;
12400 #ifdef FEAT_MBYTE
12401     buf->b_start_bomb = buf->b_p_bomb;
12402 
12403     /* Only use free/alloc when necessary, they take time. */
12404     if (buf->b_start_fenc == NULL
12405 			     || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12406     {
12407 	vim_free(buf->b_start_fenc);
12408 	buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12409     }
12410 #endif
12411 }
12412 
12413 /*
12414  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12415  * from when editing started (save_file_ff() called).
12416  * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12417  * changed and 'binary' is not set.
12418  * Also when 'endofline' was changed and 'fixeol' is not set.
12419  * When "ignore_empty" is true don't consider a new, empty buffer to be
12420  * changed.
12421  */
12422     int
12423 file_ff_differs(buf_T *buf, int ignore_empty)
12424 {
12425     /* In a buffer that was never loaded the options are not valid. */
12426     if (buf->b_flags & BF_NEVERLOADED)
12427 	return FALSE;
12428     if (ignore_empty
12429 	    && (buf->b_flags & BF_NEW)
12430 	    && buf->b_ml.ml_line_count == 1
12431 	    && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12432 	return FALSE;
12433     if (buf->b_start_ffc != *buf->b_p_ff)
12434 	return TRUE;
12435     if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
12436 	return TRUE;
12437 #ifdef FEAT_MBYTE
12438     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12439 	return TRUE;
12440     if (buf->b_start_fenc == NULL)
12441 	return (*buf->b_p_fenc != NUL);
12442     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12443 #else
12444     return FALSE;
12445 #endif
12446 }
12447 
12448 /*
12449  * return OK if "p" is a valid fileformat name, FAIL otherwise.
12450  */
12451     int
12452 check_ff_value(char_u *p)
12453 {
12454     return check_opt_strings(p, p_ff_values, FALSE);
12455 }
12456 
12457 /*
12458  * Return the effective shiftwidth value for current buffer, using the
12459  * 'tabstop' value when 'shiftwidth' is zero.
12460  */
12461     long
12462 get_sw_value(buf_T *buf)
12463 {
12464     return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
12465 }
12466 
12467 /*
12468  * Return the effective softtabstop value for the current buffer, using the
12469  * 'tabstop' value when 'softtabstop' is negative.
12470  */
12471     long
12472 get_sts_value(void)
12473 {
12474     return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
12475 }
12476 
12477 /*
12478  * Check matchpairs option for "*initc".
12479  * If there is a match set "*initc" to the matching character and "*findc" to
12480  * the opposite character.  Set "*backwards" to the direction.
12481  * When "switchit" is TRUE swap the direction.
12482  */
12483     void
12484 find_mps_values(
12485     int	    *initc,
12486     int	    *findc,
12487     int	    *backwards,
12488     int	    switchit)
12489 {
12490     char_u	*ptr;
12491 
12492     ptr = curbuf->b_p_mps;
12493     while (*ptr != NUL)
12494     {
12495 #ifdef FEAT_MBYTE
12496 	if (has_mbyte)
12497 	{
12498 	    char_u *prev;
12499 
12500 	    if (mb_ptr2char(ptr) == *initc)
12501 	    {
12502 		if (switchit)
12503 		{
12504 		    *findc = *initc;
12505 		    *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12506 		    *backwards = TRUE;
12507 		}
12508 		else
12509 		{
12510 		    *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12511 		    *backwards = FALSE;
12512 		}
12513 		return;
12514 	    }
12515 	    prev = ptr;
12516 	    ptr += mb_ptr2len(ptr) + 1;
12517 	    if (mb_ptr2char(ptr) == *initc)
12518 	    {
12519 		if (switchit)
12520 		{
12521 		    *findc = *initc;
12522 		    *initc = mb_ptr2char(prev);
12523 		    *backwards = FALSE;
12524 		}
12525 		else
12526 		{
12527 		    *findc = mb_ptr2char(prev);
12528 		    *backwards = TRUE;
12529 		}
12530 		return;
12531 	    }
12532 	    ptr += mb_ptr2len(ptr);
12533 	}
12534 	else
12535 #endif
12536 	{
12537 	    if (*ptr == *initc)
12538 	    {
12539 		if (switchit)
12540 		{
12541 		    *backwards = TRUE;
12542 		    *findc = *initc;
12543 		    *initc = ptr[2];
12544 		}
12545 		else
12546 		{
12547 		    *backwards = FALSE;
12548 		    *findc = ptr[2];
12549 		}
12550 		return;
12551 	    }
12552 	    ptr += 2;
12553 	    if (*ptr == *initc)
12554 	    {
12555 		if (switchit)
12556 		{
12557 		    *backwards = FALSE;
12558 		    *findc = *initc;
12559 		    *initc = ptr[-2];
12560 		}
12561 		else
12562 		{
12563 		    *backwards = TRUE;
12564 		    *findc =  ptr[-2];
12565 		}
12566 		return;
12567 	    }
12568 	    ++ptr;
12569 	}
12570 	if (*ptr == ',')
12571 	    ++ptr;
12572     }
12573 }
12574 
12575 #if defined(FEAT_LINEBREAK) || defined(PROTO)
12576 /*
12577  * This is called when 'breakindentopt' is changed and when a window is
12578  * initialized.
12579  */
12580     static int
12581 briopt_check(win_T *wp)
12582 {
12583     char_u	*p;
12584     int		bri_shift = 0;
12585     long	bri_min = 20;
12586     int		bri_sbr = FALSE;
12587 
12588     p = wp->w_p_briopt;
12589     while (*p != NUL)
12590     {
12591 	if (STRNCMP(p, "shift:", 6) == 0
12592 		 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12593 	{
12594 	    p += 6;
12595 	    bri_shift = getdigits(&p);
12596 	}
12597 	else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12598 	{
12599 	    p += 4;
12600 	    bri_min = getdigits(&p);
12601 	}
12602 	else if (STRNCMP(p, "sbr", 3) == 0)
12603 	{
12604 	    p += 3;
12605 	    bri_sbr = TRUE;
12606 	}
12607 	if (*p != ',' && *p != NUL)
12608 	    return FAIL;
12609 	if (*p == ',')
12610 	    ++p;
12611     }
12612 
12613     wp->w_p_brishift = bri_shift;
12614     wp->w_p_brimin   = bri_min;
12615     wp->w_p_brisbr   = bri_sbr;
12616 
12617     return OK;
12618 }
12619 #endif
12620 
12621 /*
12622  * Get the local or global value of 'backupcopy'.
12623  */
12624     unsigned int
12625 get_bkc_value(buf_T *buf)
12626 {
12627     return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12628 }
12629 
12630 #if defined(FEAT_SIGNS) || defined(PROTO)
12631 /*
12632  * Return TRUE when window "wp" has a column to draw signs in.
12633  */
12634      int
12635 signcolumn_on(win_T *wp)
12636 {
12637     if (*wp->w_p_scl == 'n')
12638 	return FALSE;
12639     if (*wp->w_p_scl == 'y')
12640 	return TRUE;
12641     return (wp->w_buffer->b_signlist != NULL
12642 # ifdef FEAT_NETBEANS_INTG
12643 			|| wp->w_buffer->b_has_sign_column
12644 # endif
12645 		    );
12646 }
12647 #endif
12648 
12649 #if defined(FEAT_EVAL) || defined(PROTO)
12650 /*
12651  * Get window or buffer local options.
12652  */
12653     dict_T *
12654 get_winbuf_options(int bufopt)
12655 {
12656     dict_T	*d;
12657     int		opt_idx;
12658 
12659     d = dict_alloc();
12660     if (d == NULL)
12661 	return NULL;
12662 
12663     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12664     {
12665 	struct vimoption *opt = &options[opt_idx];
12666 
12667 	if ((bufopt && (opt->indir & PV_BUF))
12668 					 || (!bufopt && (opt->indir & PV_WIN)))
12669 	{
12670 	    char_u *varp = get_varp(opt);
12671 
12672 	    if (varp != NULL)
12673 	    {
12674 		if (opt->flags & P_STRING)
12675 		    dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
12676 		else if (opt->flags & P_NUM)
12677 		    dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
12678 		else
12679 		    dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
12680 	    }
12681 	}
12682     }
12683 
12684     return d;
12685 }
12686 #endif
12687