xref: /vim-8.2.3635/src/option.c (revision e16b00a1)
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_WINDOWS) && 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 #ifdef FEAT_WINDOWS
249 # define PV_WFH		OPT_WIN(WV_WFH)
250 # define PV_WFW		OPT_WIN(WV_WFW)
251 #endif
252 #define PV_WRAP		OPT_WIN(WV_WRAP)
253 #ifdef FEAT_CURSORBIND
254 # define PV_CRBIND	OPT_WIN(WV_CRBIND)
255 #endif
256 #ifdef FEAT_CONCEAL
257 # define PV_COCU	OPT_WIN(WV_COCU)
258 # define PV_COLE	OPT_WIN(WV_COLE)
259 #endif
260 #ifdef FEAT_TERMINAL
261 # define PV_TK		OPT_WIN(WV_TK)
262 # define PV_TMS		OPT_WIN(WV_TMS)
263 #endif
264 #ifdef FEAT_SIGNS
265 # define PV_SCL		OPT_WIN(WV_SCL)
266 #endif
267 
268 /* WV_ and BV_ values get typecasted to this for the "indir" field */
269 typedef enum
270 {
271     PV_NONE = 0,
272     PV_MAXVAL = 0xffff    /* to avoid warnings for value out of range */
273 } idopt_T;
274 
275 /*
276  * Options local to a window have a value local to a buffer and global to all
277  * buffers.  Indicate this by setting "var" to VAR_WIN.
278  */
279 #define VAR_WIN ((char_u *)-1)
280 
281 /*
282  * These are the global values for options which are also local to a buffer.
283  * Only to be used in option.c!
284  */
285 static int	p_ai;
286 static int	p_bin;
287 #ifdef FEAT_MBYTE
288 static int	p_bomb;
289 #endif
290 static char_u	*p_bh;
291 static char_u	*p_bt;
292 static int	p_bl;
293 static int	p_ci;
294 #ifdef FEAT_CINDENT
295 static int	p_cin;
296 static char_u	*p_cink;
297 static char_u	*p_cino;
298 #endif
299 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300 static char_u	*p_cinw;
301 #endif
302 #ifdef FEAT_COMMENTS
303 static char_u	*p_com;
304 #endif
305 #ifdef FEAT_FOLDING
306 static char_u	*p_cms;
307 #endif
308 #ifdef FEAT_INS_EXPAND
309 static char_u	*p_cpt;
310 #endif
311 #ifdef FEAT_COMPL_FUNC
312 static char_u	*p_cfu;
313 static char_u	*p_ofu;
314 #endif
315 static int	p_eol;
316 static int	p_fixeol;
317 static int	p_et;
318 #ifdef FEAT_MBYTE
319 static char_u	*p_fenc;
320 #endif
321 static char_u	*p_ff;
322 static char_u	*p_fo;
323 static char_u	*p_flp;
324 #ifdef FEAT_AUTOCMD
325 static char_u	*p_ft;
326 #endif
327 static long	p_iminsert;
328 static long	p_imsearch;
329 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330 static char_u	*p_inex;
331 #endif
332 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333 static char_u	*p_inde;
334 static char_u	*p_indk;
335 #endif
336 #if defined(FEAT_EVAL)
337 static char_u	*p_fex;
338 #endif
339 static int	p_inf;
340 static char_u	*p_isk;
341 #ifdef FEAT_CRYPT
342 static char_u	*p_key;
343 #endif
344 #ifdef FEAT_LISP
345 static int	p_lisp;
346 #endif
347 static int	p_ml;
348 static int	p_ma;
349 static int	p_mod;
350 static char_u	*p_mps;
351 static char_u	*p_nf;
352 static int	p_pi;
353 #ifdef FEAT_TEXTOBJ
354 static char_u	*p_qe;
355 #endif
356 static int	p_ro;
357 #ifdef FEAT_SMARTINDENT
358 static int	p_si;
359 #endif
360 static int	p_sn;
361 static long	p_sts;
362 #if defined(FEAT_SEARCHPATH)
363 static char_u	*p_sua;
364 #endif
365 static long	p_sw;
366 static int	p_swf;
367 #ifdef FEAT_SYN_HL
368 static long	p_smc;
369 static char_u	*p_syn;
370 #endif
371 #ifdef FEAT_SPELL
372 static char_u	*p_spc;
373 static char_u	*p_spf;
374 static char_u	*p_spl;
375 #endif
376 static long	p_ts;
377 static long	p_tw;
378 static int	p_tx;
379 #ifdef FEAT_PERSISTENT_UNDO
380 static int	p_udf;
381 #endif
382 static long	p_wm;
383 #ifdef FEAT_KEYMAP
384 static char_u	*p_keymap;
385 #endif
386 
387 /* Saved values for when 'bin' is set. */
388 static int	p_et_nobin;
389 static int	p_ml_nobin;
390 static long	p_tw_nobin;
391 static long	p_wm_nobin;
392 
393 /* Saved values for when 'paste' is set */
394 static int	p_ai_nopaste;
395 static int	p_et_nopaste;
396 static long	p_sts_nopaste;
397 static long	p_tw_nopaste;
398 static long	p_wm_nopaste;
399 
400 struct vimoption
401 {
402     char	*fullname;	/* full option name */
403     char	*shortname;	/* permissible abbreviation */
404     long_u	flags;		/* see below */
405     char_u	*var;		/* global option: pointer to variable;
406 				 * window-local option: VAR_WIN;
407 				 * buffer-local option: global value */
408     idopt_T	indir;		/* global option: PV_NONE;
409 				 * local option: indirect option index */
410     char_u	*def_val[2];	/* default values for variable (vi and vim) */
411 #ifdef FEAT_EVAL
412     scid_T	scriptID;	/* script in which the option was last set */
413 # define SCRIPTID_INIT , 0
414 #else
415 # define SCRIPTID_INIT
416 #endif
417 };
418 
419 #define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
420 #define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */
421 
422 /*
423  * Flags
424  */
425 #define P_BOOL		0x01	/* the option is boolean */
426 #define P_NUM		0x02	/* the option is numeric */
427 #define P_STRING	0x04	/* the option is a string */
428 #define P_ALLOCED	0x08	/* the string option is in allocated memory,
429 				   must use free_string_option() when
430 				   assigning new value. Not set if default is
431 				   the same. */
432 #define P_EXPAND	0x10	/* environment expansion.  NOTE: P_EXPAND can
433 				   never be used for local or hidden options! */
434 #define P_NODEFAULT	0x40	/* don't set to default value */
435 #define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
436 				    use vim_free() when assigning new value */
437 #define P_WAS_SET	0x100	/* option has been set/reset */
438 #define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
439 #define P_VI_DEF	0x400	/* Use Vi default for Vim */
440 #define P_VIM		0x800	/* Vim option, reset when 'cp' set */
441 
442 				/* when option changed, what to display: */
443 #define P_RSTAT		0x1000	/* redraw status lines */
444 #define P_RWIN		0x2000	/* redraw current window and recompute text */
445 #define P_RBUF		0x4000	/* redraw current buffer and recompute text */
446 #define P_RALL		0x6000	/* redraw all windows */
447 #define P_RCLR		0x7000	/* clear and redraw all */
448 
449 #define P_COMMA		 0x8000	 /* comma separated list */
450 #define P_ONECOMMA	0x18000L /* P_COMMA and cannot have two consecutive
451 				  * commas */
452 #define P_NODUP		0x20000L /* don't allow duplicate strings */
453 #define P_FLAGLIST	0x40000L /* list of single-char flags */
454 
455 #define P_SECURE	0x80000L /* cannot change in modeline or secure mode */
456 #define P_GETTEXT      0x100000L /* expand default value with _() */
457 #define P_NOGLOB       0x200000L /* do not use local value for global vimrc */
458 #define P_NFNAME       0x400000L /* only normal file name chars allowed */
459 #define P_INSECURE     0x800000L /* option was set from a modeline */
460 #define P_PRI_MKRC    0x1000000L /* priority for :mkvimrc (setting option has
461 				    side effects) */
462 #define P_NO_ML       0x2000000L /* not allowed in modeline */
463 #define P_CURSWANT    0x4000000L /* update curswant required; not needed when
464 				  * there is a redraw flag */
465 #define P_NDNAME      0x8000000L /* only normal dir name chars allowed */
466 #define P_RWINONLY   0x10000000L /* only redraw current window */
467 
468 #define ISK_LATIN1  (char_u *)"@,48-57,_,192-255"
469 
470 /* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471  * for the currency sign. */
472 #if defined(MSWIN)
473 # define ISP_LATIN1 (char_u *)"@,~-255"
474 #else
475 # define ISP_LATIN1 (char_u *)"@,161-255"
476 #endif
477 
478 /* Make the string as short as possible when compiling with few features. */
479 #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
480 	|| defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
481 	|| defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
482 	|| defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX) \
483 	|| defined(FEAT_TERMINAL)
484 # 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,$:StatusLineTerm"
485 #else
486 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
487 #endif
488 
489 /* Default python version for pyx* commands */
490 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
491 # define DEFAULT_PYTHON_VER	0
492 #elif defined(FEAT_PYTHON3)
493 # define DEFAULT_PYTHON_VER	3
494 #elif defined(FEAT_PYTHON)
495 # define DEFAULT_PYTHON_VER	2
496 #else
497 # define DEFAULT_PYTHON_VER	0
498 #endif
499 
500 /*
501  * options[] is initialized here.
502  * The order of the options MUST be alphabetic for ":set all" and findoption().
503  * All option names MUST start with a lowercase letter (for findoption()).
504  * Exception: "t_" options are at the end.
505  * The options with a NULL variable are 'hidden': a set command for them is
506  * ignored and they are not printed.
507  */
508 static struct vimoption options[] =
509 {
510     {"aleph",	    "al",   P_NUM|P_VI_DEF|P_CURSWANT,
511 #ifdef FEAT_RIGHTLEFT
512 			    (char_u *)&p_aleph, PV_NONE,
513 #else
514 			    (char_u *)NULL, PV_NONE,
515 #endif
516 			    {
517 #if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
518 			    (char_u *)128L,
519 #else
520 			    (char_u *)224L,
521 #endif
522 					    (char_u *)0L} SCRIPTID_INIT},
523     {"antialias",   "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
524 #if defined(FEAT_GUI) && defined(MACOS_X)
525 			    (char_u *)&p_antialias, PV_NONE,
526 			    {(char_u *)FALSE, (char_u *)FALSE}
527 #else
528 			    (char_u *)NULL, PV_NONE,
529 			    {(char_u *)FALSE, (char_u *)FALSE}
530 #endif
531 			    SCRIPTID_INIT},
532     {"arabic",	    "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
533 #ifdef FEAT_ARABIC
534 			    (char_u *)VAR_WIN, PV_ARAB,
535 #else
536 			    (char_u *)NULL, PV_NONE,
537 #endif
538 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
539     {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540 #ifdef FEAT_ARABIC
541 			    (char_u *)&p_arshape, PV_NONE,
542 #else
543 			    (char_u *)NULL, PV_NONE,
544 #endif
545 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
546     {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
547 #ifdef FEAT_RIGHTLEFT
548 			    (char_u *)&p_ari, PV_NONE,
549 #else
550 			    (char_u *)NULL, PV_NONE,
551 #endif
552 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
553     {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
554 #ifdef FEAT_FKMAP
555 			    (char_u *)&p_altkeymap, PV_NONE,
556 #else
557 			    (char_u *)NULL, PV_NONE,
558 #endif
559 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
560     {"ambiwidth",  "ambw",  P_STRING|P_VI_DEF|P_RCLR,
561 #if defined(FEAT_MBYTE)
562 			    (char_u *)&p_ambw, PV_NONE,
563 			    {(char_u *)"single", (char_u *)0L}
564 #else
565 			    (char_u *)NULL, PV_NONE,
566 			    {(char_u *)0L, (char_u *)0L}
567 #endif
568 			    SCRIPTID_INIT},
569     {"autochdir",  "acd",   P_BOOL|P_VI_DEF,
570 #ifdef FEAT_AUTOCHDIR
571 			    (char_u *)&p_acd, PV_NONE,
572 			    {(char_u *)FALSE, (char_u *)0L}
573 #else
574 			    (char_u *)NULL, PV_NONE,
575 			    {(char_u *)0L, (char_u *)0L}
576 #endif
577 			    SCRIPTID_INIT},
578     {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
579 			    (char_u *)&p_ai, PV_AI,
580 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
581     {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
582 			    (char_u *)NULL, PV_NONE,
583 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
584     {"autoread",    "ar",   P_BOOL|P_VI_DEF,
585 			    (char_u *)&p_ar, PV_AR,
586 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
587     {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
588 			    (char_u *)&p_aw, PV_NONE,
589 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
590     {"autowriteall","awa",  P_BOOL|P_VI_DEF,
591 			    (char_u *)&p_awa, PV_NONE,
592 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
593     {"background",  "bg",   P_STRING|P_VI_DEF|P_RCLR,
594 			    (char_u *)&p_bg, PV_NONE,
595 			    {
596 #if (defined(WIN3264)) && !defined(FEAT_GUI)
597 			    (char_u *)"dark",
598 #else
599 			    (char_u *)"light",
600 #endif
601 					    (char_u *)0L} SCRIPTID_INIT},
602     {"backspace",   "bs",   P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
603 			    (char_u *)&p_bs, PV_NONE,
604 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
605     {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
606 			    (char_u *)&p_bk, PV_NONE,
607 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
608     {"backupcopy",  "bkc",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
609 			    (char_u *)&p_bkc, PV_BKC,
610 #ifdef UNIX
611 			    {(char_u *)"yes", (char_u *)"auto"}
612 #else
613 			    {(char_u *)"auto", (char_u *)"auto"}
614 #endif
615 			    SCRIPTID_INIT},
616     {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
617 							    |P_NODUP|P_SECURE,
618 			    (char_u *)&p_bdir, PV_NONE,
619 			    {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
620     {"backupext",   "bex",  P_STRING|P_VI_DEF|P_NFNAME,
621 			    (char_u *)&p_bex, PV_NONE,
622 			    {
623 #ifdef VMS
624 			    (char_u *)"_",
625 #else
626 			    (char_u *)"~",
627 #endif
628 					    (char_u *)0L} SCRIPTID_INIT},
629     {"backupskip",  "bsk",  P_STRING|P_VI_DEF|P_ONECOMMA,
630 #ifdef FEAT_WILDIGN
631 			    (char_u *)&p_bsk, PV_NONE,
632 			    {(char_u *)"", (char_u *)0L}
633 #else
634 			    (char_u *)NULL, PV_NONE,
635 			    {(char_u *)0L, (char_u *)0L}
636 #endif
637 			    SCRIPTID_INIT},
638     {"balloondelay","bdlay",P_NUM|P_VI_DEF,
639 #ifdef FEAT_BEVAL
640 			    (char_u *)&p_bdlay, PV_NONE,
641 			    {(char_u *)600L, (char_u *)0L}
642 #else
643 			    (char_u *)NULL, PV_NONE,
644 			    {(char_u *)0L, (char_u *)0L}
645 #endif
646 			    SCRIPTID_INIT},
647     {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
648 #ifdef FEAT_BEVAL
649 			    (char_u *)&p_beval, PV_NONE,
650 			    {(char_u *)FALSE, (char_u *)0L}
651 #else
652 			    (char_u *)NULL, PV_NONE,
653 			    {(char_u *)0L, (char_u *)0L}
654 #endif
655 			    SCRIPTID_INIT},
656     {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
657 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 			    (char_u *)&p_bexpr, PV_BEXPR,
659 			    {(char_u *)"", (char_u *)0L}
660 #else
661 			    (char_u *)NULL, PV_NONE,
662 			    {(char_u *)0L, (char_u *)0L}
663 #endif
664 			    SCRIPTID_INIT},
665     {"beautify",    "bf",   P_BOOL|P_VI_DEF,
666 			    (char_u *)NULL, PV_NONE,
667 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
668     {"belloff",      "bo",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 			    (char_u *)&p_bo, PV_NONE,
670 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
671     {"binary",	    "bin",  P_BOOL|P_VI_DEF|P_RSTAT,
672 			    (char_u *)&p_bin, PV_BIN,
673 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
674     {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
675 			    (char_u *)NULL, PV_NONE,
676 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
677     {"bomb",	    NULL,   P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
678 #ifdef FEAT_MBYTE
679 			    (char_u *)&p_bomb, PV_BOMB,
680 #else
681 			    (char_u *)NULL, PV_NONE,
682 #endif
683 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
684     {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
685 #ifdef FEAT_LINEBREAK
686 			    (char_u *)&p_breakat, PV_NONE,
687 			    {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
688 #else
689 			    (char_u *)NULL, PV_NONE,
690 			    {(char_u *)0L, (char_u *)0L}
691 #endif
692 			    SCRIPTID_INIT},
693     {"breakindent",   "bri",  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
694 #ifdef FEAT_LINEBREAK
695 			    (char_u *)VAR_WIN, PV_BRI,
696 			    {(char_u *)FALSE, (char_u *)0L}
697 #else
698 			    (char_u *)NULL, PV_NONE,
699 			    {(char_u *)0L, (char_u *)0L}
700 #endif
701 			    SCRIPTID_INIT},
702     {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
703 						  |P_ONECOMMA|P_NODUP,
704 #ifdef FEAT_LINEBREAK
705 			    (char_u *)VAR_WIN, PV_BRIOPT,
706 			    {(char_u *)"", (char_u *)NULL}
707 #else
708 			    (char_u *)NULL, PV_NONE,
709 			    {(char_u *)"", (char_u *)NULL}
710 #endif
711 			    SCRIPTID_INIT},
712     {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
713 #ifdef FEAT_BROWSE
714 			    (char_u *)&p_bsdir, PV_NONE,
715 			    {(char_u *)"last", (char_u *)0L}
716 #else
717 			    (char_u *)NULL, PV_NONE,
718 			    {(char_u *)0L, (char_u *)0L}
719 #endif
720 			    SCRIPTID_INIT},
721     {"bufhidden",   "bh",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
722 			    (char_u *)&p_bh, PV_BH,
723 			    {(char_u *)"", (char_u *)0L}
724 			    SCRIPTID_INIT},
725     {"buflisted",   "bl",   P_BOOL|P_VI_DEF|P_NOGLOB,
726 			    (char_u *)&p_bl, PV_BL,
727 			    {(char_u *)1L, (char_u *)0L}
728 			    SCRIPTID_INIT},
729     {"buftype",	    "bt",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
730 			    (char_u *)&p_bt, PV_BT,
731 			    {(char_u *)"", (char_u *)0L}
732 			    SCRIPTID_INIT},
733     {"casemap",	    "cmp",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
734 #ifdef FEAT_MBYTE
735 			    (char_u *)&p_cmp, PV_NONE,
736 			    {(char_u *)"internal,keepascii", (char_u *)0L}
737 #else
738 			    (char_u *)NULL, PV_NONE,
739 			    {(char_u *)0L, (char_u *)0L}
740 #endif
741 			    SCRIPTID_INIT},
742     {"cdpath",	    "cd",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
743 #ifdef FEAT_SEARCHPATH
744 			    (char_u *)&p_cdpath, PV_NONE,
745 			    {(char_u *)",,", (char_u *)0L}
746 #else
747 			    (char_u *)NULL, PV_NONE,
748 			    {(char_u *)0L, (char_u *)0L}
749 #endif
750 			    SCRIPTID_INIT},
751     {"cedit",	    NULL,   P_STRING,
752 #ifdef FEAT_CMDWIN
753 			    (char_u *)&p_cedit, PV_NONE,
754 			    {(char_u *)"", (char_u *)CTRL_F_STR}
755 #else
756 			    (char_u *)NULL, PV_NONE,
757 			    {(char_u *)0L, (char_u *)0L}
758 #endif
759 			    SCRIPTID_INIT},
760     {"charconvert",  "ccv", P_STRING|P_VI_DEF|P_SECURE,
761 #if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
762 			    (char_u *)&p_ccv, PV_NONE,
763 			    {(char_u *)"", (char_u *)0L}
764 #else
765 			    (char_u *)NULL, PV_NONE,
766 			    {(char_u *)0L, (char_u *)0L}
767 #endif
768 			    SCRIPTID_INIT},
769     {"cindent",	    "cin",  P_BOOL|P_VI_DEF|P_VIM,
770 #ifdef FEAT_CINDENT
771 			    (char_u *)&p_cin, PV_CIN,
772 #else
773 			    (char_u *)NULL, PV_NONE,
774 #endif
775 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
776     {"cinkeys",	    "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
777 #ifdef FEAT_CINDENT
778 			    (char_u *)&p_cink, PV_CINK,
779 			    {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
780 #else
781 			    (char_u *)NULL, PV_NONE,
782 			    {(char_u *)0L, (char_u *)0L}
783 #endif
784 			    SCRIPTID_INIT},
785     {"cinoptions",  "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
786 #ifdef FEAT_CINDENT
787 			    (char_u *)&p_cino, PV_CINO,
788 #else
789 			    (char_u *)NULL, PV_NONE,
790 #endif
791 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
792     {"cinwords",    "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
793 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
794 			    (char_u *)&p_cinw, PV_CINW,
795 			    {(char_u *)"if,else,while,do,for,switch",
796 				(char_u *)0L}
797 #else
798 			    (char_u *)NULL, PV_NONE,
799 			    {(char_u *)0L, (char_u *)0L}
800 #endif
801 			    SCRIPTID_INIT},
802     {"clipboard",   "cb",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
803 #ifdef FEAT_CLIPBOARD
804 			    (char_u *)&p_cb, PV_NONE,
805 # ifdef FEAT_XCLIPBOARD
806 			    {(char_u *)"autoselect,exclude:cons\\|linux",
807 							       (char_u *)0L}
808 # else
809 			    {(char_u *)"", (char_u *)0L}
810 # endif
811 #else
812 			    (char_u *)NULL, PV_NONE,
813 			    {(char_u *)"", (char_u *)0L}
814 #endif
815 			    SCRIPTID_INIT},
816     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
817 			    (char_u *)&p_ch, PV_NONE,
818 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
819     {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
820 #ifdef FEAT_CMDWIN
821 			    (char_u *)&p_cwh, PV_NONE,
822 #else
823 			    (char_u *)NULL, PV_NONE,
824 #endif
825 			    {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
826     {"colorcolumn", "cc",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
827 #ifdef FEAT_SYN_HL
828 			    (char_u *)VAR_WIN, PV_CC,
829 #else
830 			    (char_u *)NULL, PV_NONE,
831 #endif
832 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
833     {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
834 			    (char_u *)&Columns, PV_NONE,
835 			    {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
836     {"comments",    "com",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
837 							  |P_NODUP|P_CURSWANT,
838 #ifdef FEAT_COMMENTS
839 			    (char_u *)&p_com, PV_COM,
840 			    {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
841 				(char_u *)0L}
842 #else
843 			    (char_u *)NULL, PV_NONE,
844 			    {(char_u *)0L, (char_u *)0L}
845 #endif
846 			    SCRIPTID_INIT},
847     {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
848 #ifdef FEAT_FOLDING
849 			    (char_u *)&p_cms, PV_CMS,
850 			    {(char_u *)"/*%s*/", (char_u *)0L}
851 #else
852 			    (char_u *)NULL, PV_NONE,
853 			    {(char_u *)0L, (char_u *)0L}
854 #endif
855 			    SCRIPTID_INIT},
856 			    /* P_PRI_MKRC isn't needed here, optval_default()
857 			     * always returns TRUE for 'compatible' */
858     {"compatible",  "cp",   P_BOOL|P_RALL,
859 			    (char_u *)&p_cp, PV_NONE,
860 			    {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
861     {"complete",    "cpt",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
862 #ifdef FEAT_INS_EXPAND
863 			    (char_u *)&p_cpt, PV_CPT,
864 			    {(char_u *)".,w,b,u,t,i", (char_u *)0L}
865 #else
866 			    (char_u *)NULL, PV_NONE,
867 			    {(char_u *)0L, (char_u *)0L}
868 #endif
869 			    SCRIPTID_INIT},
870     {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
871 #ifdef FEAT_CONCEAL
872 			    (char_u *)VAR_WIN, PV_COCU,
873 			    {(char_u *)"", (char_u *)NULL}
874 #else
875 			    (char_u *)NULL, PV_NONE,
876 			    {(char_u *)NULL, (char_u *)0L}
877 #endif
878 			    SCRIPTID_INIT},
879     {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
880 #ifdef FEAT_CONCEAL
881 			    (char_u *)VAR_WIN, PV_COLE,
882 #else
883 			    (char_u *)NULL, PV_NONE,
884 #endif
885 			    {(char_u *)0L, (char_u *)0L}
886 			    SCRIPTID_INIT},
887     {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
888 #ifdef FEAT_COMPL_FUNC
889 			    (char_u *)&p_cfu, PV_CFU,
890 			    {(char_u *)"", (char_u *)0L}
891 #else
892 			    (char_u *)NULL, PV_NONE,
893 			    {(char_u *)0L, (char_u *)0L}
894 #endif
895 			    SCRIPTID_INIT},
896     {"completeopt",   "cot",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
897 #ifdef FEAT_INS_EXPAND
898 			    (char_u *)&p_cot, PV_NONE,
899 			    {(char_u *)"menu,preview", (char_u *)0L}
900 #else
901 			    (char_u *)NULL, PV_NONE,
902 			    {(char_u *)0L, (char_u *)0L}
903 #endif
904 			    SCRIPTID_INIT},
905     {"confirm",     "cf",   P_BOOL|P_VI_DEF,
906 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 			    (char_u *)&p_confirm, PV_NONE,
908 #else
909 			    (char_u *)NULL, PV_NONE,
910 #endif
911 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
912     {"conskey",	    "consk",P_BOOL|P_VI_DEF,
913 			    (char_u *)NULL, PV_NONE,
914 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
915     {"copyindent",  "ci",   P_BOOL|P_VI_DEF|P_VIM,
916 			    (char_u *)&p_ci, PV_CI,
917 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
918     {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 			    (char_u *)&p_cpo, PV_NONE,
920 			    {(char_u *)CPO_VI, (char_u *)CPO_VIM}
921 			    SCRIPTID_INIT},
922     {"cryptmethod", "cm",   P_STRING|P_ALLOCED|P_VI_DEF,
923 #ifdef FEAT_CRYPT
924 			    (char_u *)&p_cm, PV_CM,
925 			    {(char_u *)"zip", (char_u *)0L}
926 #else
927 			    (char_u *)NULL, PV_NONE,
928 			    {(char_u *)0L, (char_u *)0L}
929 #endif
930 			    SCRIPTID_INIT},
931     {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932 #ifdef FEAT_CSCOPE
933 			    (char_u *)&p_cspc, PV_NONE,
934 #else
935 			    (char_u *)NULL, PV_NONE,
936 #endif
937 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
938     {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939 #ifdef FEAT_CSCOPE
940 			    (char_u *)&p_csprg, PV_NONE,
941 			    {(char_u *)"cscope", (char_u *)0L}
942 #else
943 			    (char_u *)NULL, PV_NONE,
944 			    {(char_u *)0L, (char_u *)0L}
945 #endif
946 			    SCRIPTID_INIT},
947     {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
948 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 			    (char_u *)&p_csqf, PV_NONE,
950 			    {(char_u *)"", (char_u *)0L}
951 #else
952 			    (char_u *)NULL, PV_NONE,
953 			    {(char_u *)0L, (char_u *)0L}
954 #endif
955 			    SCRIPTID_INIT},
956     {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957 #ifdef FEAT_CSCOPE
958 			    (char_u *)&p_csre, PV_NONE,
959 #else
960 			    (char_u *)NULL, PV_NONE,
961 #endif
962 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
963     {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
964 #ifdef FEAT_CSCOPE
965 			    (char_u *)&p_cst, PV_NONE,
966 #else
967 			    (char_u *)NULL, PV_NONE,
968 #endif
969 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
970     {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971 #ifdef FEAT_CSCOPE
972 			    (char_u *)&p_csto, PV_NONE,
973 #else
974 			    (char_u *)NULL, PV_NONE,
975 #endif
976 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
977     {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978 #ifdef FEAT_CSCOPE
979 			    (char_u *)&p_csverbose, PV_NONE,
980 #else
981 			    (char_u *)NULL, PV_NONE,
982 #endif
983 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
984     {"cursorbind",  "crb",  P_BOOL|P_VI_DEF,
985 #ifdef FEAT_CURSORBIND
986 			    (char_u *)VAR_WIN, PV_CRBIND,
987 #else
988 			    (char_u *)NULL, PV_NONE,
989 #endif
990 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
991     {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
992 #ifdef FEAT_SYN_HL
993 			    (char_u *)VAR_WIN, PV_CUC,
994 #else
995 			    (char_u *)NULL, PV_NONE,
996 #endif
997 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
998     {"cursorline",   "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
999 #ifdef FEAT_SYN_HL
1000 			    (char_u *)VAR_WIN, PV_CUL,
1001 #else
1002 			    (char_u *)NULL, PV_NONE,
1003 #endif
1004 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1005     {"debug",	    NULL,   P_STRING|P_VI_DEF,
1006 			    (char_u *)&p_debug, PV_NONE,
1007 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1008     {"define",	    "def",  P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
1009 #ifdef FEAT_FIND_ID
1010 			    (char_u *)&p_def, PV_DEF,
1011 			    {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
1012 #else
1013 			    (char_u *)NULL, PV_NONE,
1014 			    {(char_u *)NULL, (char_u *)0L}
1015 #endif
1016 			    SCRIPTID_INIT},
1017     {"delcombine", "deco",  P_BOOL|P_VI_DEF|P_VIM,
1018 #ifdef FEAT_MBYTE
1019 			    (char_u *)&p_deco, PV_NONE,
1020 #else
1021 			    (char_u *)NULL, PV_NONE,
1022 #endif
1023 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1024     {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
1025 #ifdef FEAT_INS_EXPAND
1026 			    (char_u *)&p_dict, PV_DICT,
1027 #else
1028 			    (char_u *)NULL, PV_NONE,
1029 #endif
1030 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1031     {"diff",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1032 #ifdef FEAT_DIFF
1033 			    (char_u *)VAR_WIN, PV_DIFF,
1034 #else
1035 			    (char_u *)NULL, PV_NONE,
1036 #endif
1037 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1038     {"diffexpr",    "dex",  P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
1039 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1040 			    (char_u *)&p_dex, PV_NONE,
1041 			    {(char_u *)"", (char_u *)0L}
1042 #else
1043 			    (char_u *)NULL, PV_NONE,
1044 			    {(char_u *)0L, (char_u *)0L}
1045 #endif
1046 			    SCRIPTID_INIT},
1047     {"diffopt",	    "dip",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1048 								     |P_NODUP,
1049 #ifdef FEAT_DIFF
1050 			    (char_u *)&p_dip, PV_NONE,
1051 			    {(char_u *)"filler", (char_u *)NULL}
1052 #else
1053 			    (char_u *)NULL, PV_NONE,
1054 			    {(char_u *)"", (char_u *)NULL}
1055 #endif
1056 			    SCRIPTID_INIT},
1057     {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
1058 #ifdef FEAT_DIGRAPHS
1059 			    (char_u *)&p_dg, PV_NONE,
1060 #else
1061 			    (char_u *)NULL, PV_NONE,
1062 #endif
1063 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1064     {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1065 							    |P_NODUP|P_SECURE,
1066 			    (char_u *)&p_dir, PV_NONE,
1067 			    {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
1068     {"display",	    "dy",   P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
1069 			    (char_u *)&p_dy, PV_NONE,
1070 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1071     {"eadirection", "ead",  P_STRING|P_VI_DEF,
1072 #ifdef FEAT_WINDOWS
1073 			    (char_u *)&p_ead, PV_NONE,
1074 			    {(char_u *)"both", (char_u *)0L}
1075 #else
1076 			    (char_u *)NULL, PV_NONE,
1077 			    {(char_u *)NULL, (char_u *)0L}
1078 #endif
1079 			    SCRIPTID_INIT},
1080     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
1081 			    (char_u *)&p_ed, PV_NONE,
1082 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1083     {"emoji",  "emo",	    P_BOOL|P_VI_DEF|P_RCLR,
1084 #if defined(FEAT_MBYTE)
1085 			    (char_u *)&p_emoji, PV_NONE,
1086 			    {(char_u *)TRUE, (char_u *)0L}
1087 #else
1088 			    (char_u *)NULL, PV_NONE,
1089 			    {(char_u *)0L, (char_u *)0L}
1090 #endif
1091 			    SCRIPTID_INIT},
1092     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
1093 #ifdef FEAT_MBYTE
1094 			    (char_u *)&p_enc, PV_NONE,
1095 			    {(char_u *)ENC_DFLT, (char_u *)0L}
1096 #else
1097 			    (char_u *)NULL, PV_NONE,
1098 			    {(char_u *)0L, (char_u *)0L}
1099 #endif
1100 			    SCRIPTID_INIT},
1101     {"endofline",   "eol",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1102 			    (char_u *)&p_eol, PV_EOL,
1103 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1104     {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
1105 			    (char_u *)&p_ea, PV_NONE,
1106 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1107     {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1108 			    (char_u *)&p_ep, PV_EP,
1109 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1110     {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
1111 			    (char_u *)&p_eb, PV_NONE,
1112 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1113     {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1114 #ifdef FEAT_QUICKFIX
1115 			    (char_u *)&p_ef, PV_NONE,
1116 			    {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1117 #else
1118 			    (char_u *)NULL, PV_NONE,
1119 			    {(char_u *)NULL, (char_u *)0L}
1120 #endif
1121 			    SCRIPTID_INIT},
1122     {"errorformat", "efm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1123 #ifdef FEAT_QUICKFIX
1124 			    (char_u *)&p_efm, PV_EFM,
1125 			    {(char_u *)DFLT_EFM, (char_u *)0L}
1126 #else
1127 			    (char_u *)NULL, PV_NONE,
1128 			    {(char_u *)NULL, (char_u *)0L}
1129 #endif
1130 			    SCRIPTID_INIT},
1131     {"esckeys",	    "ek",   P_BOOL|P_VIM,
1132 			    (char_u *)&p_ek, PV_NONE,
1133 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1134     {"eventignore", "ei",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1135 #ifdef FEAT_AUTOCMD
1136 			    (char_u *)&p_ei, PV_NONE,
1137 #else
1138 			    (char_u *)NULL, PV_NONE,
1139 #endif
1140 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1141     {"expandtab",   "et",   P_BOOL|P_VI_DEF|P_VIM,
1142 			    (char_u *)&p_et, PV_ET,
1143 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1144     {"exrc",	    "ex",   P_BOOL|P_VI_DEF|P_SECURE,
1145 			    (char_u *)&p_exrc, PV_NONE,
1146 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1147     {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1148 								   |P_NO_MKRC,
1149 #ifdef FEAT_MBYTE
1150 			    (char_u *)&p_fenc, PV_FENC,
1151 			    {(char_u *)"", (char_u *)0L}
1152 #else
1153 			    (char_u *)NULL, PV_NONE,
1154 			    {(char_u *)0L, (char_u *)0L}
1155 #endif
1156 			    SCRIPTID_INIT},
1157     {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
1158 #ifdef FEAT_MBYTE
1159 			    (char_u *)&p_fencs, PV_NONE,
1160 			    {(char_u *)"ucs-bom", (char_u *)0L}
1161 #else
1162 			    (char_u *)NULL, PV_NONE,
1163 			    {(char_u *)0L, (char_u *)0L}
1164 #endif
1165 			    SCRIPTID_INIT},
1166     {"fileformat",  "ff",   P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1167 								  |P_CURSWANT,
1168 			    (char_u *)&p_ff, PV_FF,
1169 			    {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
1170     {"fileformats", "ffs",  P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
1171 			    (char_u *)&p_ffs, PV_NONE,
1172 			    {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1173 			    SCRIPTID_INIT},
1174     {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1175 			    (char_u *)&p_fic, PV_NONE,
1176 			    {
1177 #ifdef CASE_INSENSITIVE_FILENAME
1178 				    (char_u *)TRUE,
1179 #else
1180 				    (char_u *)FALSE,
1181 #endif
1182 					(char_u *)0L} SCRIPTID_INIT},
1183     {"filetype",    "ft",   P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
1184 #ifdef FEAT_AUTOCMD
1185 			    (char_u *)&p_ft, PV_FT,
1186 			    {(char_u *)"", (char_u *)0L}
1187 #else
1188 			    (char_u *)NULL, PV_NONE,
1189 			    {(char_u *)0L, (char_u *)0L}
1190 #endif
1191 			    SCRIPTID_INIT},
1192     {"fillchars",   "fcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1193 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1194 			    (char_u *)&p_fcs, PV_NONE,
1195 			    {(char_u *)"vert:|,fold:-", (char_u *)0L}
1196 #else
1197 			    (char_u *)NULL, PV_NONE,
1198 			    {(char_u *)"", (char_u *)0L}
1199 #endif
1200 			    SCRIPTID_INIT},
1201     {"fixendofline",  "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1202 			    (char_u *)&p_fixeol, PV_FIXEOL,
1203 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1204     {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
1205 #ifdef FEAT_FKMAP
1206 			    (char_u *)&p_fkmap, PV_NONE,
1207 #else
1208 			    (char_u *)NULL, PV_NONE,
1209 #endif
1210 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1211     {"flash",	    "fl",   P_BOOL|P_VI_DEF,
1212 			    (char_u *)NULL, PV_NONE,
1213 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1214     {"foldclose",   "fcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
1215 #ifdef FEAT_FOLDING
1216 			    (char_u *)&p_fcl, PV_NONE,
1217 			    {(char_u *)"", (char_u *)0L}
1218 #else
1219 			    (char_u *)NULL, PV_NONE,
1220 			    {(char_u *)NULL, (char_u *)0L}
1221 #endif
1222 			    SCRIPTID_INIT},
1223     {"foldcolumn",  "fdc",  P_NUM|P_VI_DEF|P_RWIN,
1224 #ifdef FEAT_FOLDING
1225 			    (char_u *)VAR_WIN, PV_FDC,
1226 			    {(char_u *)FALSE, (char_u *)0L}
1227 #else
1228 			    (char_u *)NULL, PV_NONE,
1229 			    {(char_u *)NULL, (char_u *)0L}
1230 #endif
1231 			    SCRIPTID_INIT},
1232     {"foldenable",  "fen",  P_BOOL|P_VI_DEF|P_RWIN,
1233 #ifdef FEAT_FOLDING
1234 			    (char_u *)VAR_WIN, PV_FEN,
1235 			    {(char_u *)TRUE, (char_u *)0L}
1236 #else
1237 			    (char_u *)NULL, PV_NONE,
1238 			    {(char_u *)NULL, (char_u *)0L}
1239 #endif
1240 			    SCRIPTID_INIT},
1241     {"foldexpr",    "fde",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1242 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1243 			    (char_u *)VAR_WIN, PV_FDE,
1244 			    {(char_u *)"0", (char_u *)NULL}
1245 #else
1246 			    (char_u *)NULL, PV_NONE,
1247 			    {(char_u *)NULL, (char_u *)0L}
1248 #endif
1249 			    SCRIPTID_INIT},
1250     {"foldignore",  "fdi",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1251 #ifdef FEAT_FOLDING
1252 			    (char_u *)VAR_WIN, PV_FDI,
1253 			    {(char_u *)"#", (char_u *)NULL}
1254 #else
1255 			    (char_u *)NULL, PV_NONE,
1256 			    {(char_u *)NULL, (char_u *)0L}
1257 #endif
1258 			    SCRIPTID_INIT},
1259     {"foldlevel",   "fdl",  P_NUM|P_VI_DEF|P_RWIN,
1260 #ifdef FEAT_FOLDING
1261 			    (char_u *)VAR_WIN, PV_FDL,
1262 			    {(char_u *)0L, (char_u *)0L}
1263 #else
1264 			    (char_u *)NULL, PV_NONE,
1265 			    {(char_u *)NULL, (char_u *)0L}
1266 #endif
1267 			    SCRIPTID_INIT},
1268     {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
1269 #ifdef FEAT_FOLDING
1270 			    (char_u *)&p_fdls, PV_NONE,
1271 			    {(char_u *)-1L, (char_u *)0L}
1272 #else
1273 			    (char_u *)NULL, PV_NONE,
1274 			    {(char_u *)NULL, (char_u *)0L}
1275 #endif
1276 			    SCRIPTID_INIT},
1277     {"foldmarker",  "fmr",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1278 						    P_RWIN|P_ONECOMMA|P_NODUP,
1279 #ifdef FEAT_FOLDING
1280 			    (char_u *)VAR_WIN, PV_FMR,
1281 			    {(char_u *)"{{{,}}}", (char_u *)NULL}
1282 #else
1283 			    (char_u *)NULL, PV_NONE,
1284 			    {(char_u *)NULL, (char_u *)0L}
1285 #endif
1286 			    SCRIPTID_INIT},
1287     {"foldmethod",  "fdm",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1288 #ifdef FEAT_FOLDING
1289 			    (char_u *)VAR_WIN, PV_FDM,
1290 			    {(char_u *)"manual", (char_u *)NULL}
1291 #else
1292 			    (char_u *)NULL, PV_NONE,
1293 			    {(char_u *)NULL, (char_u *)0L}
1294 #endif
1295 			    SCRIPTID_INIT},
1296     {"foldminlines","fml",  P_NUM|P_VI_DEF|P_RWIN,
1297 #ifdef FEAT_FOLDING
1298 			    (char_u *)VAR_WIN, PV_FML,
1299 			    {(char_u *)1L, (char_u *)0L}
1300 #else
1301 			    (char_u *)NULL, PV_NONE,
1302 			    {(char_u *)NULL, (char_u *)0L}
1303 #endif
1304 			    SCRIPTID_INIT},
1305     {"foldnestmax", "fdn",  P_NUM|P_VI_DEF|P_RWIN,
1306 #ifdef FEAT_FOLDING
1307 			    (char_u *)VAR_WIN, PV_FDN,
1308 			    {(char_u *)20L, (char_u *)0L}
1309 #else
1310 			    (char_u *)NULL, PV_NONE,
1311 			    {(char_u *)NULL, (char_u *)0L}
1312 #endif
1313 			    SCRIPTID_INIT},
1314     {"foldopen",    "fdo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1315 #ifdef FEAT_FOLDING
1316 			    (char_u *)&p_fdo, PV_NONE,
1317 		 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1318 						 (char_u *)0L}
1319 #else
1320 			    (char_u *)NULL, PV_NONE,
1321 			    {(char_u *)NULL, (char_u *)0L}
1322 #endif
1323 			    SCRIPTID_INIT},
1324     {"foldtext",    "fdt",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1325 #if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1326 			    (char_u *)VAR_WIN, PV_FDT,
1327 			    {(char_u *)"foldtext()", (char_u *)NULL}
1328 #else
1329 			    (char_u *)NULL, PV_NONE,
1330 			    {(char_u *)NULL, (char_u *)0L}
1331 #endif
1332 			    SCRIPTID_INIT},
1333     {"formatexpr", "fex",   P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1334 #ifdef FEAT_EVAL
1335 			    (char_u *)&p_fex, PV_FEX,
1336 			    {(char_u *)"", (char_u *)0L}
1337 #else
1338 			    (char_u *)NULL, PV_NONE,
1339 			    {(char_u *)0L, (char_u *)0L}
1340 #endif
1341 			    SCRIPTID_INIT},
1342     {"formatoptions","fo",  P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1343 			    (char_u *)&p_fo, PV_FO,
1344 			    {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1345 			    SCRIPTID_INIT},
1346     {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1347 			    (char_u *)&p_flp, PV_FLP,
1348 			    {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1349 						 (char_u *)0L} SCRIPTID_INIT},
1350     {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1351 			    (char_u *)&p_fp, PV_FP,
1352 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1353     {"fsync",       "fs",   P_BOOL|P_SECURE|P_VI_DEF,
1354 #ifdef HAVE_FSYNC
1355 			    (char_u *)&p_fs, PV_NONE,
1356 			    {(char_u *)TRUE, (char_u *)0L}
1357 #else
1358 			    (char_u *)NULL, PV_NONE,
1359 			    {(char_u *)FALSE, (char_u *)0L}
1360 #endif
1361 			    SCRIPTID_INIT},
1362     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
1363 			    (char_u *)&p_gd, PV_NONE,
1364 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1365     {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
1366 			    (char_u *)NULL, PV_NONE,
1367 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1368     {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1369 #ifdef FEAT_QUICKFIX
1370 			    (char_u *)&p_gefm, PV_NONE,
1371 			    {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
1372 #else
1373 			    (char_u *)NULL, PV_NONE,
1374 			    {(char_u *)NULL, (char_u *)0L}
1375 #endif
1376 			    SCRIPTID_INIT},
1377     {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1378 #ifdef FEAT_QUICKFIX
1379 			    (char_u *)&p_gp, PV_GP,
1380 			    {
1381 # ifdef WIN3264
1382 			    /* may be changed to "grep -n" in os_win32.c */
1383 			    (char_u *)"findstr /n",
1384 # else
1385 #  ifdef UNIX
1386 			    /* Add an extra file name so that grep will always
1387 			     * insert a file name in the match line. */
1388 			    (char_u *)"grep -n $* /dev/null",
1389 #  else
1390 #   ifdef VMS
1391 			    (char_u *)"SEARCH/NUMBERS ",
1392 #   else
1393 			    (char_u *)"grep -n ",
1394 #   endif
1395 #  endif
1396 # endif
1397 			    (char_u *)0L}
1398 #else
1399 			    (char_u *)NULL, PV_NONE,
1400 			    {(char_u *)NULL, (char_u *)0L}
1401 #endif
1402 			    SCRIPTID_INIT},
1403     {"guicursor",    "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1404 #ifdef CURSOR_SHAPE
1405 			    (char_u *)&p_guicursor, PV_NONE,
1406 			    {
1407 # ifdef FEAT_GUI
1408 				(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",
1409 # else	/* Win32 console */
1410 				(char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1411 # endif
1412 				    (char_u *)0L}
1413 #else
1414 			    (char_u *)NULL, PV_NONE,
1415 			    {(char_u *)NULL, (char_u *)0L}
1416 #endif
1417 			    SCRIPTID_INIT},
1418     {"guifont",	    "gfn",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1419 #ifdef FEAT_GUI
1420 			    (char_u *)&p_guifont, PV_NONE,
1421 			    {(char_u *)"", (char_u *)0L}
1422 #else
1423 			    (char_u *)NULL, PV_NONE,
1424 			    {(char_u *)NULL, (char_u *)0L}
1425 #endif
1426 			    SCRIPTID_INIT},
1427     {"guifontset",  "gfs",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
1428 #if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1429 			    (char_u *)&p_guifontset, PV_NONE,
1430 			    {(char_u *)"", (char_u *)0L}
1431 #else
1432 			    (char_u *)NULL, PV_NONE,
1433 			    {(char_u *)NULL, (char_u *)0L}
1434 #endif
1435 			    SCRIPTID_INIT},
1436     {"guifontwide", "gfw",  P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1437 #if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1438 			    (char_u *)&p_guifontwide, PV_NONE,
1439 			    {(char_u *)"", (char_u *)0L}
1440 #else
1441 			    (char_u *)NULL, PV_NONE,
1442 			    {(char_u *)NULL, (char_u *)0L}
1443 #endif
1444 			    SCRIPTID_INIT},
1445     {"guiheadroom", "ghr",  P_NUM|P_VI_DEF,
1446 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
1447 			    (char_u *)&p_ghr, PV_NONE,
1448 #else
1449 			    (char_u *)NULL, PV_NONE,
1450 #endif
1451 			    {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
1452     {"guioptions",  "go",   P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
1453 #if defined(FEAT_GUI)
1454 			    (char_u *)&p_go, PV_NONE,
1455 # if defined(UNIX) && !defined(MACOS)
1456 			    {(char_u *)"aegimrLtT", (char_u *)0L}
1457 # else
1458 			    {(char_u *)"egmrLtT", (char_u *)0L}
1459 # endif
1460 #else
1461 			    (char_u *)NULL, PV_NONE,
1462 			    {(char_u *)NULL, (char_u *)0L}
1463 #endif
1464 			    SCRIPTID_INIT},
1465     {"guipty",	    NULL,   P_BOOL|P_VI_DEF,
1466 #if defined(FEAT_GUI)
1467 			    (char_u *)&p_guipty, PV_NONE,
1468 #else
1469 			    (char_u *)NULL, PV_NONE,
1470 #endif
1471 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1472     {"guitablabel",  "gtl", P_STRING|P_VI_DEF|P_RWIN,
1473 #if defined(FEAT_GUI_TABLINE)
1474 			    (char_u *)&p_gtl, PV_NONE,
1475 			    {(char_u *)"", (char_u *)0L}
1476 #else
1477 			    (char_u *)NULL, PV_NONE,
1478 			    {(char_u *)NULL, (char_u *)0L}
1479 #endif
1480 			    SCRIPTID_INIT},
1481     {"guitabtooltip",  "gtt", P_STRING|P_VI_DEF|P_RWIN,
1482 #if defined(FEAT_GUI_TABLINE)
1483 			    (char_u *)&p_gtt, PV_NONE,
1484 			    {(char_u *)"", (char_u *)0L}
1485 #else
1486 			    (char_u *)NULL, PV_NONE,
1487 			    {(char_u *)NULL, (char_u *)0L}
1488 #endif
1489 			    SCRIPTID_INIT},
1490     {"hardtabs",    "ht",   P_NUM|P_VI_DEF,
1491 			    (char_u *)NULL, PV_NONE,
1492 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
1493     {"helpfile",    "hf",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1494 			    (char_u *)&p_hf, PV_NONE,
1495 			    {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1496 			    SCRIPTID_INIT},
1497     {"helpheight",  "hh",   P_NUM|P_VI_DEF,
1498 #ifdef FEAT_WINDOWS
1499 			    (char_u *)&p_hh, PV_NONE,
1500 #else
1501 			    (char_u *)NULL, PV_NONE,
1502 #endif
1503 			    {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
1504     {"helplang",    "hlg",  P_STRING|P_VI_DEF|P_ONECOMMA,
1505 #ifdef FEAT_MULTI_LANG
1506 			    (char_u *)&p_hlg, PV_NONE,
1507 			    {(char_u *)"", (char_u *)0L}
1508 #else
1509 			    (char_u *)NULL, PV_NONE,
1510 			    {(char_u *)0L, (char_u *)0L}
1511 #endif
1512 			    SCRIPTID_INIT},
1513     {"hidden",	    "hid",  P_BOOL|P_VI_DEF,
1514 			    (char_u *)&p_hid, PV_NONE,
1515 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1516     {"highlight",   "hl",   P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
1517 			    (char_u *)&p_hl, PV_NONE,
1518 			    {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1519 			    SCRIPTID_INIT},
1520     {"history",	    "hi",   P_NUM|P_VIM,
1521 			    (char_u *)&p_hi, PV_NONE,
1522 			    {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
1523     {"hkmap",	    "hk",   P_BOOL|P_VI_DEF|P_VIM,
1524 #ifdef FEAT_RIGHTLEFT
1525 			    (char_u *)&p_hkmap, PV_NONE,
1526 #else
1527 			    (char_u *)NULL, PV_NONE,
1528 #endif
1529 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1530     {"hkmapp",	    "hkp",  P_BOOL|P_VI_DEF|P_VIM,
1531 #ifdef FEAT_RIGHTLEFT
1532 			    (char_u *)&p_hkmapp, PV_NONE,
1533 #else
1534 			    (char_u *)NULL, PV_NONE,
1535 #endif
1536 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1537     {"hlsearch",    "hls",  P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1538 			    (char_u *)&p_hls, PV_NONE,
1539 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1540     {"icon",	    NULL,   P_BOOL|P_VI_DEF,
1541 #ifdef FEAT_TITLE
1542 			    (char_u *)&p_icon, PV_NONE,
1543 #else
1544 			    (char_u *)NULL, PV_NONE,
1545 #endif
1546 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1547     {"iconstring",  NULL,   P_STRING|P_VI_DEF,
1548 #ifdef FEAT_TITLE
1549 			    (char_u *)&p_iconstring, PV_NONE,
1550 #else
1551 			    (char_u *)NULL, PV_NONE,
1552 #endif
1553 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1554     {"ignorecase",  "ic",   P_BOOL|P_VI_DEF,
1555 			    (char_u *)&p_ic, PV_NONE,
1556 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1557     {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1558 # if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1559 			    (char_u *)&p_imaf, PV_NONE,
1560 			    {(char_u *)"", (char_u *)NULL}
1561 # else
1562 			    (char_u *)NULL, PV_NONE,
1563 			    {(char_u *)NULL, (char_u *)0L}
1564 # endif
1565 			    SCRIPTID_INIT},
1566     {"imactivatekey","imak",P_STRING|P_VI_DEF,
1567 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1568 			    (char_u *)&p_imak, PV_NONE,
1569 #else
1570 			    (char_u *)NULL, PV_NONE,
1571 #endif
1572 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1573     {"imcmdline",   "imc",  P_BOOL|P_VI_DEF,
1574 #ifdef USE_IM_CONTROL
1575 			    (char_u *)&p_imcmdline, PV_NONE,
1576 #else
1577 			    (char_u *)NULL, PV_NONE,
1578 #endif
1579 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1580     {"imdisable",   "imd",  P_BOOL|P_VI_DEF,
1581 #ifdef USE_IM_CONTROL
1582 			    (char_u *)&p_imdisable, PV_NONE,
1583 #else
1584 			    (char_u *)NULL, PV_NONE,
1585 #endif
1586 #ifdef __sgi
1587 			    {(char_u *)TRUE, (char_u *)0L}
1588 #else
1589 			    {(char_u *)FALSE, (char_u *)0L}
1590 #endif
1591 			    SCRIPTID_INIT},
1592     {"iminsert",    "imi",  P_NUM|P_VI_DEF,
1593 			    (char_u *)&p_iminsert, PV_IMI,
1594 #ifdef B_IMODE_IM
1595 			    {(char_u *)B_IMODE_IM, (char_u *)0L}
1596 #else
1597 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1598 #endif
1599 			    SCRIPTID_INIT},
1600     {"imsearch",    "ims",  P_NUM|P_VI_DEF,
1601 			    (char_u *)&p_imsearch, PV_IMS,
1602 #ifdef B_IMODE_IM
1603 			    {(char_u *)B_IMODE_IM, (char_u *)0L}
1604 #else
1605 			    {(char_u *)B_IMODE_NONE, (char_u *)0L}
1606 #endif
1607 			    SCRIPTID_INIT},
1608     {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
1609 # if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1610 			    (char_u *)&p_imsf, PV_NONE,
1611 			    {(char_u *)"", (char_u *)NULL}
1612 # else
1613 			    (char_u *)NULL, PV_NONE,
1614 			    {(char_u *)NULL, (char_u *)0L}
1615 # endif
1616 			    SCRIPTID_INIT},
1617     {"include",	    "inc",  P_STRING|P_ALLOCED|P_VI_DEF,
1618 #ifdef FEAT_FIND_ID
1619 			    (char_u *)&p_inc, PV_INC,
1620 			    {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1621 #else
1622 			    (char_u *)NULL, PV_NONE,
1623 			    {(char_u *)0L, (char_u *)0L}
1624 #endif
1625 			    SCRIPTID_INIT},
1626     {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1627 #if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1628 			    (char_u *)&p_inex, PV_INEX,
1629 			    {(char_u *)"", (char_u *)0L}
1630 #else
1631 			    (char_u *)NULL, PV_NONE,
1632 			    {(char_u *)0L, (char_u *)0L}
1633 #endif
1634 			    SCRIPTID_INIT},
1635     {"incsearch",   "is",   P_BOOL|P_VI_DEF|P_VIM,
1636 			    (char_u *)&p_is, PV_NONE,
1637 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1638     {"indentexpr", "inde",  P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1639 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1640 			    (char_u *)&p_inde, PV_INDE,
1641 			    {(char_u *)"", (char_u *)0L}
1642 #else
1643 			    (char_u *)NULL, PV_NONE,
1644 			    {(char_u *)0L, (char_u *)0L}
1645 #endif
1646 			    SCRIPTID_INIT},
1647     {"indentkeys", "indk",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1648 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1649 			    (char_u *)&p_indk, PV_INDK,
1650 			    {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1651 #else
1652 			    (char_u *)NULL, PV_NONE,
1653 			    {(char_u *)0L, (char_u *)0L}
1654 #endif
1655 			    SCRIPTID_INIT},
1656     {"infercase",   "inf",  P_BOOL|P_VI_DEF,
1657 			    (char_u *)&p_inf, PV_INF,
1658 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1659     {"insertmode",  "im",   P_BOOL|P_VI_DEF|P_VIM,
1660 			    (char_u *)&p_im, PV_NONE,
1661 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1662     {"isfname",	    "isf",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1663 			    (char_u *)&p_isf, PV_NONE,
1664 			    {
1665 #ifdef BACKSLASH_IN_FILENAME
1666 				/* Excluded are: & and ^ are special in cmd.exe
1667 				 * ( and ) are used in text separating fnames */
1668 			    (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1669 #else
1670 # ifdef AMIGA
1671 			    (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1672 # else
1673 #  ifdef VMS
1674 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1675 #  else /* UNIX et al. */
1676 #   ifdef EBCDIC
1677 			    (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1678 #   else
1679 			    (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1680 #   endif
1681 #  endif
1682 # endif
1683 #endif
1684 				(char_u *)0L} SCRIPTID_INIT},
1685     {"isident",	    "isi",  P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1686 			    (char_u *)&p_isi, PV_NONE,
1687 			    {
1688 #if defined(MSWIN)
1689 			    (char_u *)"@,48-57,_,128-167,224-235",
1690 #else
1691 # ifdef EBCDIC
1692 			    /* TODO: EBCDIC Check this! @ == isalpha()*/
1693 			    (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1694 				    "112-120,128,140-142,156,158,172,"
1695 				    "174,186,191,203-207,219-225,235-239,"
1696 				    "251-254",
1697 # else
1698 			    (char_u *)"@,48-57,_,192-255",
1699 # endif
1700 #endif
1701 				(char_u *)0L} SCRIPTID_INIT},
1702     {"iskeyword",   "isk",  P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1703 			    (char_u *)&p_isk, PV_ISK,
1704 			    {
1705 #ifdef EBCDIC
1706 			     (char_u *)"@,240-249,_",
1707 			     /* TODO: EBCDIC Check this! @ == isalpha()*/
1708 			     (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1709 				    "112-120,128,140-142,156,158,172,"
1710 				    "174,186,191,203-207,219-225,235-239,"
1711 				    "251-254",
1712 #else
1713 				(char_u *)"@,48-57,_",
1714 # if defined(MSWIN)
1715 				(char_u *)"@,48-57,_,128-167,224-235"
1716 # else
1717 				ISK_LATIN1
1718 # endif
1719 #endif
1720 			    } SCRIPTID_INIT},
1721     {"isprint",	    "isp",  P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1722 			    (char_u *)&p_isp, PV_NONE,
1723 			    {
1724 #if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
1725 		|| defined(VMS)
1726 			    (char_u *)"@,~-255",
1727 #else
1728 # ifdef EBCDIC
1729 			    /* all chars above 63 are printable */
1730 			    (char_u *)"63-255",
1731 # else
1732 			    ISP_LATIN1,
1733 # endif
1734 #endif
1735 				(char_u *)0L} SCRIPTID_INIT},
1736     {"joinspaces",  "js",   P_BOOL|P_VI_DEF|P_VIM,
1737 			    (char_u *)&p_js, PV_NONE,
1738 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1739     {"key",	    NULL,   P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1740 #ifdef FEAT_CRYPT
1741 			    (char_u *)&p_key, PV_KEY,
1742 			    {(char_u *)"", (char_u *)0L}
1743 #else
1744 			    (char_u *)NULL, PV_NONE,
1745 			    {(char_u *)0L, (char_u *)0L}
1746 #endif
1747 			    SCRIPTID_INIT},
1748     {"keymap",	    "kmp",  P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
1749 #ifdef FEAT_KEYMAP
1750 			    (char_u *)&p_keymap, PV_KMAP,
1751 			    {(char_u *)"", (char_u *)0L}
1752 #else
1753 			    (char_u *)NULL, PV_NONE,
1754 			    {(char_u *)"", (char_u *)0L}
1755 #endif
1756 			    SCRIPTID_INIT},
1757     {"keymodel",    "km",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1758 			    (char_u *)&p_km, PV_NONE,
1759 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1760     {"keywordprg",  "kp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1761 			    (char_u *)&p_kp, PV_KP,
1762 			    {
1763 #ifdef MSWIN
1764 			    (char_u *)":help",
1765 #else
1766 # ifdef VMS
1767 			    (char_u *)"help",
1768 # else
1769 #  ifdef USEMAN_S
1770 			    (char_u *)"man -s",
1771 #  else
1772 			    (char_u *)"man",
1773 #  endif
1774 # endif
1775 #endif
1776 				(char_u *)0L} SCRIPTID_INIT},
1777     {"langmap",     "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
1778 #ifdef FEAT_LANGMAP
1779 			    (char_u *)&p_langmap, PV_NONE,
1780 			    {(char_u *)"",	/* unmatched } */
1781 #else
1782 			    (char_u *)NULL, PV_NONE,
1783 			    {(char_u *)NULL,
1784 #endif
1785 				(char_u *)0L} SCRIPTID_INIT},
1786     {"langmenu",    "lm",   P_STRING|P_VI_DEF|P_NFNAME,
1787 #if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1788 			    (char_u *)&p_lm, PV_NONE,
1789 #else
1790 			    (char_u *)NULL, PV_NONE,
1791 #endif
1792 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1793     {"langnoremap",  "lnr",   P_BOOL|P_VI_DEF,
1794 #ifdef FEAT_LANGMAP
1795 			    (char_u *)&p_lnr, PV_NONE,
1796 #else
1797 			    (char_u *)NULL, PV_NONE,
1798 #endif
1799 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1800     {"langremap",  "lrm",   P_BOOL|P_VI_DEF,
1801 #ifdef FEAT_LANGMAP
1802 			    (char_u *)&p_lrm, PV_NONE,
1803 #else
1804 			    (char_u *)NULL, PV_NONE,
1805 #endif
1806 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1807     {"laststatus",  "ls",   P_NUM|P_VI_DEF|P_RALL,
1808 #ifdef FEAT_WINDOWS
1809 			    (char_u *)&p_ls, PV_NONE,
1810 #else
1811 			    (char_u *)NULL, PV_NONE,
1812 #endif
1813 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
1814     {"lazyredraw",  "lz",   P_BOOL|P_VI_DEF,
1815 			    (char_u *)&p_lz, PV_NONE,
1816 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1817     {"linebreak",   "lbr",  P_BOOL|P_VI_DEF|P_RWIN,
1818 #ifdef FEAT_LINEBREAK
1819 			    (char_u *)VAR_WIN, PV_LBR,
1820 #else
1821 			    (char_u *)NULL, PV_NONE,
1822 #endif
1823 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1824     {"lines",	    NULL,   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1825 			    (char_u *)&Rows, PV_NONE,
1826 			    {
1827 #if defined(WIN3264)
1828 			    (char_u *)25L,
1829 #else
1830 			    (char_u *)24L,
1831 #endif
1832 					    (char_u *)0L} SCRIPTID_INIT},
1833     {"linespace",   "lsp",  P_NUM|P_VI_DEF|P_RCLR,
1834 #ifdef FEAT_GUI
1835 			    (char_u *)&p_linespace, PV_NONE,
1836 #else
1837 			    (char_u *)NULL, PV_NONE,
1838 #endif
1839 #ifdef FEAT_GUI_W32
1840 			    {(char_u *)1L, (char_u *)0L}
1841 #else
1842 			    {(char_u *)0L, (char_u *)0L}
1843 #endif
1844 			    SCRIPTID_INIT},
1845     {"lisp",	    NULL,   P_BOOL|P_VI_DEF,
1846 #ifdef FEAT_LISP
1847 			    (char_u *)&p_lisp, PV_LISP,
1848 #else
1849 			    (char_u *)NULL, PV_NONE,
1850 #endif
1851 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1852     {"lispwords",   "lw",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
1853 #ifdef FEAT_LISP
1854 			    (char_u *)&p_lispwords, PV_LW,
1855 			    {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1856 #else
1857 			    (char_u *)NULL, PV_NONE,
1858 			    {(char_u *)"", (char_u *)0L}
1859 #endif
1860 			    SCRIPTID_INIT},
1861     {"list",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
1862 			    (char_u *)VAR_WIN, PV_LIST,
1863 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1864     {"listchars",   "lcs",  P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
1865 			    (char_u *)&p_lcs, PV_NONE,
1866 			    {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
1867     {"loadplugins", "lpl",  P_BOOL|P_VI_DEF,
1868 			    (char_u *)&p_lpl, PV_NONE,
1869 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1870     {"luadll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1871 #if defined(DYNAMIC_LUA)
1872 			    (char_u *)&p_luadll, PV_NONE,
1873 			    {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1874 #else
1875 			    (char_u *)NULL, PV_NONE,
1876 			    {(char_u *)"", (char_u *)0L}
1877 #endif
1878 			    SCRIPTID_INIT},
1879     {"macatsui",    NULL,   P_BOOL|P_VI_DEF|P_RCLR,
1880 #ifdef FEAT_GUI_MAC
1881 			    (char_u *)&p_macatsui, PV_NONE,
1882 			    {(char_u *)TRUE, (char_u *)0L}
1883 #else
1884 			    (char_u *)NULL, PV_NONE,
1885 			    {(char_u *)"", (char_u *)0L}
1886 #endif
1887 			    SCRIPTID_INIT},
1888     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
1889 			    (char_u *)&p_magic, PV_NONE,
1890 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1891     {"makeef",	    "mef",  P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1892 #ifdef FEAT_QUICKFIX
1893 			    (char_u *)&p_mef, PV_NONE,
1894 			    {(char_u *)"", (char_u *)0L}
1895 #else
1896 			    (char_u *)NULL, PV_NONE,
1897 			    {(char_u *)NULL, (char_u *)0L}
1898 #endif
1899 			    SCRIPTID_INIT},
1900     {"makeencoding","menc", P_STRING|P_VI_DEF,
1901 #ifdef FEAT_MBYTE
1902 			    (char_u *)&p_menc, PV_MENC,
1903 			    {(char_u *)"", (char_u *)0L}
1904 #else
1905 			    (char_u *)NULL, PV_NONE,
1906 			    {(char_u *)0L, (char_u *)0L}
1907 #endif
1908 			    SCRIPTID_INIT},
1909     {"makeprg",	    "mp",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1910 #ifdef FEAT_QUICKFIX
1911 			    (char_u *)&p_mp, PV_MP,
1912 # ifdef VMS
1913 			    {(char_u *)"MMS", (char_u *)0L}
1914 # else
1915 			    {(char_u *)"make", (char_u *)0L}
1916 # endif
1917 #else
1918 			    (char_u *)NULL, PV_NONE,
1919 			    {(char_u *)NULL, (char_u *)0L}
1920 #endif
1921 			    SCRIPTID_INIT},
1922     {"matchpairs",  "mps",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
1923 			    (char_u *)&p_mps, PV_MPS,
1924 			    {(char_u *)"(:),{:},[:]", (char_u *)0L}
1925 			    SCRIPTID_INIT},
1926     {"matchtime",   "mat",  P_NUM|P_VI_DEF,
1927 			    (char_u *)&p_mat, PV_NONE,
1928 			    {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1929     {"maxcombine",  "mco",  P_NUM|P_VI_DEF|P_CURSWANT,
1930 #ifdef FEAT_MBYTE
1931 			    (char_u *)&p_mco, PV_NONE,
1932 #else
1933 			    (char_u *)NULL, PV_NONE,
1934 #endif
1935 			    {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
1936     {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1937 #ifdef FEAT_EVAL
1938 			    (char_u *)&p_mfd, PV_NONE,
1939 #else
1940 			    (char_u *)NULL, PV_NONE,
1941 #endif
1942 			    {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
1943     {"maxmapdepth", "mmd",  P_NUM|P_VI_DEF,
1944 			    (char_u *)&p_mmd, PV_NONE,
1945 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1946     {"maxmem",	    "mm",   P_NUM|P_VI_DEF,
1947 			    (char_u *)&p_mm, PV_NONE,
1948 			    {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1949 			    SCRIPTID_INIT},
1950     {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1951 			    (char_u *)&p_mmp, PV_NONE,
1952 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
1953     {"maxmemtot",   "mmt",  P_NUM|P_VI_DEF,
1954 			    (char_u *)&p_mmt, PV_NONE,
1955 			    {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1956 			    SCRIPTID_INIT},
1957     {"menuitems",   "mis",  P_NUM|P_VI_DEF,
1958 #ifdef FEAT_MENU
1959 			    (char_u *)&p_mis, PV_NONE,
1960 #else
1961 			    (char_u *)NULL, PV_NONE,
1962 #endif
1963 			    {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
1964     {"mesg",	    NULL,   P_BOOL|P_VI_DEF,
1965 			    (char_u *)NULL, PV_NONE,
1966 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1967     {"mkspellmem",  "msm",  P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
1968 #ifdef FEAT_SPELL
1969 			    (char_u *)&p_msm, PV_NONE,
1970 			    {(char_u *)"460000,2000,500", (char_u *)0L}
1971 #else
1972 			    (char_u *)NULL, PV_NONE,
1973 			    {(char_u *)0L, (char_u *)0L}
1974 #endif
1975 			    SCRIPTID_INIT},
1976     {"modeline",    "ml",   P_BOOL|P_VIM,
1977 			    (char_u *)&p_ml, PV_ML,
1978 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1979     {"modelines",   "mls",  P_NUM|P_VI_DEF,
1980 			    (char_u *)&p_mls, PV_NONE,
1981 			    {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
1982     {"modifiable",  "ma",   P_BOOL|P_VI_DEF|P_NOGLOB,
1983 			    (char_u *)&p_ma, PV_MA,
1984 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
1985     {"modified",    "mod",  P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1986 			    (char_u *)&p_mod, PV_MOD,
1987 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1988     {"more",	    NULL,   P_BOOL|P_VIM,
1989 			    (char_u *)&p_more, PV_NONE,
1990 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
1991     {"mouse",	    NULL,   P_STRING|P_VI_DEF|P_FLAGLIST,
1992 			    (char_u *)&p_mouse, PV_NONE,
1993 			    {
1994 #if defined(WIN3264)
1995 				(char_u *)"a",
1996 #else
1997 				(char_u *)"",
1998 #endif
1999 				(char_u *)0L} SCRIPTID_INIT},
2000     {"mousefocus",   "mousef", P_BOOL|P_VI_DEF,
2001 #ifdef FEAT_GUI
2002 			    (char_u *)&p_mousef, PV_NONE,
2003 #else
2004 			    (char_u *)NULL, PV_NONE,
2005 #endif
2006 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2007     {"mousehide",   "mh",   P_BOOL|P_VI_DEF,
2008 #ifdef FEAT_GUI
2009 			    (char_u *)&p_mh, PV_NONE,
2010 #else
2011 			    (char_u *)NULL, PV_NONE,
2012 #endif
2013 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2014     {"mousemodel",  "mousem", P_STRING|P_VI_DEF,
2015 			    (char_u *)&p_mousem, PV_NONE,
2016 			    {
2017 #if defined(MSWIN)
2018 				(char_u *)"popup",
2019 #else
2020 # if defined(MACOS)
2021 				(char_u *)"popup_setpos",
2022 # else
2023 				(char_u *)"extend",
2024 # endif
2025 #endif
2026 				(char_u *)0L} SCRIPTID_INIT},
2027     {"mouseshape",  "mouses",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2028 #ifdef FEAT_MOUSESHAPE
2029 			    (char_u *)&p_mouseshape, PV_NONE,
2030 			    {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2031 #else
2032 			    (char_u *)NULL, PV_NONE,
2033 			    {(char_u *)NULL, (char_u *)0L}
2034 #endif
2035 			    SCRIPTID_INIT},
2036     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
2037 			    (char_u *)&p_mouset, PV_NONE,
2038 			    {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
2039     {"mzquantum",  "mzq",   P_NUM,
2040 #ifdef FEAT_MZSCHEME
2041 			    (char_u *)&p_mzq, PV_NONE,
2042 #else
2043 			    (char_u *)NULL, PV_NONE,
2044 #endif
2045 			    {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
2046     {"novice",	    NULL,   P_BOOL|P_VI_DEF,
2047 			    (char_u *)NULL, PV_NONE,
2048 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2049     {"nrformats",   "nf",   P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
2050 			    (char_u *)&p_nf, PV_NF,
2051 			    {(char_u *)"bin,octal,hex", (char_u *)0L}
2052 			    SCRIPTID_INIT},
2053     {"number",	    "nu",   P_BOOL|P_VI_DEF|P_RWIN,
2054 			    (char_u *)VAR_WIN, PV_NU,
2055 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2056     {"numberwidth", "nuw",  P_NUM|P_RWIN|P_VIM,
2057 #ifdef FEAT_LINEBREAK
2058 			    (char_u *)VAR_WIN, PV_NUW,
2059 #else
2060 			    (char_u *)NULL, PV_NONE,
2061 #endif
2062 			    {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
2063     {"omnifunc",    "ofu",  P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2064 #ifdef FEAT_COMPL_FUNC
2065 			    (char_u *)&p_ofu, PV_OFU,
2066 			    {(char_u *)"", (char_u *)0L}
2067 #else
2068 			    (char_u *)NULL, PV_NONE,
2069 			    {(char_u *)0L, (char_u *)0L}
2070 #endif
2071 			    SCRIPTID_INIT},
2072     {"open",	    NULL,   P_BOOL|P_VI_DEF,
2073 			    (char_u *)NULL, PV_NONE,
2074 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2075     {"opendevice",  "odev", P_BOOL|P_VI_DEF,
2076 #if defined(MSWIN)
2077 			    (char_u *)&p_odev, PV_NONE,
2078 #else
2079 			    (char_u *)NULL, PV_NONE,
2080 #endif
2081 			    {(char_u *)FALSE, (char_u *)FALSE}
2082 			    SCRIPTID_INIT},
2083     {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2084 			    (char_u *)&p_opfunc, PV_NONE,
2085 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2086     {"optimize",    "opt",  P_BOOL|P_VI_DEF,
2087 			    (char_u *)NULL, PV_NONE,
2088 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2089     {"osfiletype",  "oft",  P_STRING|P_ALLOCED|P_VI_DEF,
2090 			    (char_u *)NULL, PV_NONE,
2091 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2092     {"packpath",    "pp",   P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2093 								    |P_SECURE,
2094 			    (char_u *)&p_pp, PV_NONE,
2095 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2096 			    SCRIPTID_INIT},
2097     {"paragraphs",  "para", P_STRING|P_VI_DEF,
2098 			    (char_u *)&p_para, PV_NONE,
2099 			    {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
2100 				(char_u *)0L} SCRIPTID_INIT},
2101     {"paste",	    NULL,   P_BOOL|P_VI_DEF|P_PRI_MKRC,
2102 			    (char_u *)&p_paste, PV_NONE,
2103 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2104     {"pastetoggle", "pt",   P_STRING|P_VI_DEF,
2105 			    (char_u *)&p_pt, PV_NONE,
2106 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2107     {"patchexpr",   "pex",  P_STRING|P_VI_DEF|P_SECURE,
2108 #if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2109 			    (char_u *)&p_pex, PV_NONE,
2110 			    {(char_u *)"", (char_u *)0L}
2111 #else
2112 			    (char_u *)NULL, PV_NONE,
2113 			    {(char_u *)0L, (char_u *)0L}
2114 #endif
2115 			    SCRIPTID_INIT},
2116     {"patchmode",   "pm",   P_STRING|P_VI_DEF|P_NFNAME,
2117 			    (char_u *)&p_pm, PV_NONE,
2118 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2119     {"path",	    "pa",   P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2120 			    (char_u *)&p_path, PV_PATH,
2121 			    {
2122 #if defined(AMIGA) || defined(MSWIN)
2123 			    (char_u *)".,,",
2124 #else
2125 			    (char_u *)".,/usr/include,,",
2126 #endif
2127 				(char_u *)0L} SCRIPTID_INIT},
2128     {"perldll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2129 #if defined(DYNAMIC_PERL)
2130 			    (char_u *)&p_perldll, PV_NONE,
2131 			    {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2132 #else
2133 			    (char_u *)NULL, PV_NONE,
2134 			    {(char_u *)0L, (char_u *)0L}
2135 #endif
2136 			    SCRIPTID_INIT},
2137     {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2138 			    (char_u *)&p_pi, PV_PI,
2139 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2140     {"previewheight", "pvh", P_NUM|P_VI_DEF,
2141 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2142 			    (char_u *)&p_pvh, PV_NONE,
2143 #else
2144 			    (char_u *)NULL, PV_NONE,
2145 #endif
2146 			    {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
2147     {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2148 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2149 			    (char_u *)VAR_WIN, PV_PVW,
2150 #else
2151 			    (char_u *)NULL, PV_NONE,
2152 #endif
2153 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2154     {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
2155 #ifdef FEAT_PRINTER
2156 			    (char_u *)&p_pdev, PV_NONE,
2157 			    {(char_u *)"", (char_u *)0L}
2158 #else
2159 			    (char_u *)NULL, PV_NONE,
2160 			    {(char_u *)NULL, (char_u *)0L}
2161 #endif
2162 			    SCRIPTID_INIT},
2163     {"printencoding", "penc", P_STRING|P_VI_DEF,
2164 #ifdef FEAT_POSTSCRIPT
2165 			    (char_u *)&p_penc, PV_NONE,
2166 			    {(char_u *)"", (char_u *)0L}
2167 #else
2168 			    (char_u *)NULL, PV_NONE,
2169 			    {(char_u *)NULL, (char_u *)0L}
2170 #endif
2171 			    SCRIPTID_INIT},
2172     {"printexpr", "pexpr",  P_STRING|P_VI_DEF|P_SECURE,
2173 #ifdef FEAT_POSTSCRIPT
2174 			    (char_u *)&p_pexpr, PV_NONE,
2175 			    {(char_u *)"", (char_u *)0L}
2176 #else
2177 			    (char_u *)NULL, PV_NONE,
2178 			    {(char_u *)NULL, (char_u *)0L}
2179 #endif
2180 			    SCRIPTID_INIT},
2181     {"printfont", "pfn",    P_STRING|P_VI_DEF,
2182 #ifdef FEAT_PRINTER
2183 			    (char_u *)&p_pfn, PV_NONE,
2184 			    {
2185 # ifdef MSWIN
2186 				(char_u *)"Courier_New:h10",
2187 # else
2188 				(char_u *)"courier",
2189 # endif
2190 				(char_u *)0L}
2191 #else
2192 			    (char_u *)NULL, PV_NONE,
2193 			    {(char_u *)NULL, (char_u *)0L}
2194 #endif
2195 			    SCRIPTID_INIT},
2196     {"printheader", "pheader",  P_STRING|P_VI_DEF|P_GETTEXT,
2197 #ifdef FEAT_PRINTER
2198 			    (char_u *)&p_header, PV_NONE,
2199 			    {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2200 #else
2201 			    (char_u *)NULL, PV_NONE,
2202 			    {(char_u *)NULL, (char_u *)0L}
2203 #endif
2204 			    SCRIPTID_INIT},
2205    {"printmbcharset", "pmbcs",  P_STRING|P_VI_DEF,
2206 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2207 			    (char_u *)&p_pmcs, 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     {"printmbfont", "pmbfn",  P_STRING|P_VI_DEF,
2215 #if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2216 			    (char_u *)&p_pmfn, 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     {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2224 #ifdef FEAT_PRINTER
2225 			    (char_u *)&p_popt, PV_NONE,
2226 			    {(char_u *)"", (char_u *)0L}
2227 #else
2228 			    (char_u *)NULL, PV_NONE,
2229 			    {(char_u *)NULL, (char_u *)0L}
2230 #endif
2231 			    SCRIPTID_INIT},
2232     {"prompt",	    NULL,   P_BOOL|P_VI_DEF,
2233 			    (char_u *)&p_prompt, PV_NONE,
2234 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2235     {"pumheight",   "ph",   P_NUM|P_VI_DEF,
2236 #ifdef FEAT_INS_EXPAND
2237 			    (char_u *)&p_ph, PV_NONE,
2238 #else
2239 			    (char_u *)NULL, PV_NONE,
2240 #endif
2241 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2242     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2243 #if defined(DYNAMIC_PYTHON3)
2244 			    (char_u *)&p_py3dll, PV_NONE,
2245 			    {(char_u *)DYNAMIC_PYTHON3_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     {"pythondll",   NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2252 #if defined(DYNAMIC_PYTHON)
2253 			    (char_u *)&p_pydll, PV_NONE,
2254 			    {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2255 #else
2256 			    (char_u *)NULL, PV_NONE,
2257 			    {(char_u *)NULL, (char_u *)0L}
2258 #endif
2259 			    SCRIPTID_INIT},
2260     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
2261 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2262 			    (char_u *)&p_pyx, PV_NONE,
2263 #else
2264 			    (char_u *)NULL, PV_NONE,
2265 #endif
2266 			    {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2267 			    SCRIPTID_INIT},
2268     {"quoteescape", "qe",   P_STRING|P_ALLOCED|P_VI_DEF,
2269 #ifdef FEAT_TEXTOBJ
2270 			    (char_u *)&p_qe, PV_QE,
2271 			    {(char_u *)"\\", (char_u *)0L}
2272 #else
2273 			    (char_u *)NULL, PV_NONE,
2274 			    {(char_u *)NULL, (char_u *)0L}
2275 #endif
2276 			    SCRIPTID_INIT},
2277     {"readonly",    "ro",   P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2278 			    (char_u *)&p_ro, PV_RO,
2279 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2280     {"redraw",	    NULL,   P_BOOL|P_VI_DEF,
2281 			    (char_u *)NULL, PV_NONE,
2282 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2283     {"redrawtime",  "rdt",  P_NUM|P_VI_DEF,
2284 #ifdef FEAT_RELTIME
2285 			    (char_u *)&p_rdt, PV_NONE,
2286 #else
2287 			    (char_u *)NULL, PV_NONE,
2288 #endif
2289 			    {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
2290     {"regexpengine", "re",  P_NUM|P_VI_DEF,
2291 			    (char_u *)&p_re, PV_NONE,
2292 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2293     {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2294 			    (char_u *)VAR_WIN, PV_RNU,
2295 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2296     {"remap",	    NULL,   P_BOOL|P_VI_DEF,
2297 			    (char_u *)&p_remap, PV_NONE,
2298 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2299     {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
2300 #ifdef FEAT_RENDER_OPTIONS
2301 			    (char_u *)&p_rop, PV_NONE,
2302 			    {(char_u *)"", (char_u *)0L}
2303 #else
2304 			    (char_u *)NULL, PV_NONE,
2305 			    {(char_u *)NULL, (char_u *)0L}
2306 #endif
2307 			    SCRIPTID_INIT},
2308     {"report",	    NULL,   P_NUM|P_VI_DEF,
2309 			    (char_u *)&p_report, PV_NONE,
2310 			    {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
2311     {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2312 #ifdef WIN3264
2313 			    (char_u *)&p_rs, PV_NONE,
2314 #else
2315 			    (char_u *)NULL, PV_NONE,
2316 #endif
2317 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2318     {"revins",	    "ri",   P_BOOL|P_VI_DEF|P_VIM,
2319 #ifdef FEAT_RIGHTLEFT
2320 			    (char_u *)&p_ri, PV_NONE,
2321 #else
2322 			    (char_u *)NULL, PV_NONE,
2323 #endif
2324 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2325     {"rightleft",   "rl",   P_BOOL|P_VI_DEF|P_RWIN,
2326 #ifdef FEAT_RIGHTLEFT
2327 			    (char_u *)VAR_WIN, PV_RL,
2328 #else
2329 			    (char_u *)NULL, PV_NONE,
2330 #endif
2331 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2332     {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2333 #ifdef FEAT_RIGHTLEFT
2334 			    (char_u *)VAR_WIN, PV_RLC,
2335 			    {(char_u *)"search", (char_u *)NULL}
2336 #else
2337 			    (char_u *)NULL, PV_NONE,
2338 			    {(char_u *)NULL, (char_u *)0L}
2339 #endif
2340 			    SCRIPTID_INIT},
2341     {"rubydll",     NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2342 #if defined(DYNAMIC_RUBY)
2343 			    (char_u *)&p_rubydll, PV_NONE,
2344 			    {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2345 #else
2346 			    (char_u *)NULL, PV_NONE,
2347 			    {(char_u *)NULL, (char_u *)0L}
2348 #endif
2349 			    SCRIPTID_INIT},
2350     {"ruler",	    "ru",   P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2351 #ifdef FEAT_CMDL_INFO
2352 			    (char_u *)&p_ru, PV_NONE,
2353 #else
2354 			    (char_u *)NULL, PV_NONE,
2355 #endif
2356 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2357     {"rulerformat", "ruf",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2358 #ifdef FEAT_STL_OPT
2359 			    (char_u *)&p_ruf, PV_NONE,
2360 #else
2361 			    (char_u *)NULL, PV_NONE,
2362 #endif
2363 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2364     {"runtimepath", "rtp",  P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2365 								    |P_SECURE,
2366 			    (char_u *)&p_rtp, PV_NONE,
2367 			    {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2368 			    SCRIPTID_INIT},
2369     {"scroll",	    "scr",  P_NUM|P_NO_MKRC|P_VI_DEF,
2370 			    (char_u *)VAR_WIN, PV_SCROLL,
2371 			    {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
2372     {"scrollbind",  "scb",  P_BOOL|P_VI_DEF,
2373 #ifdef FEAT_SCROLLBIND
2374 			    (char_u *)VAR_WIN, PV_SCBIND,
2375 #else
2376 			    (char_u *)NULL, PV_NONE,
2377 #endif
2378 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2379     {"scrolljump",  "sj",   P_NUM|P_VI_DEF|P_VIM,
2380 			    (char_u *)&p_sj, PV_NONE,
2381 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2382     {"scrolloff",   "so",   P_NUM|P_VI_DEF|P_VIM|P_RALL,
2383 			    (char_u *)&p_so, PV_NONE,
2384 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2385     {"scrollopt",   "sbo",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2386 #ifdef FEAT_SCROLLBIND
2387 			    (char_u *)&p_sbo, PV_NONE,
2388 			    {(char_u *)"ver,jump", (char_u *)0L}
2389 #else
2390 			    (char_u *)NULL, PV_NONE,
2391 			    {(char_u *)0L, (char_u *)0L}
2392 #endif
2393 			    SCRIPTID_INIT},
2394     {"sections",    "sect", P_STRING|P_VI_DEF,
2395 			    (char_u *)&p_sections, PV_NONE,
2396 			    {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2397 			    SCRIPTID_INIT},
2398     {"secure",	    NULL,   P_BOOL|P_VI_DEF|P_SECURE,
2399 			    (char_u *)&p_secure, PV_NONE,
2400 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2401     {"selection",   "sel",  P_STRING|P_VI_DEF,
2402 			    (char_u *)&p_sel, PV_NONE,
2403 			    {(char_u *)"inclusive", (char_u *)0L}
2404 			    SCRIPTID_INIT},
2405     {"selectmode",  "slm",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2406 			    (char_u *)&p_slm, PV_NONE,
2407 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2408     {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2409 #ifdef FEAT_SESSION
2410 			    (char_u *)&p_ssop, PV_NONE,
2411 	 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
2412 							       (char_u *)0L}
2413 #else
2414 			    (char_u *)NULL, PV_NONE,
2415 			    {(char_u *)0L, (char_u *)0L}
2416 #endif
2417 			    SCRIPTID_INIT},
2418     {"shell",	    "sh",   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2419 			    (char_u *)&p_sh, PV_NONE,
2420 			    {
2421 #ifdef VMS
2422 			    (char_u *)"-",
2423 #else
2424 # if defined(WIN3264)
2425 			    (char_u *)"",	/* set in set_init_1() */
2426 # else
2427 			    (char_u *)"sh",
2428 # endif
2429 #endif /* VMS */
2430 				(char_u *)0L} SCRIPTID_INIT},
2431     {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2432 			    (char_u *)&p_shcf, PV_NONE,
2433 			    {
2434 #if defined(MSWIN)
2435 			    (char_u *)"/c",
2436 #else
2437 			    (char_u *)"-c",
2438 #endif
2439 				(char_u *)0L} SCRIPTID_INIT},
2440     {"shellpipe",   "sp",   P_STRING|P_VI_DEF|P_SECURE,
2441 #ifdef FEAT_QUICKFIX
2442 			    (char_u *)&p_sp, PV_NONE,
2443 			    {
2444 #if defined(UNIX)
2445 			    (char_u *)"| tee",
2446 #else
2447 			    (char_u *)">",
2448 #endif
2449 				(char_u *)0L}
2450 #else
2451 			    (char_u *)NULL, PV_NONE,
2452 			    {(char_u *)0L, (char_u *)0L}
2453 #endif
2454 			    SCRIPTID_INIT},
2455     {"shellquote",  "shq",  P_STRING|P_VI_DEF|P_SECURE,
2456 			    (char_u *)&p_shq, PV_NONE,
2457 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2458     {"shellredir",  "srr",  P_STRING|P_VI_DEF|P_SECURE,
2459 			    (char_u *)&p_srr, PV_NONE,
2460 			    {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
2461     {"shellslash",  "ssl",   P_BOOL|P_VI_DEF,
2462 #ifdef BACKSLASH_IN_FILENAME
2463 			    (char_u *)&p_ssl, PV_NONE,
2464 #else
2465 			    (char_u *)NULL, PV_NONE,
2466 #endif
2467 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2468     {"shelltemp",   "stmp", P_BOOL,
2469 			    (char_u *)&p_stmp, PV_NONE,
2470 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2471     {"shelltype",   "st",   P_NUM|P_VI_DEF,
2472 #ifdef AMIGA
2473 			    (char_u *)&p_st, PV_NONE,
2474 #else
2475 			    (char_u *)NULL, PV_NONE,
2476 #endif
2477 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2478     {"shellxquote", "sxq",  P_STRING|P_VI_DEF|P_SECURE,
2479 			    (char_u *)&p_sxq, PV_NONE,
2480 			    {
2481 #if defined(UNIX) && defined(USE_SYSTEM)
2482 			    (char_u *)"\"",
2483 #else
2484 			    (char_u *)"",
2485 #endif
2486 				(char_u *)0L} SCRIPTID_INIT},
2487     {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2488 			    (char_u *)&p_sxe, PV_NONE,
2489 			    {
2490 #if defined(WIN3264)
2491 			    (char_u *)"\"&|<>()@^",
2492 #else
2493 			    (char_u *)"",
2494 #endif
2495 				(char_u *)0L} SCRIPTID_INIT},
2496     {"shiftround",  "sr",   P_BOOL|P_VI_DEF|P_VIM,
2497 			    (char_u *)&p_sr, PV_NONE,
2498 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2499     {"shiftwidth",  "sw",   P_NUM|P_VI_DEF,
2500 			    (char_u *)&p_sw, PV_SW,
2501 			    {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2502     {"shortmess",   "shm",  P_STRING|P_VIM|P_FLAGLIST,
2503 			    (char_u *)&p_shm, PV_NONE,
2504 			    {(char_u *)"", (char_u *)"filnxtToO"}
2505 			    SCRIPTID_INIT},
2506     {"shortname",   "sn",   P_BOOL|P_VI_DEF,
2507 			    (char_u *)&p_sn, PV_SN,
2508 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2509     {"showbreak",   "sbr",  P_STRING|P_VI_DEF|P_RALL,
2510 #ifdef FEAT_LINEBREAK
2511 			    (char_u *)&p_sbr, PV_NONE,
2512 #else
2513 			    (char_u *)NULL, PV_NONE,
2514 #endif
2515 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2516     {"showcmd",	    "sc",   P_BOOL|P_VIM,
2517 #ifdef FEAT_CMDL_INFO
2518 			    (char_u *)&p_sc, PV_NONE,
2519 #else
2520 			    (char_u *)NULL, PV_NONE,
2521 #endif
2522 			    {(char_u *)FALSE,
2523 #ifdef UNIX
2524 				(char_u *)FALSE
2525 #else
2526 				(char_u *)TRUE
2527 #endif
2528 				} SCRIPTID_INIT},
2529     {"showfulltag", "sft",  P_BOOL|P_VI_DEF,
2530 			    (char_u *)&p_sft, PV_NONE,
2531 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2532     {"showmatch",   "sm",   P_BOOL|P_VI_DEF,
2533 			    (char_u *)&p_sm, PV_NONE,
2534 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2535     {"showmode",    "smd",  P_BOOL|P_VIM,
2536 			    (char_u *)&p_smd, PV_NONE,
2537 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2538     {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2539 #ifdef FEAT_WINDOWS
2540 			    (char_u *)&p_stal, PV_NONE,
2541 #else
2542 			    (char_u *)NULL, PV_NONE,
2543 #endif
2544 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
2545     {"sidescroll",  "ss",   P_NUM|P_VI_DEF,
2546 			    (char_u *)&p_ss, PV_NONE,
2547 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2548     {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2549 			    (char_u *)&p_siso, PV_NONE,
2550 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2551     {"signcolumn",   "scl",  P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2552 #ifdef FEAT_SIGNS
2553 			    (char_u *)VAR_WIN, PV_SCL,
2554 			    {(char_u *)"auto", (char_u *)0L}
2555 #else
2556 			    (char_u *)NULL, PV_NONE,
2557 			    {(char_u *)NULL, (char_u *)0L}
2558 #endif
2559 			    SCRIPTID_INIT},
2560     {"slowopen",    "slow", P_BOOL|P_VI_DEF,
2561 			    (char_u *)NULL, PV_NONE,
2562 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2563     {"smartcase",   "scs",  P_BOOL|P_VI_DEF|P_VIM,
2564 			    (char_u *)&p_scs, PV_NONE,
2565 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2566     {"smartindent", "si",   P_BOOL|P_VI_DEF|P_VIM,
2567 #ifdef FEAT_SMARTINDENT
2568 			    (char_u *)&p_si, PV_SI,
2569 #else
2570 			    (char_u *)NULL, PV_NONE,
2571 #endif
2572 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2573     {"smarttab",    "sta",  P_BOOL|P_VI_DEF|P_VIM,
2574 			    (char_u *)&p_sta, PV_NONE,
2575 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2576     {"softtabstop", "sts",  P_NUM|P_VI_DEF|P_VIM,
2577 			    (char_u *)&p_sts, PV_STS,
2578 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2579     {"sourceany",   NULL,   P_BOOL|P_VI_DEF,
2580 			    (char_u *)NULL, PV_NONE,
2581 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2582     {"spell",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
2583 #ifdef FEAT_SPELL
2584 			    (char_u *)VAR_WIN, PV_SPELL,
2585 #else
2586 			    (char_u *)NULL, PV_NONE,
2587 #endif
2588 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2589     {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
2590 #ifdef FEAT_SPELL
2591 			    (char_u *)&p_spc, PV_SPC,
2592 			    {(char_u *)"[.?!]\\_[\\])'\"	 ]\\+", (char_u *)0L}
2593 #else
2594 			    (char_u *)NULL, PV_NONE,
2595 			    {(char_u *)0L, (char_u *)0L}
2596 #endif
2597 			    SCRIPTID_INIT},
2598     {"spellfile",   "spf",  P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2599 								  |P_ONECOMMA,
2600 #ifdef FEAT_SPELL
2601 			    (char_u *)&p_spf, PV_SPF,
2602 			    {(char_u *)"", (char_u *)0L}
2603 #else
2604 			    (char_u *)NULL, PV_NONE,
2605 			    {(char_u *)0L, (char_u *)0L}
2606 #endif
2607 			    SCRIPTID_INIT},
2608     {"spelllang",   "spl",  P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2609 							     |P_RBUF|P_EXPAND,
2610 #ifdef FEAT_SPELL
2611 			    (char_u *)&p_spl, PV_SPL,
2612 			    {(char_u *)"en", (char_u *)0L}
2613 #else
2614 			    (char_u *)NULL, PV_NONE,
2615 			    {(char_u *)0L, (char_u *)0L}
2616 #endif
2617 			    SCRIPTID_INIT},
2618     {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
2619 #ifdef FEAT_SPELL
2620 			    (char_u *)&p_sps, PV_NONE,
2621 			    {(char_u *)"best", (char_u *)0L}
2622 #else
2623 			    (char_u *)NULL, PV_NONE,
2624 			    {(char_u *)0L, (char_u *)0L}
2625 #endif
2626 			    SCRIPTID_INIT},
2627     {"splitbelow",  "sb",   P_BOOL|P_VI_DEF,
2628 #ifdef FEAT_WINDOWS
2629 			    (char_u *)&p_sb, PV_NONE,
2630 #else
2631 			    (char_u *)NULL, PV_NONE,
2632 #endif
2633 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2634     {"splitright",  "spr",  P_BOOL|P_VI_DEF,
2635 #ifdef FEAT_WINDOWS
2636 			    (char_u *)&p_spr, PV_NONE,
2637 #else
2638 			    (char_u *)NULL, PV_NONE,
2639 #endif
2640 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2641     {"startofline", "sol",  P_BOOL|P_VI_DEF|P_VIM,
2642 			    (char_u *)&p_sol, PV_NONE,
2643 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2644     {"statusline"  ,"stl",  P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2645 #ifdef FEAT_STL_OPT
2646 			    (char_u *)&p_stl, PV_STL,
2647 #else
2648 			    (char_u *)NULL, PV_NONE,
2649 #endif
2650 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2651     {"suffixes",    "su",   P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2652 			    (char_u *)&p_su, PV_NONE,
2653 			    {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
2654 				(char_u *)0L} SCRIPTID_INIT},
2655     {"suffixesadd", "sua",  P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
2656 #ifdef FEAT_SEARCHPATH
2657 			    (char_u *)&p_sua, PV_SUA,
2658 			    {(char_u *)"", (char_u *)0L}
2659 #else
2660 			    (char_u *)NULL, PV_NONE,
2661 			    {(char_u *)0L, (char_u *)0L}
2662 #endif
2663 			    SCRIPTID_INIT},
2664     {"swapfile",    "swf",  P_BOOL|P_VI_DEF|P_RSTAT,
2665 			    (char_u *)&p_swf, PV_SWF,
2666 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2667     {"swapsync",    "sws",  P_STRING|P_VI_DEF,
2668 			    (char_u *)&p_sws, PV_NONE,
2669 			    {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
2670     {"switchbuf",   "swb",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2671 			    (char_u *)&p_swb, PV_NONE,
2672 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2673     {"synmaxcol",   "smc",  P_NUM|P_VI_DEF|P_RBUF,
2674 #ifdef FEAT_SYN_HL
2675 			    (char_u *)&p_smc, PV_SMC,
2676 			    {(char_u *)3000L, (char_u *)0L}
2677 #else
2678 			    (char_u *)NULL, PV_NONE,
2679 			    {(char_u *)0L, (char_u *)0L}
2680 #endif
2681 			    SCRIPTID_INIT},
2682     {"syntax",	    "syn",  P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
2683 #ifdef FEAT_SYN_HL
2684 			    (char_u *)&p_syn, PV_SYN,
2685 			    {(char_u *)"", (char_u *)0L}
2686 #else
2687 			    (char_u *)NULL, PV_NONE,
2688 			    {(char_u *)0L, (char_u *)0L}
2689 #endif
2690 			    SCRIPTID_INIT},
2691     {"tabline",	    "tal",  P_STRING|P_VI_DEF|P_RALL,
2692 #ifdef FEAT_STL_OPT
2693 			    (char_u *)&p_tal, PV_NONE,
2694 #else
2695 			    (char_u *)NULL, PV_NONE,
2696 #endif
2697 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2698     {"tabpagemax",  "tpm",  P_NUM|P_VI_DEF,
2699 #ifdef FEAT_WINDOWS
2700 			    (char_u *)&p_tpm, PV_NONE,
2701 #else
2702 			    (char_u *)NULL, PV_NONE,
2703 #endif
2704 			    {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
2705     {"tabstop",	    "ts",   P_NUM|P_VI_DEF|P_RBUF,
2706 			    (char_u *)&p_ts, PV_TS,
2707 			    {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
2708     {"tagbsearch",  "tbs",   P_BOOL|P_VI_DEF,
2709 			    (char_u *)&p_tbs, PV_NONE,
2710 #ifdef VMS	/* binary searching doesn't appear to work on VMS */
2711 			    {(char_u *)0L, (char_u *)0L}
2712 #else
2713 			    {(char_u *)TRUE, (char_u *)0L}
2714 #endif
2715 			    SCRIPTID_INIT},
2716     {"tagcase",	    "tc",   P_STRING|P_VIM,
2717 			    (char_u *)&p_tc, PV_TC,
2718 			    {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
2719     {"taglength",   "tl",   P_NUM|P_VI_DEF,
2720 			    (char_u *)&p_tl, PV_NONE,
2721 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2722     {"tagrelative", "tr",   P_BOOL|P_VIM,
2723 			    (char_u *)&p_tr, PV_NONE,
2724 			    {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
2725     {"tags",	    "tag",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
2726 			    (char_u *)&p_tags, PV_TAGS,
2727 			    {
2728 #if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2729 			    (char_u *)"./tags,./TAGS,tags,TAGS",
2730 #else
2731 			    (char_u *)"./tags,tags",
2732 #endif
2733 				(char_u *)0L} SCRIPTID_INIT},
2734     {"tagstack",    "tgst", P_BOOL|P_VI_DEF,
2735 			    (char_u *)&p_tgst, PV_NONE,
2736 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2737     {"tcldll",      NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2738 #if defined(DYNAMIC_TCL)
2739 			    (char_u *)&p_tcldll, PV_NONE,
2740 			    {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2741 #else
2742 			    (char_u *)NULL, PV_NONE,
2743 			    {(char_u *)0L, (char_u *)0L}
2744 #endif
2745 			    SCRIPTID_INIT},
2746     {"term",	    NULL,   P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2747 			    (char_u *)&T_NAME, PV_NONE,
2748 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2749     {"termbidi", "tbidi",   P_BOOL|P_VI_DEF,
2750 #ifdef FEAT_ARABIC
2751 			    (char_u *)&p_tbidi, PV_NONE,
2752 #else
2753 			    (char_u *)NULL, PV_NONE,
2754 #endif
2755 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2756     {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2757 #ifdef FEAT_MBYTE
2758 			    (char_u *)&p_tenc, PV_NONE,
2759 			    {(char_u *)"", (char_u *)0L}
2760 #else
2761 			    (char_u *)NULL, PV_NONE,
2762 			    {(char_u *)0L, (char_u *)0L}
2763 #endif
2764 			    SCRIPTID_INIT},
2765     {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2766 #ifdef FEAT_TERMGUICOLORS
2767 			    (char_u *)&p_tgc, PV_NONE,
2768 			    {(char_u *)FALSE, (char_u *)FALSE}
2769 #else
2770 			    (char_u*)NULL, PV_NONE,
2771 			    {(char_u *)FALSE, (char_u *)FALSE}
2772 #endif
2773 			    SCRIPTID_INIT},
2774     {"termkey", "tk",	    P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2775 #ifdef FEAT_TERMINAL
2776 			    (char_u *)VAR_WIN, PV_TK,
2777 			    {(char_u *)"", (char_u *)NULL}
2778 #else
2779 			    (char_u *)NULL, PV_NONE,
2780 			    {(char_u *)NULL, (char_u *)0L}
2781 #endif
2782 			    SCRIPTID_INIT},
2783     {"termsize", "tms",	    P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2784 #ifdef FEAT_TERMINAL
2785 			    (char_u *)VAR_WIN, PV_TMS,
2786 			    {(char_u *)"", (char_u *)NULL}
2787 #else
2788 			    (char_u *)NULL, PV_NONE,
2789 			    {(char_u *)NULL, (char_u *)0L}
2790 #endif
2791 			    SCRIPTID_INIT},
2792     {"terse",	    NULL,   P_BOOL|P_VI_DEF,
2793 			    (char_u *)&p_terse, PV_NONE,
2794 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2795     {"textauto",    "ta",   P_BOOL|P_VIM,
2796 			    (char_u *)&p_ta, PV_NONE,
2797 			    {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2798 			    SCRIPTID_INIT},
2799     {"textmode",    "tx",   P_BOOL|P_VI_DEF|P_NO_MKRC,
2800 			    (char_u *)&p_tx, PV_TX,
2801 			    {
2802 #ifdef USE_CRNL
2803 			    (char_u *)TRUE,
2804 #else
2805 			    (char_u *)FALSE,
2806 #endif
2807 				(char_u *)0L} SCRIPTID_INIT},
2808     {"textwidth",   "tw",   P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2809 			    (char_u *)&p_tw, PV_TW,
2810 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2811     {"thesaurus",   "tsr",  P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
2812 #ifdef FEAT_INS_EXPAND
2813 			    (char_u *)&p_tsr, PV_TSR,
2814 #else
2815 			    (char_u *)NULL, PV_NONE,
2816 #endif
2817 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2818     {"tildeop",	    "top",  P_BOOL|P_VI_DEF|P_VIM,
2819 			    (char_u *)&p_to, PV_NONE,
2820 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2821     {"timeout",	    "to",   P_BOOL|P_VI_DEF,
2822 			    (char_u *)&p_timeout, PV_NONE,
2823 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2824     {"timeoutlen",  "tm",   P_NUM|P_VI_DEF,
2825 			    (char_u *)&p_tm, PV_NONE,
2826 			    {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
2827     {"title",	    NULL,   P_BOOL|P_VI_DEF,
2828 #ifdef FEAT_TITLE
2829 			    (char_u *)&p_title, PV_NONE,
2830 #else
2831 			    (char_u *)NULL, PV_NONE,
2832 #endif
2833 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2834     {"titlelen",    NULL,   P_NUM|P_VI_DEF,
2835 #ifdef FEAT_TITLE
2836 			    (char_u *)&p_titlelen, PV_NONE,
2837 #else
2838 			    (char_u *)NULL, PV_NONE,
2839 #endif
2840 			    {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
2841     {"titleold",    NULL,   P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
2842 #ifdef FEAT_TITLE
2843 			    (char_u *)&p_titleold, PV_NONE,
2844 			    {(char_u *)N_("Thanks for flying Vim"),
2845 							       (char_u *)0L}
2846 #else
2847 			    (char_u *)NULL, PV_NONE,
2848 			    {(char_u *)0L, (char_u *)0L}
2849 #endif
2850 			    SCRIPTID_INIT},
2851     {"titlestring", NULL,   P_STRING|P_VI_DEF,
2852 #ifdef FEAT_TITLE
2853 			    (char_u *)&p_titlestring, PV_NONE,
2854 #else
2855 			    (char_u *)NULL, PV_NONE,
2856 #endif
2857 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2858     {"toolbar",     "tb",   P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
2859 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2860 			    (char_u *)&p_toolbar, PV_NONE,
2861 			    {(char_u *)"icons,tooltips", (char_u *)0L}
2862 #else
2863 			    (char_u *)NULL, PV_NONE,
2864 			    {(char_u *)0L, (char_u *)0L}
2865 #endif
2866 			    SCRIPTID_INIT},
2867     {"toolbariconsize",	"tbis", P_STRING|P_VI_DEF,
2868 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
2869 			    (char_u *)&p_tbis, PV_NONE,
2870 			    {(char_u *)"small", (char_u *)0L}
2871 #else
2872 			    (char_u *)NULL, PV_NONE,
2873 			    {(char_u *)0L, (char_u *)0L}
2874 #endif
2875 			    SCRIPTID_INIT},
2876     {"ttimeout",    NULL,   P_BOOL|P_VI_DEF|P_VIM,
2877 			    (char_u *)&p_ttimeout, PV_NONE,
2878 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2879     {"ttimeoutlen", "ttm",  P_NUM|P_VI_DEF,
2880 			    (char_u *)&p_ttm, PV_NONE,
2881 			    {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
2882     {"ttybuiltin",  "tbi",  P_BOOL|P_VI_DEF,
2883 			    (char_u *)&p_tbi, PV_NONE,
2884 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
2885     {"ttyfast",	    "tf",   P_BOOL|P_NO_MKRC|P_VI_DEF,
2886 			    (char_u *)&p_tf, PV_NONE,
2887 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2888     {"ttymouse",    "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2889 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2890 			    (char_u *)&p_ttym, PV_NONE,
2891 #else
2892 			    (char_u *)NULL, PV_NONE,
2893 #endif
2894 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2895     {"ttyscroll",   "tsl",  P_NUM|P_VI_DEF,
2896 			    (char_u *)&p_ttyscroll, PV_NONE,
2897 			    {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
2898     {"ttytype",	    "tty",  P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2899 			    (char_u *)&T_NAME, PV_NONE,
2900 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2901     {"undodir",     "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2902 								    |P_VI_DEF,
2903 #ifdef FEAT_PERSISTENT_UNDO
2904 			    (char_u *)&p_udir, PV_NONE,
2905 			    {(char_u *)".", (char_u *)0L}
2906 #else
2907 			    (char_u *)NULL, PV_NONE,
2908 			    {(char_u *)0L, (char_u *)0L}
2909 #endif
2910 			    SCRIPTID_INIT},
2911     {"undofile",    "udf",  P_BOOL|P_VI_DEF|P_VIM,
2912 #ifdef FEAT_PERSISTENT_UNDO
2913 			    (char_u *)&p_udf, PV_UDF,
2914 #else
2915 			    (char_u *)NULL, PV_NONE,
2916 #endif
2917 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
2918     {"undolevels",  "ul",   P_NUM|P_VI_DEF,
2919 			    (char_u *)&p_ul, PV_UL,
2920 			    {
2921 #if defined(UNIX) || defined(WIN3264) || defined(VMS)
2922 			    (char_u *)1000L,
2923 #else
2924 			    (char_u *)100L,
2925 #endif
2926 				(char_u *)0L} SCRIPTID_INIT},
2927     {"undoreload",  "ur",   P_NUM|P_VI_DEF,
2928 			    (char_u *)&p_ur, PV_NONE,
2929 			    { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
2930     {"updatecount", "uc",   P_NUM|P_VI_DEF,
2931 			    (char_u *)&p_uc, PV_NONE,
2932 			    {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
2933     {"updatetime",  "ut",   P_NUM|P_VI_DEF,
2934 			    (char_u *)&p_ut, PV_NONE,
2935 			    {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
2936     {"verbose",	    "vbs",  P_NUM|P_VI_DEF,
2937 			    (char_u *)&p_verbose, PV_NONE,
2938 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2939     {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2940 			    (char_u *)&p_vfile, PV_NONE,
2941 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2942     {"viewdir",     "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2943 #ifdef FEAT_SESSION
2944 			    (char_u *)&p_vdir, PV_NONE,
2945 			    {(char_u *)DFLT_VDIR, (char_u *)0L}
2946 #else
2947 			    (char_u *)NULL, PV_NONE,
2948 			    {(char_u *)0L, (char_u *)0L}
2949 #endif
2950 			    SCRIPTID_INIT},
2951     {"viewoptions", "vop",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
2952 #ifdef FEAT_SESSION
2953 			    (char_u *)&p_vop, PV_NONE,
2954 			    {(char_u *)"folds,options,cursor", (char_u *)0L}
2955 #else
2956 			    (char_u *)NULL, PV_NONE,
2957 			    {(char_u *)0L, (char_u *)0L}
2958 #endif
2959 			    SCRIPTID_INIT},
2960     {"viminfo",	    "vi",   P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
2961 #ifdef FEAT_VIMINFO
2962 			    (char_u *)&p_viminfo, PV_NONE,
2963 #if defined(MSWIN)
2964 			    {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
2965 #else
2966 # ifdef AMIGA
2967 			    {(char_u *)"",
2968 				 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
2969 # else
2970 			    {(char_u *)"", (char_u *)"'100,<50,s10,h"}
2971 # endif
2972 #endif
2973 #else
2974 			    (char_u *)NULL, PV_NONE,
2975 			    {(char_u *)0L, (char_u *)0L}
2976 #endif
2977 			    SCRIPTID_INIT},
2978     {"viminfofile", "vif",  P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2979 #ifdef FEAT_VIMINFO
2980 			    (char_u *)&p_viminfofile, PV_NONE,
2981 			    {(char_u *)"", (char_u *)0L}
2982 #else
2983 			    (char_u *)NULL, PV_NONE,
2984 			    {(char_u *)0L, (char_u *)0L}
2985 #endif
2986 			    SCRIPTID_INIT},
2987     {"virtualedit", "ve",   P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2988 							    |P_VIM|P_CURSWANT,
2989 #ifdef FEAT_VIRTUALEDIT
2990 			    (char_u *)&p_ve, PV_NONE,
2991 			    {(char_u *)"", (char_u *)""}
2992 #else
2993 			    (char_u *)NULL, PV_NONE,
2994 			    {(char_u *)0L, (char_u *)0L}
2995 #endif
2996 			    SCRIPTID_INIT},
2997     {"visualbell",  "vb",   P_BOOL|P_VI_DEF,
2998 			    (char_u *)&p_vb, PV_NONE,
2999 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3000     {"w300",	    NULL,   P_NUM|P_VI_DEF,
3001 			    (char_u *)NULL, PV_NONE,
3002 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3003     {"w1200",	    NULL,   P_NUM|P_VI_DEF,
3004 			    (char_u *)NULL, PV_NONE,
3005 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3006     {"w9600",	    NULL,   P_NUM|P_VI_DEF,
3007 			    (char_u *)NULL, PV_NONE,
3008 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3009     {"warn",	    NULL,   P_BOOL|P_VI_DEF,
3010 			    (char_u *)&p_warn, PV_NONE,
3011 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3012     {"weirdinvert", "wiv",  P_BOOL|P_VI_DEF|P_RCLR,
3013 			    (char_u *)&p_wiv, PV_NONE,
3014 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3015     {"whichwrap",   "ww",   P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
3016 			    (char_u *)&p_ww, PV_NONE,
3017 			    {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
3018     {"wildchar",    "wc",   P_NUM|P_VIM,
3019 			    (char_u *)&p_wc, PV_NONE,
3020 			    {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3021 			    SCRIPTID_INIT},
3022     {"wildcharm",   "wcm",  P_NUM|P_VI_DEF,
3023 			    (char_u *)&p_wcm, PV_NONE,
3024 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3025     {"wildignore",  "wig",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
3026 #ifdef FEAT_WILDIGN
3027 			    (char_u *)&p_wig, PV_NONE,
3028 #else
3029 			    (char_u *)NULL, PV_NONE,
3030 #endif
3031 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
3032     {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3033 			    (char_u *)&p_wic, PV_NONE,
3034 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3035     {"wildmenu",    "wmnu", P_BOOL|P_VI_DEF,
3036 #ifdef FEAT_WILDMENU
3037 			    (char_u *)&p_wmnu, PV_NONE,
3038 #else
3039 			    (char_u *)NULL, PV_NONE,
3040 #endif
3041 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3042     {"wildmode",    "wim",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
3043 			    (char_u *)&p_wim, PV_NONE,
3044 			    {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
3045     {"wildoptions", "wop",  P_STRING|P_VI_DEF,
3046 #ifdef FEAT_CMDL_COMPL
3047 			    (char_u *)&p_wop, PV_NONE,
3048 			    {(char_u *)"", (char_u *)0L}
3049 #else
3050 			    (char_u *)NULL, PV_NONE,
3051 			    {(char_u *)NULL, (char_u *)0L}
3052 #endif
3053 			    SCRIPTID_INIT},
3054     {"winaltkeys",  "wak",  P_STRING|P_VI_DEF,
3055 #ifdef FEAT_WAK
3056 			    (char_u *)&p_wak, PV_NONE,
3057 			    {(char_u *)"menu", (char_u *)0L}
3058 #else
3059 			    (char_u *)NULL, PV_NONE,
3060 			    {(char_u *)NULL, (char_u *)0L}
3061 #endif
3062 			    SCRIPTID_INIT},
3063     {"window",	    "wi",   P_NUM|P_VI_DEF,
3064 			    (char_u *)&p_window, PV_NONE,
3065 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3066     {"winheight",   "wh",   P_NUM|P_VI_DEF,
3067 #ifdef FEAT_WINDOWS
3068 			    (char_u *)&p_wh, PV_NONE,
3069 #else
3070 			    (char_u *)NULL, PV_NONE,
3071 #endif
3072 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3073     {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
3074 #ifdef FEAT_WINDOWS
3075 			    (char_u *)VAR_WIN, PV_WFH,
3076 #else
3077 			    (char_u *)NULL, PV_NONE,
3078 #endif
3079 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3080     {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
3081 #ifdef FEAT_WINDOWS
3082 			    (char_u *)VAR_WIN, PV_WFW,
3083 #else
3084 			    (char_u *)NULL, PV_NONE,
3085 #endif
3086 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3087     {"winminheight", "wmh", P_NUM|P_VI_DEF,
3088 #ifdef FEAT_WINDOWS
3089 			    (char_u *)&p_wmh, PV_NONE,
3090 #else
3091 			    (char_u *)NULL, PV_NONE,
3092 #endif
3093 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3094     {"winminwidth", "wmw", P_NUM|P_VI_DEF,
3095 #ifdef FEAT_WINDOWS
3096 			    (char_u *)&p_wmw, PV_NONE,
3097 #else
3098 			    (char_u *)NULL, PV_NONE,
3099 #endif
3100 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
3101     {"winwidth",   "wiw",   P_NUM|P_VI_DEF,
3102 #ifdef FEAT_WINDOWS
3103 			    (char_u *)&p_wiw, PV_NONE,
3104 #else
3105 			    (char_u *)NULL, PV_NONE,
3106 #endif
3107 			    {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
3108     {"wrap",	    NULL,   P_BOOL|P_VI_DEF|P_RWIN,
3109 			    (char_u *)VAR_WIN, PV_WRAP,
3110 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3111     {"wrapmargin",  "wm",   P_NUM|P_VI_DEF,
3112 			    (char_u *)&p_wm, PV_WM,
3113 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3114     {"wrapscan",    "ws",   P_BOOL|P_VI_DEF,
3115 			    (char_u *)&p_ws, PV_NONE,
3116 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3117     {"write",	    NULL,   P_BOOL|P_VI_DEF,
3118 			    (char_u *)&p_write, PV_NONE,
3119 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
3120     {"writeany",    "wa",   P_BOOL|P_VI_DEF,
3121 			    (char_u *)&p_wa, PV_NONE,
3122 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
3123     {"writebackup", "wb",   P_BOOL|P_VI_DEF|P_VIM,
3124 			    (char_u *)&p_wb, PV_NONE,
3125 			    {
3126 #ifdef FEAT_WRITEBACKUP
3127 			    (char_u *)TRUE,
3128 #else
3129 			    (char_u *)FALSE,
3130 #endif
3131 				(char_u *)0L} SCRIPTID_INIT},
3132     {"writedelay",  "wd",   P_NUM|P_VI_DEF,
3133 			    (char_u *)&p_wd, PV_NONE,
3134 			    {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
3135 
3136 /* terminal output codes */
3137 #define p_term(sss, vvv)   {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
3138 			    (char_u *)&vvv, PV_NONE, \
3139 			    {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
3140 
3141     p_term("t_AB", T_CAB)
3142     p_term("t_AF", T_CAF)
3143     p_term("t_AL", T_CAL)
3144     p_term("t_al", T_AL)
3145     p_term("t_bc", T_BC)
3146     p_term("t_cd", T_CD)
3147     p_term("t_ce", T_CE)
3148     p_term("t_cl", T_CL)
3149     p_term("t_cm", T_CM)
3150     p_term("t_Ce", T_UCE)
3151     p_term("t_Co", T_CCO)
3152     p_term("t_CS", T_CCS)
3153     p_term("t_Cs", T_UCS)
3154     p_term("t_cs", T_CS)
3155 #ifdef FEAT_WINDOWS
3156     p_term("t_CV", T_CSV)
3157 #endif
3158     p_term("t_da", T_DA)
3159     p_term("t_db", T_DB)
3160     p_term("t_DL", T_CDL)
3161     p_term("t_dl", T_DL)
3162     p_term("t_EI", T_CEI)
3163     p_term("t_fs", T_FS)
3164     p_term("t_IE", T_CIE)
3165     p_term("t_IS", T_CIS)
3166     p_term("t_ke", T_KE)
3167     p_term("t_ks", T_KS)
3168     p_term("t_le", T_LE)
3169     p_term("t_mb", T_MB)
3170     p_term("t_md", T_MD)
3171     p_term("t_me", T_ME)
3172     p_term("t_mr", T_MR)
3173     p_term("t_ms", T_MS)
3174     p_term("t_nd", T_ND)
3175     p_term("t_op", T_OP)
3176     p_term("t_RB", T_RBG)
3177     p_term("t_RI", T_CRI)
3178     p_term("t_RV", T_CRV)
3179     p_term("t_Sb", T_CSB)
3180     p_term("t_se", T_SE)
3181     p_term("t_Sf", T_CSF)
3182     p_term("t_SI", T_CSI)
3183     p_term("t_so", T_SO)
3184     p_term("t_SR", T_CSR)
3185     p_term("t_sr", T_SR)
3186     p_term("t_te", T_TE)
3187     p_term("t_ti", T_TI)
3188     p_term("t_ts", T_TS)
3189     p_term("t_u7", T_U7)
3190     p_term("t_ue", T_UE)
3191     p_term("t_us", T_US)
3192     p_term("t_ut", T_UT)
3193     p_term("t_vb", T_VB)
3194     p_term("t_ve", T_VE)
3195     p_term("t_vi", T_VI)
3196     p_term("t_vs", T_VS)
3197     p_term("t_WP", T_CWP)
3198     p_term("t_GP", T_CGP)
3199     p_term("t_WS", T_CWS)
3200     p_term("t_xn", T_XN)
3201     p_term("t_xs", T_XS)
3202     p_term("t_ZH", T_CZH)
3203     p_term("t_ZR", T_CZR)
3204     p_term("t_8f", T_8F)
3205     p_term("t_8b", T_8B)
3206     p_term("t_BE", T_BE)
3207     p_term("t_BD", T_BD)
3208 
3209 /* terminal key codes are not in here */
3210 
3211     /* end marker */
3212     {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
3213 };
3214 
3215 #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3216 
3217 #ifdef FEAT_MBYTE
3218 static char *(p_ambw_values[]) = {"single", "double", NULL};
3219 #endif
3220 static char *(p_bg_values[]) = {"light", "dark", NULL};
3221 static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
3222 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
3223 #ifdef FEAT_CRYPT
3224 static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
3225 #endif
3226 #ifdef FEAT_CMDL_COMPL
3227 static char *(p_wop_values[]) = {"tagfile", NULL};
3228 #endif
3229 #ifdef FEAT_WAK
3230 static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3231 #endif
3232 static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
3233 static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3234 static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
3235 static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
3236 #ifdef FEAT_BROWSE
3237 static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3238 #endif
3239 #ifdef FEAT_SCROLLBIND
3240 static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3241 #endif
3242 static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
3243 #ifdef FEAT_WINDOWS
3244 static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3245 #endif
3246 #ifdef FEAT_AUTOCMD
3247 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3248 #else
3249 static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
3250 #endif
3251 static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3252 static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3253 #ifdef FEAT_FOLDING
3254 static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
3255 # ifdef FEAT_DIFF
3256 				"diff",
3257 # endif
3258 				NULL};
3259 static char *(p_fcl_values[]) = {"all", NULL};
3260 #endif
3261 #ifdef FEAT_INS_EXPAND
3262 static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
3263 #endif
3264 #ifdef FEAT_SIGNS
3265 static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3266 #endif
3267 
3268 static void set_option_default(int, int opt_flags, int compatible);
3269 static void set_options_default(int opt_flags);
3270 static char_u *term_bg_default(void);
3271 static void did_set_option(int opt_idx, int opt_flags, int new_value);
3272 static char_u *illegal_char(char_u *, int);
3273 #ifdef FEAT_CMDWIN
3274 static char_u *check_cedit(void);
3275 #endif
3276 #ifdef FEAT_TITLE
3277 static void did_set_title(int icon);
3278 #endif
3279 static char_u *option_expand(int opt_idx, char_u *val);
3280 static void didset_options(void);
3281 static void didset_options2(void);
3282 static void check_string_option(char_u **pp);
3283 #if defined(FEAT_EVAL) || defined(PROTO)
3284 static long_u *insecure_flag(int opt_idx, int opt_flags);
3285 #else
3286 # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3287 #endif
3288 static void set_string_option_global(int opt_idx, char_u **varp);
3289 static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3290 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);
3291 static char_u *set_chars_option(char_u **varp);
3292 #ifdef FEAT_SYN_HL
3293 static int int_cmp(const void *a, const void *b);
3294 #endif
3295 #ifdef FEAT_CLIPBOARD
3296 static char_u *check_clipboard_option(void);
3297 #endif
3298 #ifdef FEAT_SPELL
3299 static char_u *did_set_spell_option(int is_spellfile);
3300 static char_u *compile_cap_prog(synblock_T *synblock);
3301 #endif
3302 #ifdef FEAT_EVAL
3303 static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
3304 #endif
3305 static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3306 static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3307 static void check_redraw(long_u flags);
3308 static int findoption(char_u *);
3309 static int find_key_option(char_u *);
3310 static void showoptions(int all, int opt_flags);
3311 static int optval_default(struct vimoption *, char_u *varp);
3312 static void showoneopt(struct vimoption *, int opt_flags);
3313 static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3314 static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3315 static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3316 static int  istermoption(struct vimoption *);
3317 static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3318 static char_u *get_varp(struct vimoption *);
3319 static void option_value2string(struct vimoption *, int opt_flags);
3320 static void check_winopt(winopt_T *wop);
3321 static int wc_use_keyname(char_u *varp, long *wcp);
3322 #ifdef FEAT_LANGMAP
3323 static void langmap_init(void);
3324 static void langmap_set(void);
3325 #endif
3326 static void paste_option_changed(void);
3327 static void compatible_set(void);
3328 #ifdef FEAT_LINEBREAK
3329 static void fill_breakat_flags(void);
3330 #endif
3331 static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3332 static int check_opt_strings(char_u *val, char **values, int);
3333 static int check_opt_wim(void);
3334 #ifdef FEAT_LINEBREAK
3335 static int briopt_check(win_T *wp);
3336 #endif
3337 
3338 /*
3339  * Initialize the options, first part.
3340  *
3341  * Called only once from main(), just after creating the first buffer.
3342  */
3343     void
3344 set_init_1(void)
3345 {
3346     char_u	*p;
3347     int		opt_idx;
3348     long_u	n;
3349 
3350 #ifdef FEAT_LANGMAP
3351     langmap_init();
3352 #endif
3353 
3354     /* Be Vi compatible by default */
3355     p_cp = TRUE;
3356 
3357     /* Use POSIX compatibility when $VIM_POSIX is set. */
3358     if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
3359     {
3360 	set_string_default("cpo", (char_u *)CPO_ALL);
3361 	set_string_default("shm", (char_u *)"A");
3362     }
3363 
3364     /*
3365      * Find default value for 'shell' option.
3366      * Don't use it if it is empty.
3367      */
3368     if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
3369 #if defined(MSWIN)
3370 	    || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
3371 # ifdef WIN3264
3372 	    || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
3373 # endif
3374 #endif
3375 	    )
3376 	set_string_default("sh", p);
3377 
3378 #ifdef FEAT_WILDIGN
3379     /*
3380      * Set the default for 'backupskip' to include environment variables for
3381      * temp files.
3382      */
3383     {
3384 # ifdef UNIX
3385 	static char	*(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3386 # else
3387 	static char	*(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3388 # endif
3389 	int		len;
3390 	garray_T	ga;
3391 	int		mustfree;
3392 
3393 	ga_init2(&ga, 1, 100);
3394 	for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3395 	{
3396 	    mustfree = FALSE;
3397 # ifdef UNIX
3398 	    if (*names[n] == NUL)
3399 		p = (char_u *)"/tmp";
3400 	    else
3401 # endif
3402 		p = vim_getenv((char_u *)names[n], &mustfree);
3403 	    if (p != NULL && *p != NUL)
3404 	    {
3405 		/* First time count the NUL, otherwise count the ','. */
3406 		len = (int)STRLEN(p) + 3;
3407 		if (ga_grow(&ga, len) == OK)
3408 		{
3409 		    if (ga.ga_len > 0)
3410 			STRCAT(ga.ga_data, ",");
3411 		    STRCAT(ga.ga_data, p);
3412 		    add_pathsep(ga.ga_data);
3413 		    STRCAT(ga.ga_data, "*");
3414 		    ga.ga_len += len;
3415 		}
3416 	    }
3417 	    if (mustfree)
3418 		vim_free(p);
3419 	}
3420 	if (ga.ga_data != NULL)
3421 	{
3422 	    set_string_default("bsk", ga.ga_data);
3423 	    vim_free(ga.ga_data);
3424 	}
3425     }
3426 #endif
3427 
3428     /*
3429      * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3430      */
3431     opt_idx = findoption((char_u *)"maxmemtot");
3432     if (opt_idx >= 0)
3433     {
3434 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3435 	if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3436 #endif
3437 	{
3438 #ifdef HAVE_AVAIL_MEM
3439 	    /* Use amount of memory available at this moment. */
3440 	    n = (mch_avail_mem(FALSE) >> 1);
3441 #else
3442 # ifdef HAVE_TOTAL_MEM
3443 	    /* Use amount of memory available to Vim. */
3444 	    n = (mch_total_mem(FALSE) >> 1);
3445 # else
3446 	    n = (0x7fffffff >> 11);
3447 # endif
3448 #endif
3449 	    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3450 	    opt_idx = findoption((char_u *)"maxmem");
3451 	    if (opt_idx >= 0)
3452 	    {
3453 #if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3454 		if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3455 		  || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3456 #endif
3457 		    options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3458 	    }
3459 	}
3460     }
3461 
3462 #ifdef FEAT_SEARCHPATH
3463     {
3464 	char_u	*cdpath;
3465 	char_u	*buf;
3466 	int	i;
3467 	int	j;
3468 	int	mustfree = FALSE;
3469 
3470 	/* Initialize the 'cdpath' option's default value. */
3471 	cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
3472 	if (cdpath != NULL)
3473 	{
3474 	    buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3475 	    if (buf != NULL)
3476 	    {
3477 		buf[0] = ',';	    /* start with ",", current dir first */
3478 		j = 1;
3479 		for (i = 0; cdpath[i] != NUL; ++i)
3480 		{
3481 		    if (vim_ispathlistsep(cdpath[i]))
3482 			buf[j++] = ',';
3483 		    else
3484 		    {
3485 			if (cdpath[i] == ' ' || cdpath[i] == ',')
3486 			    buf[j++] = '\\';
3487 			buf[j++] = cdpath[i];
3488 		    }
3489 		}
3490 		buf[j] = NUL;
3491 		opt_idx = findoption((char_u *)"cdpath");
3492 		if (opt_idx >= 0)
3493 		{
3494 		    options[opt_idx].def_val[VI_DEFAULT] = buf;
3495 		    options[opt_idx].flags |= P_DEF_ALLOCED;
3496 		}
3497 		else
3498 		    vim_free(buf); /* cannot happen */
3499 	    }
3500 	    if (mustfree)
3501 		vim_free(cdpath);
3502 	}
3503     }
3504 #endif
3505 
3506 #if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3507     /* Set print encoding on platforms that don't default to latin1 */
3508     set_string_default("penc",
3509 # if defined(MSWIN)
3510 		       (char_u *)"cp1252"
3511 # else
3512 #  ifdef VMS
3513 		       (char_u *)"dec-mcs"
3514 #  else
3515 #   ifdef EBCDIC
3516 		       (char_u *)"ebcdic-uk"
3517 #   else
3518 #    ifdef MAC
3519 		       (char_u *)"mac-roman"
3520 #    else /* HPUX */
3521 		       (char_u *)"hp-roman8"
3522 #    endif
3523 #   endif
3524 #  endif
3525 # endif
3526 		       );
3527 #endif
3528 
3529 #ifdef FEAT_POSTSCRIPT
3530     /* 'printexpr' must be allocated to be able to evaluate it. */
3531     set_string_default("pexpr",
3532 # if defined(MSWIN)
3533 	    (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
3534 # else
3535 #  ifdef VMS
3536 	    (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3537 
3538 #  else
3539 	    (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3540 #  endif
3541 # endif
3542 	    );
3543 #endif
3544 
3545     /*
3546      * Set all the options (except the terminal options) to their default
3547      * value.  Also set the global value for local options.
3548      */
3549     set_options_default(0);
3550 
3551 #ifdef FEAT_GUI
3552     if (found_reverse_arg)
3553 	set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3554 #endif
3555 
3556     curbuf->b_p_initialized = TRUE;
3557     curbuf->b_p_ar = -1;	/* no local 'autoread' value */
3558     curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
3559     check_buf_options(curbuf);
3560     check_win_options(curwin);
3561     check_options();
3562 
3563     /* Must be before option_expand(), because that one needs vim_isIDc() */
3564     didset_options();
3565 
3566 #ifdef FEAT_SPELL
3567     /* Use the current chartab for the generic chartab. This is not in
3568      * didset_options() because it only depends on 'encoding'. */
3569     init_spell_chartab();
3570 #endif
3571 
3572     /*
3573      * Expand environment variables and things like "~" for the defaults.
3574      * If option_expand() returns non-NULL the variable is expanded.  This can
3575      * only happen for non-indirect options.
3576      * Also set the default to the expanded value, so ":set" does not list
3577      * them.
3578      * Don't set the P_ALLOCED flag, because we don't want to free the
3579      * default.
3580      */
3581     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3582     {
3583 	if ((options[opt_idx].flags & P_GETTEXT)
3584 					      && options[opt_idx].var != NULL)
3585 	    p = (char_u *)_(*(char **)options[opt_idx].var);
3586 	else
3587 	    p = option_expand(opt_idx, NULL);
3588 	if (p != NULL && (p = vim_strsave(p)) != NULL)
3589 	{
3590 	    *(char_u **)options[opt_idx].var = p;
3591 	    /* VIMEXP
3592 	     * Defaults for all expanded options are currently the same for Vi
3593 	     * and Vim.  When this changes, add some code here!  Also need to
3594 	     * split P_DEF_ALLOCED in two.
3595 	     */
3596 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3597 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3598 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3599 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3600 	}
3601     }
3602 
3603     save_file_ff(curbuf);	/* Buffer is unchanged */
3604 
3605 #if defined(FEAT_ARABIC)
3606     /* Detect use of mlterm.
3607      * Mlterm is a terminal emulator akin to xterm that has some special
3608      * abilities (bidi namely).
3609      * NOTE: mlterm's author is being asked to 'set' a variable
3610      *       instead of an environment variable due to inheritance.
3611      */
3612     if (mch_getenv((char_u *)"MLTERM") != NULL)
3613 	set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3614 #endif
3615 
3616     didset_options2();
3617 
3618 #ifdef FEAT_MBYTE
3619 # if defined(WIN3264) && defined(FEAT_GETTEXT)
3620     /*
3621      * If $LANG isn't set, try to get a good value for it.  This makes the
3622      * right language be used automatically.  Don't do this for English.
3623      */
3624     if (mch_getenv((char_u *)"LANG") == NULL)
3625     {
3626 	char	buf[20];
3627 
3628 	/* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3629 	 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3630 	 * only the first two. */
3631 	n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3632 							     (LPTSTR)buf, 20);
3633 	if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3634 	{
3635 	    /* There are a few exceptions (probably more) */
3636 	    if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3637 		STRCPY(buf, "zh_TW");
3638 	    else if (STRNICMP(buf, "chs", 3) == 0
3639 					      || STRNICMP(buf, "zhc", 3) == 0)
3640 		STRCPY(buf, "zh_CN");
3641 	    else if (STRNICMP(buf, "jp", 2) == 0)
3642 		STRCPY(buf, "ja");
3643 	    else
3644 		buf[2] = NUL;		/* truncate to two-letter code */
3645 	    vim_setenv((char_u *)"LANG", (char_u *)buf);
3646 	}
3647     }
3648 # else
3649 #  ifdef MACOS_CONVERT
3650     /* Moved to os_mac_conv.c to avoid dependency problems. */
3651     mac_lang_init();
3652 #  endif
3653 # endif
3654 
3655     /* enc_locale() will try to find the encoding of the current locale. */
3656     p = enc_locale();
3657     if (p != NULL)
3658     {
3659 	char_u *save_enc;
3660 
3661 	/* Try setting 'encoding' and check if the value is valid.
3662 	 * If not, go back to the default "latin1". */
3663 	save_enc = p_enc;
3664 	p_enc = p;
3665 	if (STRCMP(p_enc, "gb18030") == 0)
3666 	{
3667 	    /* We don't support "gb18030", but "cp936" is a good substitute
3668 	     * for practical purposes, thus use that.  It's not an alias to
3669 	     * still support conversion between gb18030 and utf-8. */
3670 	    p_enc = vim_strsave((char_u *)"cp936");
3671 	    vim_free(p);
3672 	}
3673 	if (mb_init() == NULL)
3674 	{
3675 	    opt_idx = findoption((char_u *)"encoding");
3676 	    if (opt_idx >= 0)
3677 	    {
3678 		options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3679 		options[opt_idx].flags |= P_DEF_ALLOCED;
3680 	    }
3681 
3682 #if defined(MSWIN) || defined(MACOS) || defined(VMS)
3683 	    if (STRCMP(p_enc, "latin1") == 0
3684 # ifdef FEAT_MBYTE
3685 		    || enc_utf8
3686 # endif
3687 		    )
3688 	    {
3689 		/* Adjust the default for 'isprint' and 'iskeyword' to match
3690 		 * latin1.  Also set the defaults for when 'nocompatible' is
3691 		 * set. */
3692 		set_string_option_direct((char_u *)"isp", -1,
3693 					      ISP_LATIN1, OPT_FREE, SID_NONE);
3694 		set_string_option_direct((char_u *)"isk", -1,
3695 					      ISK_LATIN1, OPT_FREE, SID_NONE);
3696 		opt_idx = findoption((char_u *)"isp");
3697 		if (opt_idx >= 0)
3698 		    options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
3699 		opt_idx = findoption((char_u *)"isk");
3700 		if (opt_idx >= 0)
3701 		    options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
3702 		(void)init_chartab();
3703 	    }
3704 #endif
3705 
3706 # if defined(WIN3264) && !defined(FEAT_GUI)
3707 	    /* Win32 console: When GetACP() returns a different value from
3708 	     * GetConsoleCP() set 'termencoding'. */
3709 	    if (GetACP() != GetConsoleCP())
3710 	    {
3711 		char	buf[50];
3712 
3713 		sprintf(buf, "cp%ld", (long)GetConsoleCP());
3714 		p_tenc = vim_strsave((char_u *)buf);
3715 		if (p_tenc != NULL)
3716 		{
3717 		    opt_idx = findoption((char_u *)"termencoding");
3718 		    if (opt_idx >= 0)
3719 		    {
3720 			options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3721 			options[opt_idx].flags |= P_DEF_ALLOCED;
3722 		    }
3723 		    convert_setup(&input_conv, p_tenc, p_enc);
3724 		    convert_setup(&output_conv, p_enc, p_tenc);
3725 		}
3726 		else
3727 		    p_tenc = empty_option;
3728 	    }
3729 # endif
3730 # if defined(WIN3264) && defined(FEAT_MBYTE)
3731 	    /* $HOME may have characters in active code page. */
3732 	    init_homedir();
3733 # endif
3734 	}
3735 	else
3736 	{
3737 	    vim_free(p_enc);
3738 	    p_enc = save_enc;
3739 	}
3740     }
3741 #endif
3742 
3743 #ifdef FEAT_MULTI_LANG
3744     /* Set the default for 'helplang'. */
3745     set_helplang_default(get_mess_lang());
3746 #endif
3747 }
3748 
3749 /*
3750  * Set an option to its default value.
3751  * This does not take care of side effects!
3752  */
3753     static void
3754 set_option_default(
3755     int		opt_idx,
3756     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3757     int		compatible)	/* use Vi default value */
3758 {
3759     char_u	*varp;		/* pointer to variable for current option */
3760     int		dvi;		/* index in def_val[] */
3761     long_u	flags;
3762     long_u	*flagsp;
3763     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3764 
3765     varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3766     flags = options[opt_idx].flags;
3767     if (varp != NULL)	    /* skip hidden option, nothing to do for it */
3768     {
3769 	dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3770 	if (flags & P_STRING)
3771 	{
3772 	    /* Use set_string_option_direct() for local options to handle
3773 	     * freeing and allocating the value. */
3774 	    if (options[opt_idx].indir != PV_NONE)
3775 		set_string_option_direct(NULL, opt_idx,
3776 				 options[opt_idx].def_val[dvi], opt_flags, 0);
3777 	    else
3778 	    {
3779 		if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3780 		    free_string_option(*(char_u **)(varp));
3781 		*(char_u **)varp = options[opt_idx].def_val[dvi];
3782 		options[opt_idx].flags &= ~P_ALLOCED;
3783 	    }
3784 	}
3785 	else if (flags & P_NUM)
3786 	{
3787 	    if (options[opt_idx].indir == PV_SCROLL)
3788 		win_comp_scroll(curwin);
3789 	    else
3790 	    {
3791 		*(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
3792 		/* May also set global value for local option. */
3793 		if (both)
3794 		    *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3795 								*(long *)varp;
3796 	    }
3797 	}
3798 	else	/* P_BOOL */
3799 	{
3800 	    /* the cast to long is required for Manx C, long_i is needed for
3801 	     * MSVC */
3802 	    *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
3803 #ifdef UNIX
3804 	    /* 'modeline' defaults to off for root */
3805 	    if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3806 		*(int *)varp = FALSE;
3807 #endif
3808 	    /* May also set global value for local option. */
3809 	    if (both)
3810 		*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3811 								*(int *)varp;
3812 	}
3813 
3814 	/* The default value is not insecure. */
3815 	flagsp = insecure_flag(opt_idx, opt_flags);
3816 	*flagsp = *flagsp & ~P_INSECURE;
3817     }
3818 
3819 #ifdef FEAT_EVAL
3820     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
3821 #endif
3822 }
3823 
3824 /*
3825  * Set all options (except terminal options) to their default value.
3826  * When "opt_flags" is non-zero skip 'encoding'.
3827  */
3828     static void
3829 set_options_default(
3830     int		opt_flags)	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3831 {
3832     int		i;
3833 #ifdef FEAT_WINDOWS
3834     win_T	*wp;
3835     tabpage_T	*tp;
3836 #endif
3837 
3838     for (i = 0; !istermoption(&options[i]); i++)
3839 	if (!(options[i].flags & P_NODEFAULT)
3840 #if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
3841 		&& (opt_flags == 0
3842 		    || (TRUE
3843 # if defined(FEAT_MBYTE)
3844 			&& options[i].var != (char_u *)&p_enc
3845 # endif
3846 # if defined(FEAT_CRYPT)
3847 			&& options[i].var != (char_u *)&p_cm
3848 			&& options[i].var != (char_u *)&p_key
3849 # endif
3850 			))
3851 #endif
3852 			)
3853 	    set_option_default(i, opt_flags, p_cp);
3854 
3855 #ifdef FEAT_WINDOWS
3856     /* The 'scroll' option must be computed for all windows. */
3857     FOR_ALL_TAB_WINDOWS(tp, wp)
3858 	win_comp_scroll(wp);
3859 #else
3860 	win_comp_scroll(curwin);
3861 #endif
3862 #ifdef FEAT_CINDENT
3863     parse_cino(curbuf);
3864 #endif
3865 }
3866 
3867 /*
3868  * Set the Vi-default value of a string option.
3869  * Used for 'sh', 'backupskip' and 'term'.
3870  */
3871     void
3872 set_string_default(char *name, char_u *val)
3873 {
3874     char_u	*p;
3875     int		opt_idx;
3876 
3877     p = vim_strsave(val);
3878     if (p != NULL)		/* we don't want a NULL */
3879     {
3880 	opt_idx = findoption((char_u *)name);
3881 	if (opt_idx >= 0)
3882 	{
3883 	    if (options[opt_idx].flags & P_DEF_ALLOCED)
3884 		vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3885 	    options[opt_idx].def_val[VI_DEFAULT] = p;
3886 	    options[opt_idx].flags |= P_DEF_ALLOCED;
3887 	}
3888     }
3889 }
3890 
3891 /*
3892  * Set the Vi-default value of a number option.
3893  * Used for 'lines' and 'columns'.
3894  */
3895     void
3896 set_number_default(char *name, long val)
3897 {
3898     int		opt_idx;
3899 
3900     opt_idx = findoption((char_u *)name);
3901     if (opt_idx >= 0)
3902 	options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
3903 }
3904 
3905 #if defined(EXITFREE) || defined(PROTO)
3906 /*
3907  * Free all options.
3908  */
3909     void
3910 free_all_options(void)
3911 {
3912     int		i;
3913 
3914     for (i = 0; !istermoption(&options[i]); i++)
3915     {
3916 	if (options[i].indir == PV_NONE)
3917 	{
3918 	    /* global option: free value and default value. */
3919 	    if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
3920 		free_string_option(*(char_u **)options[i].var);
3921 	    if (options[i].flags & P_DEF_ALLOCED)
3922 		free_string_option(options[i].def_val[VI_DEFAULT]);
3923 	}
3924 	else if (options[i].var != VAR_WIN
3925 		&& (options[i].flags & P_STRING))
3926 	    /* buffer-local option: free global value */
3927 	    free_string_option(*(char_u **)options[i].var);
3928     }
3929 }
3930 #endif
3931 
3932 
3933 /*
3934  * Initialize the options, part two: After getting Rows and Columns and
3935  * setting 'term'.
3936  */
3937     void
3938 set_init_2(void)
3939 {
3940     int		idx;
3941 
3942     /*
3943      * 'scroll' defaults to half the window height. Note that this default is
3944      * wrong when the window height changes.
3945      */
3946     set_number_default("scroll", (long)((long_u)Rows >> 1));
3947     idx = findoption((char_u *)"scroll");
3948     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
3949 	set_option_default(idx, OPT_LOCAL, p_cp);
3950     comp_col();
3951 
3952     /*
3953      * 'window' is only for backwards compatibility with Vi.
3954      * Default is Rows - 1.
3955      */
3956     if (!option_was_set((char_u *)"window"))
3957 	p_window = Rows - 1;
3958     set_number_default("window", Rows - 1);
3959 
3960     /* For DOS console the default is always black. */
3961 #if !((defined(WIN3264)) && !defined(FEAT_GUI))
3962     /*
3963      * If 'background' wasn't set by the user, try guessing the value,
3964      * depending on the terminal name.  Only need to check for terminals
3965      * with a dark background, that can handle color.
3966      */
3967     idx = findoption((char_u *)"bg");
3968     if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3969 						 && *term_bg_default() == 'd')
3970     {
3971 	set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
3972 	/* don't mark it as set, when starting the GUI it may be
3973 	 * changed again */
3974 	options[idx].flags &= ~P_WAS_SET;
3975     }
3976 #endif
3977 
3978 #ifdef CURSOR_SHAPE
3979     parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3980 #endif
3981 #ifdef FEAT_MOUSESHAPE
3982     parse_shape_opt(SHAPE_MOUSE);  /* set mouse shapes from 'mouseshape' */
3983 #endif
3984 #ifdef FEAT_PRINTER
3985     (void)parse_printoptions();	    /* parse 'printoptions' default value */
3986 #endif
3987 }
3988 
3989 /*
3990  * Return "dark" or "light" depending on the kind of terminal.
3991  * This is just guessing!  Recognized are:
3992  * "linux"	    Linux console
3993  * "screen.linux"   Linux console with screen
3994  * "cygwin"	    Cygwin shell
3995  * "putty"	    Putty program
3996  * We also check the COLORFGBG environment variable, which is set by
3997  * rxvt and derivatives. This variable contains either two or three
3998  * values separated by semicolons; we want the last value in either
3999  * case. If this value is 0-6 or 8, our background is dark.
4000  */
4001     static char_u *
4002 term_bg_default(void)
4003 {
4004 #if defined(WIN3264)
4005     /* DOS console nearly always black */
4006     return (char_u *)"dark";
4007 #else
4008     char_u	*p;
4009 
4010     if (STRCMP(T_NAME, "linux") == 0
4011 	    || STRCMP(T_NAME, "screen.linux") == 0
4012 	    || STRCMP(T_NAME, "cygwin") == 0
4013 	    || STRCMP(T_NAME, "putty") == 0
4014 	    || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4015 		&& (p = vim_strrchr(p, ';')) != NULL
4016 		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4017 		&& p[2] == NUL))
4018 	return (char_u *)"dark";
4019     return (char_u *)"light";
4020 #endif
4021 }
4022 
4023 /*
4024  * Initialize the options, part three: After reading the .vimrc
4025  */
4026     void
4027 set_init_3(void)
4028 {
4029 #if defined(UNIX) || defined(WIN3264)
4030 /*
4031  * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4032  * This is done after other initializations, where 'shell' might have been
4033  * set, but only if they have not been set before.
4034  */
4035     char_u  *p;
4036     int	    idx_srr;
4037     int	    do_srr;
4038 # ifdef FEAT_QUICKFIX
4039     int	    idx_sp;
4040     int	    do_sp;
4041 # endif
4042 
4043     idx_srr = findoption((char_u *)"srr");
4044     if (idx_srr < 0)
4045 	do_srr = FALSE;
4046     else
4047 	do_srr = !(options[idx_srr].flags & P_WAS_SET);
4048 # ifdef FEAT_QUICKFIX
4049     idx_sp = findoption((char_u *)"sp");
4050     if (idx_sp < 0)
4051 	do_sp = FALSE;
4052     else
4053 	do_sp = !(options[idx_sp].flags & P_WAS_SET);
4054 # endif
4055     p = get_isolated_shell_name();
4056     if (p != NULL)
4057     {
4058 	/*
4059 	 * Default for p_sp is "| tee", for p_srr is ">".
4060 	 * For known shells it is changed here to include stderr.
4061 	 */
4062 	if (	   fnamecmp(p, "csh") == 0
4063 		|| fnamecmp(p, "tcsh") == 0
4064 # if defined(WIN3264)	/* also check with .exe extension */
4065 		|| fnamecmp(p, "csh.exe") == 0
4066 		|| fnamecmp(p, "tcsh.exe") == 0
4067 # endif
4068 	   )
4069 	{
4070 # if defined(FEAT_QUICKFIX)
4071 	    if (do_sp)
4072 	    {
4073 #  ifdef WIN3264
4074 		p_sp = (char_u *)">&";
4075 #  else
4076 		p_sp = (char_u *)"|& tee";
4077 #  endif
4078 		options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4079 	    }
4080 # endif
4081 	    if (do_srr)
4082 	    {
4083 		p_srr = (char_u *)">&";
4084 		options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4085 	    }
4086 	}
4087 	else
4088 	    /* Always use bourne shell style redirection if we reach this */
4089 	    if (       fnamecmp(p, "sh") == 0
4090 		    || fnamecmp(p, "ksh") == 0
4091 		    || fnamecmp(p, "mksh") == 0
4092 		    || fnamecmp(p, "pdksh") == 0
4093 		    || fnamecmp(p, "zsh") == 0
4094 		    || fnamecmp(p, "zsh-beta") == 0
4095 		    || fnamecmp(p, "bash") == 0
4096 		    || fnamecmp(p, "fish") == 0
4097 # ifdef WIN3264
4098 		    || fnamecmp(p, "cmd") == 0
4099 		    || fnamecmp(p, "sh.exe") == 0
4100 		    || fnamecmp(p, "ksh.exe") == 0
4101 		    || fnamecmp(p, "mksh.exe") == 0
4102 		    || fnamecmp(p, "pdksh.exe") == 0
4103 		    || fnamecmp(p, "zsh.exe") == 0
4104 		    || fnamecmp(p, "zsh-beta.exe") == 0
4105 		    || fnamecmp(p, "bash.exe") == 0
4106 		    || fnamecmp(p, "cmd.exe") == 0
4107 # endif
4108 		    )
4109 	    {
4110 # if defined(FEAT_QUICKFIX)
4111 		if (do_sp)
4112 		{
4113 #  ifdef WIN3264
4114 		    p_sp = (char_u *)">%s 2>&1";
4115 #  else
4116 		    p_sp = (char_u *)"2>&1| tee";
4117 #  endif
4118 		    options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4119 		}
4120 # endif
4121 		if (do_srr)
4122 		{
4123 		    p_srr = (char_u *)">%s 2>&1";
4124 		    options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4125 		}
4126 	    }
4127 	vim_free(p);
4128     }
4129 #endif
4130 
4131 #if defined(WIN3264)
4132     /*
4133      * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4134      * 'shell' option.
4135      * This is done after other initializations, where 'shell' might have been
4136      * set, but only if they have not been set before.  Default for p_shcf is
4137      * "/c", for p_shq is "".  For "sh" like  shells it is changed here to
4138      * "-c" and "\"".  And for Win32 we need to set p_sxq instead.
4139      */
4140     if (strstr((char *)gettail(p_sh), "sh") != NULL)
4141     {
4142 	int	idx3;
4143 
4144 	idx3 = findoption((char_u *)"shcf");
4145 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4146 	{
4147 	    p_shcf = (char_u *)"-c";
4148 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4149 	}
4150 
4151 	/* Somehow Win32 requires the quotes around the redirection too */
4152 	idx3 = findoption((char_u *)"sxq");
4153 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4154 	{
4155 	    p_sxq = (char_u *)"\"";
4156 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4157 	}
4158     }
4159     else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4160     {
4161 	int	idx3;
4162 
4163 	/*
4164 	 * cmd.exe on Windows will strip the first and last double quote given
4165 	 * on the command line, e.g. most of the time things like:
4166 	 *   cmd /c "my path/to/echo" "my args to echo"
4167 	 * become:
4168 	 *   my path/to/echo" "my args to echo
4169 	 * when executed.
4170 	 *
4171 	 * To avoid this, set shellxquote to surround the command in
4172 	 * parenthesis.  This appears to make most commands work, without
4173 	 * breaking commands that worked previously, such as
4174 	 * '"path with spaces/cmd" "a&b"'.
4175 	 */
4176 	idx3 = findoption((char_u *)"sxq");
4177 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4178 	{
4179 	    p_sxq = (char_u *)"(";
4180 	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
4181 	}
4182 
4183 	idx3 = findoption((char_u *)"shcf");
4184 	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4185 	{
4186 	    p_shcf = (char_u *)"/c";
4187 	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
4188 	}
4189     }
4190 #endif
4191 
4192     if (BUFEMPTY())
4193     {
4194 	int idx_ffs = findoption((char_u *)"ffs");
4195 
4196 	/* Apply the first entry of 'fileformats' to the initial buffer. */
4197 	if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4198 	    set_fileformat(default_fileformat(), OPT_LOCAL);
4199     }
4200 
4201 #ifdef FEAT_TITLE
4202     set_title_defaults();
4203 #endif
4204 }
4205 
4206 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
4207 /*
4208  * When 'helplang' is still at its default value, set it to "lang".
4209  * Only the first two characters of "lang" are used.
4210  */
4211     void
4212 set_helplang_default(char_u *lang)
4213 {
4214     int		idx;
4215 
4216     if (lang == NULL || STRLEN(lang) < 2)	/* safety check */
4217 	return;
4218     idx = findoption((char_u *)"hlg");
4219     if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
4220     {
4221 	if (options[idx].flags & P_ALLOCED)
4222 	    free_string_option(p_hlg);
4223 	p_hlg = vim_strsave(lang);
4224 	if (p_hlg == NULL)
4225 	    p_hlg = empty_option;
4226 	else
4227 	{
4228 	    /* zh_CN becomes "cn", zh_TW becomes "tw". */
4229 	    if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4230 	    {
4231 		p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4232 		p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4233 	    }
4234 	    p_hlg[2] = NUL;
4235 	}
4236 	options[idx].flags |= P_ALLOCED;
4237     }
4238 }
4239 #endif
4240 
4241 #ifdef FEAT_GUI
4242 static char_u *gui_bg_default(void);
4243 
4244     static char_u *
4245 gui_bg_default(void)
4246 {
4247     if (gui_get_lightness(gui.back_pixel) < 127)
4248 	return (char_u *)"dark";
4249     return (char_u *)"light";
4250 }
4251 
4252 /*
4253  * Option initializations that can only be done after opening the GUI window.
4254  */
4255     void
4256 init_gui_options(void)
4257 {
4258     /* Set the 'background' option according to the lightness of the
4259      * background color, unless the user has set it already. */
4260     if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4261     {
4262 	set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4263 	highlight_changed();
4264     }
4265 }
4266 #endif
4267 
4268 #ifdef FEAT_TITLE
4269 /*
4270  * 'title' and 'icon' only default to true if they have not been set or reset
4271  * in .vimrc and we can read the old value.
4272  * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4273  * they can be reset.  This reduces startup time when using X on a remote
4274  * machine.
4275  */
4276     void
4277 set_title_defaults(void)
4278 {
4279     int	    idx1;
4280     long    val;
4281 
4282     /*
4283      * If GUI is (going to be) used, we can always set the window title and
4284      * icon name.  Saves a bit of time, because the X11 display server does
4285      * not need to be contacted.
4286      */
4287     idx1 = findoption((char_u *)"title");
4288     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4289     {
4290 #ifdef FEAT_GUI
4291 	if (gui.starting || gui.in_use)
4292 	    val = TRUE;
4293 	else
4294 #endif
4295 	    val = mch_can_restore_title();
4296 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4297 	p_title = val;
4298     }
4299     idx1 = findoption((char_u *)"icon");
4300     if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
4301     {
4302 #ifdef FEAT_GUI
4303 	if (gui.starting || gui.in_use)
4304 	    val = TRUE;
4305 	else
4306 #endif
4307 	    val = mch_can_restore_icon();
4308 	options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
4309 	p_icon = val;
4310     }
4311 }
4312 #endif
4313 
4314 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4315     static void
4316 trigger_optionsset_string(
4317 	int	opt_idx,
4318 	int	opt_flags,
4319 	char_u *oldval,
4320 	char_u *newval)
4321 {
4322     if (oldval != NULL && newval != NULL)
4323     {
4324 	char_u buf_type[7];
4325 
4326 	sprintf((char *)buf_type, "%s",
4327 	    (opt_flags & OPT_LOCAL) ? "local" : "global");
4328 	set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4329 	set_vim_var_string(VV_OPTION_NEW, newval, -1);
4330 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4331 	apply_autocmds(EVENT_OPTIONSET,
4332 		       (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4333 	reset_v_option_vars();
4334     }
4335     vim_free(oldval);
4336     vim_free(newval);
4337 }
4338 #endif
4339 
4340 /*
4341  * Parse 'arg' for option settings.
4342  *
4343  * 'arg' may be IObuff, but only when no errors can be present and option
4344  * does not need to be expanded with option_expand().
4345  * "opt_flags":
4346  * 0 for ":set"
4347  * OPT_GLOBAL   for ":setglobal"
4348  * OPT_LOCAL    for ":setlocal" and a modeline
4349  * OPT_MODELINE for a modeline
4350  * OPT_WINONLY  to only set window-local options
4351  * OPT_NOWIN	to skip setting window-local options
4352  *
4353  * returns FAIL if an error is detected, OK otherwise
4354  */
4355     int
4356 do_set(
4357     char_u	*arg,		/* option string (may be written to!) */
4358     int		opt_flags)
4359 {
4360     int		opt_idx;
4361     char_u	*errmsg;
4362     char_u	errbuf[80];
4363     char_u	*startarg;
4364     int		prefix;	/* 1: nothing, 0: "no", 2: "inv" in front of name */
4365     int		nextchar;	    /* next non-white char after option name */
4366     int		afterchar;	    /* character just after option name */
4367     int		len;
4368     int		i;
4369     varnumber_T	value;
4370     int		key;
4371     long_u	flags;		    /* flags for current option */
4372     char_u	*varp = NULL;	    /* pointer to variable for current option */
4373     int		did_show = FALSE;   /* already showed one value */
4374     int		adding;		    /* "opt+=arg" */
4375     int		prepending;	    /* "opt^=arg" */
4376     int		removing;	    /* "opt-=arg" */
4377     int		cp_val = 0;
4378     char_u	key_name[2];
4379 
4380     if (*arg == NUL)
4381     {
4382 	showoptions(0, opt_flags);
4383 	did_show = TRUE;
4384 	goto theend;
4385     }
4386 
4387     while (*arg != NUL)		/* loop to process all options */
4388     {
4389 	errmsg = NULL;
4390 	startarg = arg;		/* remember for error message */
4391 
4392 	if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4393 						&& !(opt_flags & OPT_MODELINE))
4394 	{
4395 	    /*
4396 	     * ":set all"  show all options.
4397 	     * ":set all&" set all options to their default value.
4398 	     */
4399 	    arg += 3;
4400 	    if (*arg == '&')
4401 	    {
4402 		++arg;
4403 		/* Only for :set command set global value of local options. */
4404 		set_options_default(OPT_FREE | opt_flags);
4405 		didset_options();
4406 		didset_options2();
4407 		redraw_all_later(CLEAR);
4408 	    }
4409 	    else
4410 	    {
4411 		showoptions(1, opt_flags);
4412 		did_show = TRUE;
4413 	    }
4414 	}
4415 	else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
4416 	{
4417 	    showoptions(2, opt_flags);
4418 	    show_termcodes();
4419 	    did_show = TRUE;
4420 	    arg += 7;
4421 	}
4422 	else
4423 	{
4424 	    prefix = 1;
4425 	    if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
4426 	    {
4427 		prefix = 0;
4428 		arg += 2;
4429 	    }
4430 	    else if (STRNCMP(arg, "inv", 3) == 0)
4431 	    {
4432 		prefix = 2;
4433 		arg += 3;
4434 	    }
4435 
4436 	    /* find end of name */
4437 	    key = 0;
4438 	    if (*arg == '<')
4439 	    {
4440 		nextchar = 0;
4441 		opt_idx = -1;
4442 		/* look out for <t_>;> */
4443 		if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4444 		    len = 5;
4445 		else
4446 		{
4447 		    len = 1;
4448 		    while (arg[len] != NUL && arg[len] != '>')
4449 			++len;
4450 		}
4451 		if (arg[len] != '>')
4452 		{
4453 		    errmsg = e_invarg;
4454 		    goto skip;
4455 		}
4456 		arg[len] = NUL;			    /* put NUL after name */
4457 		if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4458 		    opt_idx = findoption(arg + 1);
4459 		arg[len++] = '>';		    /* restore '>' */
4460 		if (opt_idx == -1)
4461 		    key = find_key_option(arg + 1);
4462 	    }
4463 	    else
4464 	    {
4465 		len = 0;
4466 		/*
4467 		 * The two characters after "t_" may not be alphanumeric.
4468 		 */
4469 		if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4470 		    len = 4;
4471 		else
4472 		    while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4473 			++len;
4474 		nextchar = arg[len];
4475 		arg[len] = NUL;			    /* put NUL after name */
4476 		opt_idx = findoption(arg);
4477 		arg[len] = nextchar;		    /* restore nextchar */
4478 		if (opt_idx == -1)
4479 		    key = find_key_option(arg);
4480 	    }
4481 
4482 	    /* remember character after option name */
4483 	    afterchar = arg[len];
4484 
4485 	    /* skip white space, allow ":set ai  ?" */
4486 	    while (VIM_ISWHITE(arg[len]))
4487 		++len;
4488 
4489 	    adding = FALSE;
4490 	    prepending = FALSE;
4491 	    removing = FALSE;
4492 	    if (arg[len] != NUL && arg[len + 1] == '=')
4493 	    {
4494 		if (arg[len] == '+')
4495 		{
4496 		    adding = TRUE;		/* "+=" */
4497 		    ++len;
4498 		}
4499 		else if (arg[len] == '^')
4500 		{
4501 		    prepending = TRUE;		/* "^=" */
4502 		    ++len;
4503 		}
4504 		else if (arg[len] == '-')
4505 		{
4506 		    removing = TRUE;		/* "-=" */
4507 		    ++len;
4508 		}
4509 	    }
4510 	    nextchar = arg[len];
4511 
4512 	    if (opt_idx == -1 && key == 0)	/* found a mismatch: skip */
4513 	    {
4514 		errmsg = (char_u *)N_("E518: Unknown option");
4515 		goto skip;
4516 	    }
4517 
4518 	    if (opt_idx >= 0)
4519 	    {
4520 		if (options[opt_idx].var == NULL)   /* hidden option: skip */
4521 		{
4522 		    /* Only give an error message when requesting the value of
4523 		     * a hidden option, ignore setting it. */
4524 		    if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4525 			    && (!(options[opt_idx].flags & P_BOOL)
4526 				|| nextchar == '?'))
4527 			errmsg = (char_u *)N_("E519: Option not supported");
4528 		    goto skip;
4529 		}
4530 
4531 		flags = options[opt_idx].flags;
4532 		varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4533 	    }
4534 	    else
4535 	    {
4536 		flags = P_STRING;
4537 		if (key < 0)
4538 		{
4539 		    key_name[0] = KEY2TERMCAP0(key);
4540 		    key_name[1] = KEY2TERMCAP1(key);
4541 		}
4542 		else
4543 		{
4544 		    key_name[0] = KS_KEY;
4545 		    key_name[1] = (key & 0xff);
4546 		}
4547 	    }
4548 
4549 	    /* Skip all options that are not window-local (used when showing
4550 	     * an already loaded buffer in a window). */
4551 	    if ((opt_flags & OPT_WINONLY)
4552 			  && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4553 		goto skip;
4554 
4555 	    /* Skip all options that are window-local (used for :vimgrep). */
4556 	    if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4557 					   && options[opt_idx].var == VAR_WIN)
4558 		goto skip;
4559 
4560 	    /* Disallow changing some options from modelines. */
4561 	    if (opt_flags & OPT_MODELINE)
4562 	    {
4563 		if (flags & (P_SECURE | P_NO_ML))
4564 		{
4565 		    errmsg = (char_u *)_("E520: Not allowed in a modeline");
4566 		    goto skip;
4567 		}
4568 #ifdef FEAT_DIFF
4569 		/* In diff mode some options are overruled.  This avoids that
4570 		 * 'foldmethod' becomes "marker" instead of "diff" and that
4571 		 * "wrap" gets set. */
4572 		if (curwin->w_p_diff
4573 			&& opt_idx >= 0  /* shut up coverity warning */
4574 			&& (
4575 #ifdef FEAT_FOLDING
4576 			    options[opt_idx].indir == PV_FDM ||
4577 #endif
4578 			    options[opt_idx].indir == PV_WRAP))
4579 		    goto skip;
4580 #endif
4581 	    }
4582 
4583 #ifdef HAVE_SANDBOX
4584 	    /* Disallow changing some options in the sandbox */
4585 	    if (sandbox != 0 && (flags & P_SECURE))
4586 	    {
4587 		errmsg = (char_u *)_(e_sandbox);
4588 		goto skip;
4589 	    }
4590 #endif
4591 
4592 	    if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4593 	    {
4594 		arg += len;
4595 		cp_val = p_cp;
4596 		if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4597 		{
4598 		    if (arg[3] == 'm')	/* "opt&vim": set to Vim default */
4599 		    {
4600 			cp_val = FALSE;
4601 			arg += 3;
4602 		    }
4603 		    else		/* "opt&vi": set to Vi default */
4604 		    {
4605 			cp_val = TRUE;
4606 			arg += 2;
4607 		    }
4608 		}
4609 		if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4610 			&& arg[1] != NUL && !VIM_ISWHITE(arg[1]))
4611 		{
4612 		    errmsg = e_trailing;
4613 		    goto skip;
4614 		}
4615 	    }
4616 
4617 	    /*
4618 	     * allow '=' and ':' for hystorical reasons (MSDOS command.com
4619 	     * allows only one '=' character per "set" command line. grrr. (jw)
4620 	     */
4621 	    if (nextchar == '?'
4622 		    || (prefix == 1
4623 			&& vim_strchr((char_u *)"=:&<", nextchar) == NULL
4624 			&& !(flags & P_BOOL)))
4625 	    {
4626 		/*
4627 		 * print value
4628 		 */
4629 		if (did_show)
4630 		    msg_putchar('\n');	    /* cursor below last one */
4631 		else
4632 		{
4633 		    gotocmdline(TRUE);	    /* cursor at status line */
4634 		    did_show = TRUE;	    /* remember that we did a line */
4635 		}
4636 		if (opt_idx >= 0)
4637 		{
4638 		    showoneopt(&options[opt_idx], opt_flags);
4639 #ifdef FEAT_EVAL
4640 		    if (p_verbose > 0)
4641 		    {
4642 			/* Mention where the option was last set. */
4643 			if (varp == options[opt_idx].var)
4644 			    last_set_msg(options[opt_idx].scriptID);
4645 			else if ((int)options[opt_idx].indir & PV_WIN)
4646 			    last_set_msg(curwin->w_p_scriptID[
4647 				      (int)options[opt_idx].indir & PV_MASK]);
4648 			else if ((int)options[opt_idx].indir & PV_BUF)
4649 			    last_set_msg(curbuf->b_p_scriptID[
4650 				      (int)options[opt_idx].indir & PV_MASK]);
4651 		    }
4652 #endif
4653 		}
4654 		else
4655 		{
4656 		    char_u	    *p;
4657 
4658 		    p = find_termcode(key_name);
4659 		    if (p == NULL)
4660 		    {
4661 			errmsg = (char_u *)N_("E846: Key code not set");
4662 			goto skip;
4663 		    }
4664 		    else
4665 			(void)show_one_termcode(key_name, p, TRUE);
4666 		}
4667 		if (nextchar != '?'
4668 			&& nextchar != NUL && !VIM_ISWHITE(afterchar))
4669 		    errmsg = e_trailing;
4670 	    }
4671 	    else
4672 	    {
4673 		if (flags & P_BOOL)		    /* boolean */
4674 		{
4675 		    if (nextchar == '=' || nextchar == ':')
4676 		    {
4677 			errmsg = e_invarg;
4678 			goto skip;
4679 		    }
4680 
4681 		    /*
4682 		     * ":set opt!": invert
4683 		     * ":set opt&": reset to default value
4684 		     * ":set opt<": reset to global value
4685 		     */
4686 		    if (nextchar == '!')
4687 			value = *(int *)(varp) ^ 1;
4688 		    else if (nextchar == '&')
4689 			value = (int)(long)(long_i)options[opt_idx].def_val[
4690 						((flags & P_VI_DEF) || cp_val)
4691 						 ?  VI_DEFAULT : VIM_DEFAULT];
4692 		    else if (nextchar == '<')
4693 		    {
4694 			/* For 'autoread' -1 means to use global value. */
4695 			if ((int *)varp == &curbuf->b_p_ar
4696 						    && opt_flags == OPT_LOCAL)
4697 			    value = -1;
4698 			else
4699 			    value = *(int *)get_varp_scope(&(options[opt_idx]),
4700 								  OPT_GLOBAL);
4701 		    }
4702 		    else
4703 		    {
4704 			/*
4705 			 * ":set invopt": invert
4706 			 * ":set opt" or ":set noopt": set or reset
4707 			 */
4708 			if (nextchar != NUL && !VIM_ISWHITE(afterchar))
4709 			{
4710 			    errmsg = e_trailing;
4711 			    goto skip;
4712 			}
4713 			if (prefix == 2)	/* inv */
4714 			    value = *(int *)(varp) ^ 1;
4715 			else
4716 			    value = prefix;
4717 		    }
4718 
4719 		    errmsg = set_bool_option(opt_idx, varp, (int)value,
4720 								   opt_flags);
4721 		}
4722 		else				    /* numeric or string */
4723 		{
4724 		    if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4725 							       || prefix != 1)
4726 		    {
4727 			errmsg = e_invarg;
4728 			goto skip;
4729 		    }
4730 
4731 		    if (flags & P_NUM)		    /* numeric */
4732 		    {
4733 			/*
4734 			 * Different ways to set a number option:
4735 			 * &	    set to default value
4736 			 * <	    set to global value
4737 			 * <xx>	    accept special key codes for 'wildchar'
4738 			 * c	    accept any non-digit for 'wildchar'
4739 			 * [-]0-9   set number
4740 			 * other    error
4741 			 */
4742 			++arg;
4743 			if (nextchar == '&')
4744 			    value = (long)(long_i)options[opt_idx].def_val[
4745 						((flags & P_VI_DEF) || cp_val)
4746 						 ?  VI_DEFAULT : VIM_DEFAULT];
4747 			else if (nextchar == '<')
4748 			{
4749 			    /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4750 			     * use the global value. */
4751 			    if ((long *)varp == &curbuf->b_p_ul
4752 						    && opt_flags == OPT_LOCAL)
4753 				value = NO_LOCAL_UNDOLEVEL;
4754 			    else
4755 				value = *(long *)get_varp_scope(
4756 					     &(options[opt_idx]), OPT_GLOBAL);
4757 			}
4758 			else if (((long *)varp == &p_wc
4759 				    || (long *)varp == &p_wcm)
4760 				&& (*arg == '<'
4761 				    || *arg == '^'
4762 				    || (*arg != NUL
4763 					&& (!arg[1] || VIM_ISWHITE(arg[1]))
4764 					&& !VIM_ISDIGIT(*arg))))
4765 			{
4766 			    value = string_to_key(arg, FALSE);
4767 			    if (value == 0 && (long *)varp != &p_wcm)
4768 			    {
4769 				errmsg = e_invarg;
4770 				goto skip;
4771 			    }
4772 			}
4773 			else if (*arg == '-' || VIM_ISDIGIT(*arg))
4774 			{
4775 			    /* Allow negative (for 'undolevels'), octal and
4776 			     * hex numbers. */
4777 			    vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4778 							     &value, NULL, 0);
4779 			    if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
4780 			    {
4781 				errmsg = e_invarg;
4782 				goto skip;
4783 			    }
4784 			}
4785 			else
4786 			{
4787 			    errmsg = (char_u *)N_("E521: Number required after =");
4788 			    goto skip;
4789 			}
4790 
4791 			if (adding)
4792 			    value = *(long *)varp + value;
4793 			if (prepending)
4794 			    value = *(long *)varp * value;
4795 			if (removing)
4796 			    value = *(long *)varp - value;
4797 			errmsg = set_num_option(opt_idx, varp, value,
4798 					   errbuf, sizeof(errbuf), opt_flags);
4799 		    }
4800 		    else if (opt_idx >= 0)		    /* string */
4801 		    {
4802 			char_u	    *save_arg = NULL;
4803 			char_u	    *s = NULL;
4804 			char_u	    *oldval = NULL;	/* previous value if *varp */
4805 			char_u	    *newval;
4806 			char_u	    *origval = NULL;
4807 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4808 			char_u	    *saved_origval = NULL;
4809 			char_u	    *saved_newval = NULL;
4810 #endif
4811 			unsigned    newlen;
4812 			int	    comma;
4813 			int	    bs;
4814 			int	    new_value_alloced;	/* new string option
4815 							   was allocated */
4816 
4817 			/* When using ":set opt=val" for a global option
4818 			 * with a local value the local value will be
4819 			 * reset, use the global value here. */
4820 			if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
4821 				&& ((int)options[opt_idx].indir & PV_BOTH))
4822 			    varp = options[opt_idx].var;
4823 
4824 			/* The old value is kept until we are sure that the
4825 			 * new value is valid. */
4826 			oldval = *(char_u **)varp;
4827 			if (nextchar == '&')	/* set to default val */
4828 			{
4829 			    newval = options[opt_idx].def_val[
4830 						((flags & P_VI_DEF) || cp_val)
4831 						 ?  VI_DEFAULT : VIM_DEFAULT];
4832 			    if ((char_u **)varp == &p_bg)
4833 			    {
4834 				/* guess the value of 'background' */
4835 #ifdef FEAT_GUI
4836 				if (gui.in_use)
4837 				    newval = gui_bg_default();
4838 				else
4839 #endif
4840 				    newval = term_bg_default();
4841 			    }
4842 
4843 			    /* expand environment variables and ~ (since the
4844 			     * default value was already expanded, only
4845 			     * required when an environment variable was set
4846 			     * later */
4847 			    if (newval == NULL)
4848 				newval = empty_option;
4849 			    else
4850 			    {
4851 				s = option_expand(opt_idx, newval);
4852 				if (s == NULL)
4853 				    s = newval;
4854 				newval = vim_strsave(s);
4855 			    }
4856 			    new_value_alloced = TRUE;
4857 			}
4858 			else if (nextchar == '<')	/* set to global val */
4859 			{
4860 			    newval = vim_strsave(*(char_u **)get_varp_scope(
4861 					     &(options[opt_idx]), OPT_GLOBAL));
4862 			    new_value_alloced = TRUE;
4863 			}
4864 			else
4865 			{
4866 			    ++arg;	/* jump to after the '=' or ':' */
4867 
4868 			    /*
4869 			     * Set 'keywordprg' to ":help" if an empty
4870 			     * value was passed to :set by the user.
4871 			     * Misuse errbuf[] for the resulting string.
4872 			     */
4873 			    if (varp == (char_u *)&p_kp
4874 					      && (*arg == NUL || *arg == ' '))
4875 			    {
4876 				STRCPY(errbuf, ":help");
4877 				save_arg = arg;
4878 				arg = errbuf;
4879 			    }
4880 			    /*
4881 			     * Convert 'backspace' number to string, for
4882 			     * adding, prepending and removing string.
4883 			     */
4884 			    else if (varp == (char_u *)&p_bs
4885 					 && VIM_ISDIGIT(**(char_u **)varp))
4886 			    {
4887 				i = getdigits((char_u **)varp);
4888 				switch (i)
4889 				{
4890 				    case 0:
4891 					*(char_u **)varp = empty_option;
4892 					break;
4893 				    case 1:
4894 					*(char_u **)varp = vim_strsave(
4895 						      (char_u *)"indent,eol");
4896 					break;
4897 				    case 2:
4898 					*(char_u **)varp = vim_strsave(
4899 						(char_u *)"indent,eol,start");
4900 					break;
4901 				}
4902 				vim_free(oldval);
4903 				oldval = *(char_u **)varp;
4904 			    }
4905 			    /*
4906 			     * Convert 'whichwrap' number to string, for
4907 			     * backwards compatibility with Vim 3.0.
4908 			     * Misuse errbuf[] for the resulting string.
4909 			     */
4910 			    else if (varp == (char_u *)&p_ww
4911 							 && VIM_ISDIGIT(*arg))
4912 			    {
4913 				*errbuf = NUL;
4914 				i = getdigits(&arg);
4915 				if (i & 1)
4916 				    STRCAT(errbuf, "b,");
4917 				if (i & 2)
4918 				    STRCAT(errbuf, "s,");
4919 				if (i & 4)
4920 				    STRCAT(errbuf, "h,l,");
4921 				if (i & 8)
4922 				    STRCAT(errbuf, "<,>,");
4923 				if (i & 16)
4924 				    STRCAT(errbuf, "[,],");
4925 				if (*errbuf != NUL)	/* remove trailing , */
4926 				    errbuf[STRLEN(errbuf) - 1] = NUL;
4927 				save_arg = arg;
4928 				arg = errbuf;
4929 			    }
4930 			    /*
4931 			     * Remove '>' before 'dir' and 'bdir', for
4932 			     * backwards compatibility with version 3.0
4933 			     */
4934 			    else if (  *arg == '>'
4935 				    && (varp == (char_u *)&p_dir
4936 					    || varp == (char_u *)&p_bdir))
4937 			    {
4938 				++arg;
4939 			    }
4940 
4941 			    /* When setting the local value of a global
4942 			     * option, the old value may be the global value. */
4943 			    if (((int)options[opt_idx].indir & PV_BOTH)
4944 						   && (opt_flags & OPT_LOCAL))
4945 				origval = *(char_u **)get_varp(
4946 							   &options[opt_idx]);
4947 			    else
4948 				origval = oldval;
4949 
4950 			    /*
4951 			     * Copy the new string into allocated memory.
4952 			     * Can't use set_string_option_direct(), because
4953 			     * we need to remove the backslashes.
4954 			     */
4955 			    /* get a bit too much */
4956 			    newlen = (unsigned)STRLEN(arg) + 1;
4957 			    if (adding || prepending || removing)
4958 				newlen += (unsigned)STRLEN(origval) + 1;
4959 			    newval = alloc(newlen);
4960 			    if (newval == NULL)  /* out of mem, don't change */
4961 				break;
4962 			    s = newval;
4963 
4964 			    /*
4965 			     * Copy the string, skip over escaped chars.
4966 			     * For MS-DOS and WIN32 backslashes before normal
4967 			     * file name characters are not removed, and keep
4968 			     * backslash at start, for "\\machine\path", but
4969 			     * do remove it for "\\\\machine\\path".
4970 			     * The reverse is found in ExpandOldSetting().
4971 			     */
4972 			    while (*arg && !VIM_ISWHITE(*arg))
4973 			    {
4974 				if (*arg == '\\' && arg[1] != NUL
4975 #ifdef BACKSLASH_IN_FILENAME
4976 					&& !((flags & P_EXPAND)
4977 						&& vim_isfilec(arg[1])
4978 						&& (arg[1] != '\\'
4979 						    || (s == newval
4980 							&& arg[2] != '\\')))
4981 #endif
4982 								    )
4983 				    ++arg;	/* remove backslash */
4984 #ifdef FEAT_MBYTE
4985 				if (has_mbyte
4986 					&& (i = (*mb_ptr2len)(arg)) > 1)
4987 				{
4988 				    /* copy multibyte char */
4989 				    mch_memmove(s, arg, (size_t)i);
4990 				    arg += i;
4991 				    s += i;
4992 				}
4993 				else
4994 #endif
4995 				    *s++ = *arg++;
4996 			    }
4997 			    *s = NUL;
4998 
4999 			    /*
5000 			     * Expand environment variables and ~.
5001 			     * Don't do it when adding without inserting a
5002 			     * comma.
5003 			     */
5004 			    if (!(adding || prepending || removing)
5005 							 || (flags & P_COMMA))
5006 			    {
5007 				s = option_expand(opt_idx, newval);
5008 				if (s != NULL)
5009 				{
5010 				    vim_free(newval);
5011 				    newlen = (unsigned)STRLEN(s) + 1;
5012 				    if (adding || prepending || removing)
5013 					newlen += (unsigned)STRLEN(origval) + 1;
5014 				    newval = alloc(newlen);
5015 				    if (newval == NULL)
5016 					break;
5017 				    STRCPY(newval, s);
5018 				}
5019 			    }
5020 
5021 			    /* locate newval[] in origval[] when removing it
5022 			     * and when adding to avoid duplicates */
5023 			    i = 0;	/* init for GCC */
5024 			    if (removing || (flags & P_NODUP))
5025 			    {
5026 				i = (int)STRLEN(newval);
5027 				bs = 0;
5028 				for (s = origval; *s; ++s)
5029 				{
5030 				    if ((!(flags & P_COMMA)
5031 						|| s == origval
5032 						|| (s[-1] == ',' && !(bs & 1)))
5033 					    && STRNCMP(s, newval, i) == 0
5034 					    && (!(flags & P_COMMA)
5035 						|| s[i] == ','
5036 						|| s[i] == NUL))
5037 					break;
5038 				    /* Count backslashes.  Only a comma with an
5039 				     * even number of backslashes or a single
5040 				     * backslash preceded by a comma before it
5041 				     * is recognized as a separator */
5042 				    if ((s > origval + 1
5043 						&& s[-1] == '\\'
5044 						&& s[-2] != ',')
5045 					    || (s == origval + 1
5046 						&& s[-1] == '\\'))
5047 
5048 					++bs;
5049 				    else
5050 					bs = 0;
5051 				}
5052 
5053 				/* do not add if already there */
5054 				if ((adding || prepending) && *s)
5055 				{
5056 				    prepending = FALSE;
5057 				    adding = FALSE;
5058 				    STRCPY(newval, origval);
5059 				}
5060 			    }
5061 
5062 			    /* concatenate the two strings; add a ',' if
5063 			     * needed */
5064 			    if (adding || prepending)
5065 			    {
5066 				comma = ((flags & P_COMMA) && *origval != NUL
5067 							   && *newval != NUL);
5068 				if (adding)
5069 				{
5070 				    i = (int)STRLEN(origval);
5071 				    /* strip a trailing comma, would get 2 */
5072 				    if (comma && i > 1
5073 					  && (flags & P_ONECOMMA) == P_ONECOMMA
5074 					  && origval[i - 1] == ','
5075 					  && origval[i - 2] != '\\')
5076 					i--;
5077 				    mch_memmove(newval + i + comma, newval,
5078 							  STRLEN(newval) + 1);
5079 				    mch_memmove(newval, origval, (size_t)i);
5080 				}
5081 				else
5082 				{
5083 				    i = (int)STRLEN(newval);
5084 				    STRMOVE(newval + i + comma, origval);
5085 				}
5086 				if (comma)
5087 				    newval[i] = ',';
5088 			    }
5089 
5090 			    /* Remove newval[] from origval[]. (Note: "i" has
5091 			     * been set above and is used here). */
5092 			    if (removing)
5093 			    {
5094 				STRCPY(newval, origval);
5095 				if (*s)
5096 				{
5097 				    /* may need to remove a comma */
5098 				    if (flags & P_COMMA)
5099 				    {
5100 					if (s == origval)
5101 					{
5102 					    /* include comma after string */
5103 					    if (s[i] == ',')
5104 						++i;
5105 					}
5106 					else
5107 					{
5108 					    /* include comma before string */
5109 					    --s;
5110 					    ++i;
5111 					}
5112 				    }
5113 				    STRMOVE(newval + (s - origval), s + i);
5114 				}
5115 			    }
5116 
5117 			    if (flags & P_FLAGLIST)
5118 			    {
5119 				/* Remove flags that appear twice. */
5120 				for (s = newval; *s;)
5121 				{
5122 				    /* if options have P_FLAGLIST and
5123 				     * P_ONECOMMA such as 'whichwrap' */
5124 				    if (flags & P_ONECOMMA)
5125 				    {
5126 					if (*s != ',' && *(s + 1) == ','
5127 					      && vim_strchr(s + 2, *s) != NULL)
5128 					{
5129 					    /* Remove the duplicated value and
5130 					     * the next comma. */
5131 					    STRMOVE(s, s + 2);
5132 					    continue;
5133 					}
5134 				    }
5135 				    else
5136 				    {
5137 					if ((!(flags & P_COMMA) || *s != ',')
5138 					      && vim_strchr(s + 1, *s) != NULL)
5139 					{
5140 					    STRMOVE(s, s + 1);
5141 					    continue;
5142 					}
5143 				    }
5144 				    ++s;
5145 				}
5146 			    }
5147 
5148 			    if (save_arg != NULL)   /* number for 'whichwrap' */
5149 				arg = save_arg;
5150 			    new_value_alloced = TRUE;
5151 			}
5152 
5153 			/* Set the new value. */
5154 			*(char_u **)(varp) = newval;
5155 
5156 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5157 			if (!starting
5158 # ifdef FEAT_CRYPT
5159 				&& options[opt_idx].indir != PV_KEY
5160 # endif
5161 					  && origval != NULL && newval != NULL)
5162 			{
5163 			    /* origval may be freed by
5164 			     * did_set_string_option(), make a copy. */
5165 			    saved_origval = vim_strsave(origval);
5166 			    /* newval (and varp) may become invalid if the
5167 			     * buffer is closed by autocommands. */
5168 			    saved_newval = vim_strsave(newval);
5169 			}
5170 #endif
5171 
5172 			/* Handle side effects, and set the global value for
5173 			 * ":set" on local options. Note: when setting 'syntax'
5174 			 * or 'filetype' autocommands may be triggered that can
5175 			 * cause havoc. */
5176 			errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5177 				new_value_alloced, oldval, errbuf, opt_flags);
5178 
5179 			/* If error detected, print the error message. */
5180 			if (errmsg != NULL)
5181 			{
5182 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5183 			    vim_free(saved_origval);
5184 			    vim_free(saved_newval);
5185 #endif
5186 			    goto skip;
5187 			}
5188 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5189 			trigger_optionsset_string(opt_idx, opt_flags,
5190 						  saved_origval, saved_newval);
5191 #endif
5192 		    }
5193 		    else	    /* key code option */
5194 		    {
5195 			char_u	    *p;
5196 
5197 			if (nextchar == '&')
5198 			{
5199 			    if (add_termcap_entry(key_name, TRUE) == FAIL)
5200 				errmsg = (char_u *)N_("E522: Not found in termcap");
5201 			}
5202 			else
5203 			{
5204 			    ++arg; /* jump to after the '=' or ':' */
5205 			    for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
5206 				if (*p == '\\' && p[1] != NUL)
5207 				    ++p;
5208 			    nextchar = *p;
5209 			    *p = NUL;
5210 			    add_termcode(key_name, arg, FALSE);
5211 			    *p = nextchar;
5212 			}
5213 			if (full_screen)
5214 			    ttest(FALSE);
5215 			redraw_all_later(CLEAR);
5216 		    }
5217 		}
5218 
5219 		if (opt_idx >= 0)
5220 		    did_set_option(opt_idx, opt_flags,
5221 					 !prepending && !adding && !removing);
5222 	    }
5223 
5224 skip:
5225 	    /*
5226 	     * Advance to next argument.
5227 	     * - skip until a blank found, taking care of backslashes
5228 	     * - skip blanks
5229 	     * - skip one "=val" argument (for hidden options ":set gfn =xx")
5230 	     */
5231 	    for (i = 0; i < 2 ; ++i)
5232 	    {
5233 		while (*arg != NUL && !VIM_ISWHITE(*arg))
5234 		    if (*arg++ == '\\' && *arg != NUL)
5235 			++arg;
5236 		arg = skipwhite(arg);
5237 		if (*arg != '=')
5238 		    break;
5239 	    }
5240 	}
5241 
5242 	if (errmsg != NULL)
5243 	{
5244 	    vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
5245 	    i = (int)STRLEN(IObuff) + 2;
5246 	    if (i + (arg - startarg) < IOSIZE)
5247 	    {
5248 		/* append the argument with the error */
5249 		STRCAT(IObuff, ": ");
5250 		mch_memmove(IObuff + i, startarg, (arg - startarg));
5251 		IObuff[i + (arg - startarg)] = NUL;
5252 	    }
5253 	    /* make sure all characters are printable */
5254 	    trans_characters(IObuff, IOSIZE);
5255 
5256 	    ++no_wait_return;	/* wait_return done later */
5257 	    emsg(IObuff);	/* show error highlighted */
5258 	    --no_wait_return;
5259 
5260 	    return FAIL;
5261 	}
5262 
5263 	arg = skipwhite(arg);
5264     }
5265 
5266 theend:
5267     if (silent_mode && did_show)
5268     {
5269 	/* After displaying option values in silent mode. */
5270 	silent_mode = FALSE;
5271 	info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
5272 	msg_putchar('\n');
5273 	cursor_on();		/* msg_start() switches it off */
5274 	out_flush();
5275 	silent_mode = TRUE;
5276 	info_message = FALSE;	/* use mch_msg(), not mch_errmsg() */
5277     }
5278 
5279     return OK;
5280 }
5281 
5282 /*
5283  * Call this when an option has been given a new value through a user command.
5284  * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5285  */
5286     static void
5287 did_set_option(
5288     int	    opt_idx,
5289     int	    opt_flags,	    /* possibly with OPT_MODELINE */
5290     int	    new_value)	    /* value was replaced completely */
5291 {
5292     long_u	*p;
5293 
5294     options[opt_idx].flags |= P_WAS_SET;
5295 
5296     /* When an option is set in the sandbox, from a modeline or in secure mode
5297      * set the P_INSECURE flag.  Otherwise, if a new value is stored reset the
5298      * flag. */
5299     p = insecure_flag(opt_idx, opt_flags);
5300     if (secure
5301 #ifdef HAVE_SANDBOX
5302 	    || sandbox != 0
5303 #endif
5304 	    || (opt_flags & OPT_MODELINE))
5305 	*p = *p | P_INSECURE;
5306     else if (new_value)
5307 	*p = *p & ~P_INSECURE;
5308 }
5309 
5310     static char_u *
5311 illegal_char(char_u *errbuf, int c)
5312 {
5313     if (errbuf == NULL)
5314 	return (char_u *)"";
5315     sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
5316 							(char *)transchar(c));
5317     return errbuf;
5318 }
5319 
5320 /*
5321  * Convert a key name or string into a key value.
5322  * Used for 'wildchar' and 'cedit' options.
5323  * When "multi_byte" is TRUE allow for multi-byte characters.
5324  */
5325     int
5326 string_to_key(char_u *arg, int multi_byte)
5327 {
5328     if (*arg == '<')
5329 	return find_key_option(arg + 1);
5330     if (*arg == '^')
5331 	return Ctrl_chr(arg[1]);
5332     if (multi_byte)
5333 	return PTR2CHAR(arg);
5334     return *arg;
5335 }
5336 
5337 #ifdef FEAT_CMDWIN
5338 /*
5339  * Check value of 'cedit' and set cedit_key.
5340  * Returns NULL if value is OK, error message otherwise.
5341  */
5342     static char_u *
5343 check_cedit(void)
5344 {
5345     int n;
5346 
5347     if (*p_cedit == NUL)
5348 	cedit_key = -1;
5349     else
5350     {
5351 	n = string_to_key(p_cedit, FALSE);
5352 	if (vim_isprintc(n))
5353 	    return e_invarg;
5354 	cedit_key = n;
5355     }
5356     return NULL;
5357 }
5358 #endif
5359 
5360 #ifdef FEAT_TITLE
5361 /*
5362  * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5363  * maketitle() to create and display it.
5364  * When switching the title or icon off, call mch_restore_title() to get
5365  * the old value back.
5366  */
5367     static void
5368 did_set_title(
5369     int	    icon)	    /* Did set icon instead of title */
5370 {
5371     if (starting != NO_SCREEN
5372 #ifdef FEAT_GUI
5373 	    && !gui.starting
5374 #endif
5375 				)
5376     {
5377 	maketitle();
5378 	if (icon)
5379 	{
5380 	    if (!p_icon)
5381 		mch_restore_title(2);
5382 	}
5383 	else
5384 	{
5385 	    if (!p_title)
5386 		mch_restore_title(1);
5387 	}
5388     }
5389 }
5390 #endif
5391 
5392 /*
5393  * set_options_bin -  called when 'bin' changes value.
5394  */
5395     void
5396 set_options_bin(
5397     int		oldval,
5398     int		newval,
5399     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5400 {
5401     /*
5402      * The option values that are changed when 'bin' changes are
5403      * copied when 'bin is set and restored when 'bin' is reset.
5404      */
5405     if (newval)
5406     {
5407 	if (!oldval)		/* switched on */
5408 	{
5409 	    if (!(opt_flags & OPT_GLOBAL))
5410 	    {
5411 		curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5412 		curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5413 		curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5414 		curbuf->b_p_et_nobin = curbuf->b_p_et;
5415 	    }
5416 	    if (!(opt_flags & OPT_LOCAL))
5417 	    {
5418 		p_tw_nobin = p_tw;
5419 		p_wm_nobin = p_wm;
5420 		p_ml_nobin = p_ml;
5421 		p_et_nobin = p_et;
5422 	    }
5423 	}
5424 
5425 	if (!(opt_flags & OPT_GLOBAL))
5426 	{
5427 	    curbuf->b_p_tw = 0;	/* no automatic line wrap */
5428 	    curbuf->b_p_wm = 0;	/* no automatic line wrap */
5429 	    curbuf->b_p_ml = 0;	/* no modelines */
5430 	    curbuf->b_p_et = 0;	/* no expandtab */
5431 	}
5432 	if (!(opt_flags & OPT_LOCAL))
5433 	{
5434 	    p_tw = 0;
5435 	    p_wm = 0;
5436 	    p_ml = FALSE;
5437 	    p_et = FALSE;
5438 	    p_bin = TRUE;	/* needed when called for the "-b" argument */
5439 	}
5440     }
5441     else if (oldval)		/* switched off */
5442     {
5443 	if (!(opt_flags & OPT_GLOBAL))
5444 	{
5445 	    curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5446 	    curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5447 	    curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5448 	    curbuf->b_p_et = curbuf->b_p_et_nobin;
5449 	}
5450 	if (!(opt_flags & OPT_LOCAL))
5451 	{
5452 	    p_tw = p_tw_nobin;
5453 	    p_wm = p_wm_nobin;
5454 	    p_ml = p_ml_nobin;
5455 	    p_et = p_et_nobin;
5456 	}
5457     }
5458 }
5459 
5460 #ifdef FEAT_VIMINFO
5461 /*
5462  * Find the parameter represented by the given character (eg ', :, ", or /),
5463  * and return its associated value in the 'viminfo' string.
5464  * Only works for number parameters, not for 'r' or 'n'.
5465  * If the parameter is not specified in the string or there is no following
5466  * number, return -1.
5467  */
5468     int
5469 get_viminfo_parameter(int type)
5470 {
5471     char_u  *p;
5472 
5473     p = find_viminfo_parameter(type);
5474     if (p != NULL && VIM_ISDIGIT(*p))
5475 	return atoi((char *)p);
5476     return -1;
5477 }
5478 
5479 /*
5480  * Find the parameter represented by the given character (eg ''', ':', '"', or
5481  * '/') in the 'viminfo' option and return a pointer to the string after it.
5482  * Return NULL if the parameter is not specified in the string.
5483  */
5484     char_u *
5485 find_viminfo_parameter(int type)
5486 {
5487     char_u  *p;
5488 
5489     for (p = p_viminfo; *p; ++p)
5490     {
5491 	if (*p == type)
5492 	    return p + 1;
5493 	if (*p == 'n')		    /* 'n' is always the last one */
5494 	    break;
5495 	p = vim_strchr(p, ',');	    /* skip until next ',' */
5496 	if (p == NULL)		    /* hit the end without finding parameter */
5497 	    break;
5498     }
5499     return NULL;
5500 }
5501 #endif
5502 
5503 /*
5504  * Expand environment variables for some string options.
5505  * These string options cannot be indirect!
5506  * If "val" is NULL expand the current value of the option.
5507  * Return pointer to NameBuff, or NULL when not expanded.
5508  */
5509     static char_u *
5510 option_expand(int opt_idx, char_u *val)
5511 {
5512     /* if option doesn't need expansion nothing to do */
5513     if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5514 	return NULL;
5515 
5516     /* If val is longer than MAXPATHL no meaningful expansion can be done,
5517      * expand_env() would truncate the string. */
5518     if (val != NULL && STRLEN(val) > MAXPATHL)
5519 	return NULL;
5520 
5521     if (val == NULL)
5522 	val = *(char_u **)options[opt_idx].var;
5523 
5524     /*
5525      * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5526      * Escape spaces when expanding 'tags', they are used to separate file
5527      * names.
5528      * For 'spellsuggest' expand after "file:".
5529      */
5530     expand_env_esc(val, NameBuff, MAXPATHL,
5531 	    (char_u **)options[opt_idx].var == &p_tags, FALSE,
5532 #ifdef FEAT_SPELL
5533 	    (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5534 #endif
5535 				  NULL);
5536     if (STRCMP(NameBuff, val) == 0)   /* they are the same */
5537 	return NULL;
5538 
5539     return NameBuff;
5540 }
5541 
5542 /*
5543  * After setting various option values: recompute variables that depend on
5544  * option values.
5545  */
5546     static void
5547 didset_options(void)
5548 {
5549     /* initialize the table for 'iskeyword' et.al. */
5550     (void)init_chartab();
5551 
5552 #ifdef FEAT_MBYTE
5553     (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5554 #endif
5555     (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5556     (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
5557 #ifdef FEAT_SESSION
5558     (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5559     (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5560 #endif
5561 #ifdef FEAT_FOLDING
5562     (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5563 #endif
5564     (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5565     (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
5566 #ifdef FEAT_VIRTUALEDIT
5567     (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5568 #endif
5569 #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5570     (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5571 #endif
5572 #ifdef FEAT_SPELL
5573     (void)spell_check_msm();
5574     (void)spell_check_sps();
5575     (void)compile_cap_prog(curwin->w_s);
5576     (void)did_set_spell_option(TRUE);
5577 #endif
5578 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5579     (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5580 #endif
5581 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
5582     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5583 #endif
5584 #ifdef FEAT_CMDWIN
5585     /* set cedit_key */
5586     (void)check_cedit();
5587 #endif
5588 #ifdef FEAT_LINEBREAK
5589     briopt_check(curwin);
5590 #endif
5591 #ifdef FEAT_LINEBREAK
5592     /* initialize the table for 'breakat'. */
5593     fill_breakat_flags();
5594 #endif
5595 
5596 }
5597 
5598 /*
5599  * More side effects of setting options.
5600  */
5601     static void
5602 didset_options2(void)
5603 {
5604     /* Initialize the highlight_attr[] table. */
5605     (void)highlight_changed();
5606 
5607     /* Parse default for 'wildmode'  */
5608     check_opt_wim();
5609 
5610     (void)set_chars_option(&p_lcs);
5611 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5612     /* Parse default for 'fillchars'. */
5613     (void)set_chars_option(&p_fcs);
5614 #endif
5615 
5616 #ifdef FEAT_CLIPBOARD
5617     /* Parse default for 'clipboard' */
5618     (void)check_clipboard_option();
5619 #endif
5620 }
5621 
5622 /*
5623  * Check for string options that are NULL (normally only termcap options).
5624  */
5625     void
5626 check_options(void)
5627 {
5628     int		opt_idx;
5629 
5630     for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5631 	if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5632 	    check_string_option((char_u **)get_varp(&(options[opt_idx])));
5633 }
5634 
5635 /*
5636  * Check string options in a buffer for NULL value.
5637  */
5638     void
5639 check_buf_options(buf_T *buf)
5640 {
5641     check_string_option(&buf->b_p_bh);
5642     check_string_option(&buf->b_p_bt);
5643 #ifdef FEAT_MBYTE
5644     check_string_option(&buf->b_p_fenc);
5645 #endif
5646     check_string_option(&buf->b_p_ff);
5647 #ifdef FEAT_FIND_ID
5648     check_string_option(&buf->b_p_def);
5649     check_string_option(&buf->b_p_inc);
5650 # ifdef FEAT_EVAL
5651     check_string_option(&buf->b_p_inex);
5652 # endif
5653 #endif
5654 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5655     check_string_option(&buf->b_p_inde);
5656     check_string_option(&buf->b_p_indk);
5657 #endif
5658 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5659     check_string_option(&buf->b_p_bexpr);
5660 #endif
5661 #if defined(FEAT_CRYPT)
5662     check_string_option(&buf->b_p_cm);
5663 #endif
5664     check_string_option(&buf->b_p_fp);
5665 #if defined(FEAT_EVAL)
5666     check_string_option(&buf->b_p_fex);
5667 #endif
5668 #ifdef FEAT_CRYPT
5669     check_string_option(&buf->b_p_key);
5670 #endif
5671     check_string_option(&buf->b_p_kp);
5672     check_string_option(&buf->b_p_mps);
5673     check_string_option(&buf->b_p_fo);
5674     check_string_option(&buf->b_p_flp);
5675     check_string_option(&buf->b_p_isk);
5676 #ifdef FEAT_COMMENTS
5677     check_string_option(&buf->b_p_com);
5678 #endif
5679 #ifdef FEAT_FOLDING
5680     check_string_option(&buf->b_p_cms);
5681 #endif
5682     check_string_option(&buf->b_p_nf);
5683 #ifdef FEAT_TEXTOBJ
5684     check_string_option(&buf->b_p_qe);
5685 #endif
5686 #ifdef FEAT_SYN_HL
5687     check_string_option(&buf->b_p_syn);
5688     check_string_option(&buf->b_s.b_syn_isk);
5689 #endif
5690 #ifdef FEAT_SPELL
5691     check_string_option(&buf->b_s.b_p_spc);
5692     check_string_option(&buf->b_s.b_p_spf);
5693     check_string_option(&buf->b_s.b_p_spl);
5694 #endif
5695 #ifdef FEAT_SEARCHPATH
5696     check_string_option(&buf->b_p_sua);
5697 #endif
5698 #ifdef FEAT_CINDENT
5699     check_string_option(&buf->b_p_cink);
5700     check_string_option(&buf->b_p_cino);
5701     parse_cino(buf);
5702 #endif
5703 #ifdef FEAT_AUTOCMD
5704     check_string_option(&buf->b_p_ft);
5705 #endif
5706 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5707     check_string_option(&buf->b_p_cinw);
5708 #endif
5709 #ifdef FEAT_INS_EXPAND
5710     check_string_option(&buf->b_p_cpt);
5711 #endif
5712 #ifdef FEAT_COMPL_FUNC
5713     check_string_option(&buf->b_p_cfu);
5714     check_string_option(&buf->b_p_ofu);
5715 #endif
5716 #ifdef FEAT_KEYMAP
5717     check_string_option(&buf->b_p_keymap);
5718 #endif
5719 #ifdef FEAT_QUICKFIX
5720     check_string_option(&buf->b_p_gp);
5721     check_string_option(&buf->b_p_mp);
5722     check_string_option(&buf->b_p_efm);
5723 #endif
5724     check_string_option(&buf->b_p_ep);
5725     check_string_option(&buf->b_p_path);
5726     check_string_option(&buf->b_p_tags);
5727     check_string_option(&buf->b_p_tc);
5728 #ifdef FEAT_INS_EXPAND
5729     check_string_option(&buf->b_p_dict);
5730     check_string_option(&buf->b_p_tsr);
5731 #endif
5732 #ifdef FEAT_LISP
5733     check_string_option(&buf->b_p_lw);
5734 #endif
5735     check_string_option(&buf->b_p_bkc);
5736 #ifdef FEAT_MBYTE
5737     check_string_option(&buf->b_p_menc);
5738 #endif
5739 }
5740 
5741 /*
5742  * Free the string allocated for an option.
5743  * Checks for the string being empty_option. This may happen if we're out of
5744  * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5745  * check_options().
5746  * Does NOT check for P_ALLOCED flag!
5747  */
5748     void
5749 free_string_option(char_u *p)
5750 {
5751     if (p != empty_option)
5752 	vim_free(p);
5753 }
5754 
5755     void
5756 clear_string_option(char_u **pp)
5757 {
5758     if (*pp != empty_option)
5759 	vim_free(*pp);
5760     *pp = empty_option;
5761 }
5762 
5763     static void
5764 check_string_option(char_u **pp)
5765 {
5766     if (*pp == NULL)
5767 	*pp = empty_option;
5768 }
5769 
5770 /*
5771  * Mark a terminal option as allocated, found by a pointer into term_strings[].
5772  */
5773     void
5774 set_term_option_alloced(char_u **p)
5775 {
5776     int		opt_idx;
5777 
5778     for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5779 	if (options[opt_idx].var == (char_u *)p)
5780 	{
5781 	    options[opt_idx].flags |= P_ALLOCED;
5782 	    return;
5783 	}
5784     return; /* cannot happen: didn't find it! */
5785 }
5786 
5787 #if defined(FEAT_EVAL) || defined(PROTO)
5788 /*
5789  * Return TRUE when option "opt" was set from a modeline or in secure mode.
5790  * Return FALSE when it wasn't.
5791  * Return -1 for an unknown option.
5792  */
5793     int
5794 was_set_insecurely(char_u *opt, int opt_flags)
5795 {
5796     int	    idx = findoption(opt);
5797     long_u  *flagp;
5798 
5799     if (idx >= 0)
5800     {
5801 	flagp = insecure_flag(idx, opt_flags);
5802 	return (*flagp & P_INSECURE) != 0;
5803     }
5804     internal_error("was_set_insecurely()");
5805     return -1;
5806 }
5807 
5808 /*
5809  * Get a pointer to the flags used for the P_INSECURE flag of option
5810  * "opt_idx".  For some local options a local flags field is used.
5811  */
5812     static long_u *
5813 insecure_flag(int opt_idx, int opt_flags)
5814 {
5815     if (opt_flags & OPT_LOCAL)
5816 	switch ((int)options[opt_idx].indir)
5817 	{
5818 #ifdef FEAT_STL_OPT
5819 	    case PV_STL:	return &curwin->w_p_stl_flags;
5820 #endif
5821 #ifdef FEAT_EVAL
5822 # ifdef FEAT_FOLDING
5823 	    case PV_FDE:	return &curwin->w_p_fde_flags;
5824 	    case PV_FDT:	return &curwin->w_p_fdt_flags;
5825 # endif
5826 # ifdef FEAT_BEVAL
5827 	    case PV_BEXPR:	return &curbuf->b_p_bexpr_flags;
5828 # endif
5829 # if defined(FEAT_CINDENT)
5830 	    case PV_INDE:	return &curbuf->b_p_inde_flags;
5831 # endif
5832 	    case PV_FEX:	return &curbuf->b_p_fex_flags;
5833 # ifdef FEAT_FIND_ID
5834 	    case PV_INEX:	return &curbuf->b_p_inex_flags;
5835 # endif
5836 #endif
5837 	}
5838 
5839     /* Nothing special, return global flags field. */
5840     return &options[opt_idx].flags;
5841 }
5842 #endif
5843 
5844 #ifdef FEAT_TITLE
5845 static void redraw_titles(void);
5846 
5847 /*
5848  * Redraw the window title and/or tab page text later.
5849  */
5850 static void redraw_titles(void)
5851 {
5852     need_maketitle = TRUE;
5853 # ifdef FEAT_WINDOWS
5854     redraw_tabline = TRUE;
5855 # endif
5856 }
5857 #endif
5858 
5859 /*
5860  * Set a string option to a new value (without checking the effect).
5861  * The string is copied into allocated memory.
5862  * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
5863  * When "set_sid" is zero set the scriptID to current_SID.  When "set_sid" is
5864  * SID_NONE don't set the scriptID.  Otherwise set the scriptID to "set_sid".
5865  */
5866     void
5867 set_string_option_direct(
5868     char_u	*name,
5869     int		opt_idx,
5870     char_u	*val,
5871     int		opt_flags,	/* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5872     int		set_sid UNUSED)
5873 {
5874     char_u	*s;
5875     char_u	**varp;
5876     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
5877     int		idx = opt_idx;
5878 
5879     if (idx == -1)		/* use name */
5880     {
5881 	idx = findoption(name);
5882 	if (idx < 0)	/* not found (should not happen) */
5883 	{
5884 	    EMSG2(_(e_intern2), "set_string_option_direct()");
5885 	    IEMSG2(_("For option %s"), name);
5886 	    return;
5887 	}
5888     }
5889 
5890     if (options[idx].var == NULL)	/* can't set hidden option */
5891 	return;
5892 
5893     s = vim_strsave(val);
5894     if (s != NULL)
5895     {
5896 	varp = (char_u **)get_varp_scope(&(options[idx]),
5897 					       both ? OPT_LOCAL : opt_flags);
5898 	if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
5899 	    free_string_option(*varp);
5900 	*varp = s;
5901 
5902 	/* For buffer/window local option may also set the global value. */
5903 	if (both)
5904 	    set_string_option_global(idx, varp);
5905 
5906 	options[idx].flags |= P_ALLOCED;
5907 
5908 	/* When setting both values of a global option with a local value,
5909 	 * make the local value empty, so that the global value is used. */
5910 	if (((int)options[idx].indir & PV_BOTH) && both)
5911 	{
5912 	    free_string_option(*varp);
5913 	    *varp = empty_option;
5914 	}
5915 # ifdef FEAT_EVAL
5916 	if (set_sid != SID_NONE)
5917 	    set_option_scriptID_idx(idx, opt_flags,
5918 					set_sid == 0 ? current_SID : set_sid);
5919 # endif
5920     }
5921 }
5922 
5923 /*
5924  * Set global value for string option when it's a local option.
5925  */
5926     static void
5927 set_string_option_global(
5928     int		opt_idx,	/* option index */
5929     char_u	**varp)		/* pointer to option variable */
5930 {
5931     char_u	**p, *s;
5932 
5933     /* the global value is always allocated */
5934     if (options[opt_idx].var == VAR_WIN)
5935 	p = (char_u **)GLOBAL_WO(varp);
5936     else
5937 	p = (char_u **)options[opt_idx].var;
5938     if (options[opt_idx].indir != PV_NONE
5939 	    && p != varp
5940 	    && (s = vim_strsave(*varp)) != NULL)
5941     {
5942 	free_string_option(*p);
5943 	*p = s;
5944     }
5945 }
5946 
5947 /*
5948  * Set a string option to a new value, and handle the effects.
5949  *
5950  * Returns NULL on success or error message on error.
5951  */
5952     static char_u *
5953 set_string_option(
5954     int		opt_idx,
5955     char_u	*value,
5956     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
5957 {
5958     char_u	*s;
5959     char_u	**varp;
5960     char_u	*oldval;
5961 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5962     char_u	*saved_oldval = NULL;
5963     char_u	*saved_newval = NULL;
5964 #endif
5965     char_u	*r = NULL;
5966 
5967     if (options[opt_idx].var == NULL)	/* don't set hidden option */
5968 	return NULL;
5969 
5970     s = vim_strsave(value);
5971     if (s != NULL)
5972     {
5973 	varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5974 		(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
5975 		    ? (((int)options[opt_idx].indir & PV_BOTH)
5976 			? OPT_GLOBAL : OPT_LOCAL)
5977 		    : opt_flags);
5978 	oldval = *varp;
5979 	*varp = s;
5980 
5981 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5982 	if (!starting
5983 # ifdef FEAT_CRYPT
5984 		&& options[opt_idx].indir != PV_KEY
5985 # endif
5986 		)
5987 	{
5988 	    saved_oldval = vim_strsave(oldval);
5989 	    saved_newval = vim_strsave(s);
5990 	}
5991 #endif
5992 	if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5993 							   opt_flags)) == NULL)
5994 	    did_set_option(opt_idx, opt_flags, TRUE);
5995 
5996 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5997 	/* call autocommand after handling side effects */
5998 	trigger_optionsset_string(opt_idx, opt_flags,
5999 						   saved_oldval, saved_newval);
6000 #endif
6001     }
6002     return r;
6003 }
6004 
6005 #if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
6006 /*
6007  * Return TRUE if "val" is a valid 'filetype' name.
6008  * Also used for 'syntax' and 'keymap'.
6009  */
6010     static int
6011 valid_filetype(char_u *val)
6012 {
6013     char_u *s;
6014 
6015     for (s = val; *s != NUL; ++s)
6016 	if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6017 	    return FALSE;
6018     return TRUE;
6019 }
6020 #endif
6021 
6022 /*
6023  * Handle string options that need some action to perform when changed.
6024  * Returns NULL for success, or an error message for an error.
6025  */
6026     static char_u *
6027 did_set_string_option(
6028     int		opt_idx,		/* index in options[] table */
6029     char_u	**varp,			/* pointer to the option variable */
6030     int		new_value_alloced,	/* new value was allocated */
6031     char_u	*oldval,		/* previous value of the option */
6032     char_u	*errbuf,		/* buffer for errors, or NULL */
6033     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
6034 {
6035     char_u	*errmsg = NULL;
6036     char_u	*s, *p;
6037     int		did_chartab = FALSE;
6038     char_u	**gvarp;
6039     long_u	free_oldval = (options[opt_idx].flags & P_ALLOCED);
6040 #ifdef FEAT_GUI
6041     /* set when changing an option that only requires a redraw in the GUI */
6042     int		redraw_gui_only = FALSE;
6043 #endif
6044 #ifdef FEAT_AUTOCMD
6045     int		ft_changed = FALSE;
6046 #endif
6047 
6048     /* Get the global option to compare with, otherwise we would have to check
6049      * two values for all local options. */
6050     gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6051 
6052     /* Disallow changing some options from secure mode */
6053     if ((secure
6054 #ifdef HAVE_SANDBOX
6055 		|| sandbox != 0
6056 #endif
6057 		) && (options[opt_idx].flags & P_SECURE))
6058     {
6059 	errmsg = e_secure;
6060     }
6061 
6062     /* Check for a "normal" directory or file name in some options.  Disallow a
6063      * path separator (slash and/or backslash), wildcards and characters that
6064      * are often illegal in a file name. Be more permissive if "secure" is off.
6065      */
6066     else if (((options[opt_idx].flags & P_NFNAME)
6067 		    && vim_strpbrk(*varp, (char_u *)(secure
6068 			    ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
6069 	  || ((options[opt_idx].flags & P_NDNAME)
6070 		    && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
6071     {
6072 	errmsg = e_invarg;
6073     }
6074 
6075     /* 'term' */
6076     else if (varp == &T_NAME)
6077     {
6078 	if (T_NAME[0] == NUL)
6079 	    errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6080 #ifdef FEAT_GUI
6081 	if (gui.in_use)
6082 	    errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6083 	else if (term_is_gui(T_NAME))
6084 	    errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6085 #endif
6086 	else if (set_termname(T_NAME) == FAIL)
6087 	    errmsg = (char_u *)N_("E522: Not found in termcap");
6088 	else
6089 	{
6090 	    /* Screen colors may have changed. */
6091 	    redraw_later_clear();
6092 
6093 	    /* Both 'term' and 'ttytype' point to T_NAME, only set the
6094 	     * P_ALLOCED flag on 'term'. */
6095 	    opt_idx = findoption((char_u *)"term");
6096 	    free_oldval = (options[opt_idx].flags & P_ALLOCED);
6097 	}
6098     }
6099 
6100     /* 'backupcopy' */
6101     else if (gvarp == &p_bkc)
6102     {
6103 	char_u		*bkc = p_bkc;
6104 	unsigned int	*flags = &bkc_flags;
6105 
6106 	if (opt_flags & OPT_LOCAL)
6107 	{
6108 	    bkc = curbuf->b_p_bkc;
6109 	    flags = &curbuf->b_bkc_flags;
6110 	}
6111 
6112 	if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6113 	    /* make the local value empty: use the global value */
6114 	    *flags = 0;
6115 	else
6116 	{
6117 	    if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6118 		errmsg = e_invarg;
6119 	    if ((((int)*flags & BKC_AUTO) != 0)
6120 		    + (((int)*flags & BKC_YES) != 0)
6121 		    + (((int)*flags & BKC_NO) != 0) != 1)
6122 	    {
6123 		/* Must have exactly one of "auto", "yes"  and "no". */
6124 		(void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6125 		errmsg = e_invarg;
6126 	    }
6127 	}
6128     }
6129 
6130     /* 'backupext' and 'patchmode' */
6131     else if (varp == &p_bex || varp == &p_pm)
6132     {
6133 	if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6134 		     *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6135 	    errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6136     }
6137 #ifdef FEAT_LINEBREAK
6138     /* 'breakindentopt' */
6139     else if (varp == &curwin->w_p_briopt)
6140     {
6141 	if (briopt_check(curwin) == FAIL)
6142 	    errmsg = e_invarg;
6143     }
6144 #endif
6145 
6146     /*
6147      * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
6148      * If the new option is invalid, use old value.  'lisp' option: refill
6149      * g_chartab[] for '-' char
6150      */
6151     else if (  varp == &p_isi
6152 	    || varp == &(curbuf->b_p_isk)
6153 	    || varp == &p_isp
6154 	    || varp == &p_isf)
6155     {
6156 	if (init_chartab() == FAIL)
6157 	{
6158 	    did_chartab = TRUE;	    /* need to restore it below */
6159 	    errmsg = e_invarg;	    /* error in value */
6160 	}
6161     }
6162 
6163     /* 'helpfile' */
6164     else if (varp == &p_hf)
6165     {
6166 	/* May compute new values for $VIM and $VIMRUNTIME */
6167 	if (didset_vim)
6168 	{
6169 	    vim_setenv((char_u *)"VIM", (char_u *)"");
6170 	    didset_vim = FALSE;
6171 	}
6172 	if (didset_vimruntime)
6173 	{
6174 	    vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6175 	    didset_vimruntime = FALSE;
6176 	}
6177     }
6178 
6179 #ifdef FEAT_SYN_HL
6180     /* 'colorcolumn' */
6181     else if (varp == &curwin->w_p_cc)
6182 	errmsg = check_colorcolumn(curwin);
6183 #endif
6184 
6185 #ifdef FEAT_MULTI_LANG
6186     /* 'helplang' */
6187     else if (varp == &p_hlg)
6188     {
6189 	/* Check for "", "ab", "ab,cd", etc. */
6190 	for (s = p_hlg; *s != NUL; s += 3)
6191 	{
6192 	    if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6193 	    {
6194 		errmsg = e_invarg;
6195 		break;
6196 	    }
6197 	    if (s[2] == NUL)
6198 		break;
6199 	}
6200     }
6201 #endif
6202 
6203     /* 'highlight' */
6204     else if (varp == &p_hl)
6205     {
6206 	if (highlight_changed() == FAIL)
6207 	    errmsg = e_invarg;	/* invalid flags */
6208     }
6209 
6210     /* 'nrformats' */
6211     else if (gvarp == &p_nf)
6212     {
6213 	if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6214 	    errmsg = e_invarg;
6215     }
6216 
6217 #ifdef FEAT_SESSION
6218     /* 'sessionoptions' */
6219     else if (varp == &p_ssop)
6220     {
6221 	if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6222 	    errmsg = e_invarg;
6223 	if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6224 	{
6225 	    /* Don't allow both "sesdir" and "curdir". */
6226 	    (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6227 	    errmsg = e_invarg;
6228 	}
6229     }
6230     /* 'viewoptions' */
6231     else if (varp == &p_vop)
6232     {
6233 	if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6234 	    errmsg = e_invarg;
6235     }
6236 #endif
6237 
6238     /* 'scrollopt' */
6239 #ifdef FEAT_SCROLLBIND
6240     else if (varp == &p_sbo)
6241     {
6242 	if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6243 	    errmsg = e_invarg;
6244     }
6245 #endif
6246 
6247     /* 'ambiwidth' */
6248 #ifdef FEAT_MBYTE
6249     else if (varp == &p_ambw || varp == &p_emoji)
6250     {
6251 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6252 	    errmsg = e_invarg;
6253 	else if (set_chars_option(&p_lcs) != NULL)
6254 	    errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6255 # if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6256 	else if (set_chars_option(&p_fcs) != NULL)
6257 	    errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6258 # endif
6259     }
6260 #endif
6261 
6262     /* 'background' */
6263     else if (varp == &p_bg)
6264     {
6265 	if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6266 	{
6267 #ifdef FEAT_EVAL
6268 	    int dark = (*p_bg == 'd');
6269 #endif
6270 
6271 	    init_highlight(FALSE, FALSE);
6272 
6273 #ifdef FEAT_EVAL
6274 	    if (dark != (*p_bg == 'd')
6275 			  && get_var_value((char_u *)"g:colors_name") != NULL)
6276 	    {
6277 		/* The color scheme must have set 'background' back to another
6278 		 * value, that's not what we want here.  Disable the color
6279 		 * scheme and set the colors again. */
6280 		do_unlet((char_u *)"g:colors_name", TRUE);
6281 		free_string_option(p_bg);
6282 		p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6283 		check_string_option(&p_bg);
6284 		init_highlight(FALSE, FALSE);
6285 	    }
6286 #endif
6287 	}
6288 	else
6289 	    errmsg = e_invarg;
6290     }
6291 
6292     /* 'wildmode' */
6293     else if (varp == &p_wim)
6294     {
6295 	if (check_opt_wim() == FAIL)
6296 	    errmsg = e_invarg;
6297     }
6298 
6299 #ifdef FEAT_CMDL_COMPL
6300     /* 'wildoptions' */
6301     else if (varp == &p_wop)
6302     {
6303 	if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6304 	    errmsg = e_invarg;
6305     }
6306 #endif
6307 
6308 #ifdef FEAT_WAK
6309     /* 'winaltkeys' */
6310     else if (varp == &p_wak)
6311     {
6312 	if (*p_wak == NUL
6313 		|| check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6314 	    errmsg = e_invarg;
6315 # ifdef FEAT_MENU
6316 #  ifdef FEAT_GUI_MOTIF
6317 	else if (gui.in_use)
6318 	    gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6319 #  else
6320 #   ifdef FEAT_GUI_GTK
6321 	else if (gui.in_use)
6322 	    gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6323 #   endif
6324 #  endif
6325 # endif
6326     }
6327 #endif
6328 
6329 #ifdef FEAT_AUTOCMD
6330     /* 'eventignore' */
6331     else if (varp == &p_ei)
6332     {
6333 	if (check_ei() == FAIL)
6334 	    errmsg = e_invarg;
6335     }
6336 #endif
6337 
6338 #ifdef FEAT_MBYTE
6339     /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6340     else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6341 							   || gvarp == &p_menc)
6342     {
6343 	if (gvarp == &p_fenc)
6344 	{
6345 	    if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
6346 		errmsg = e_modifiable;
6347 	    else if (vim_strchr(*varp, ',') != NULL)
6348 		/* No comma allowed in 'fileencoding'; catches confusing it
6349 		 * with 'fileencodings'. */
6350 		errmsg = e_invarg;
6351 	    else
6352 	    {
6353 # ifdef FEAT_TITLE
6354 		/* May show a "+" in the title now. */
6355 		redraw_titles();
6356 # endif
6357 		/* Add 'fileencoding' to the swap file. */
6358 		ml_setflags(curbuf);
6359 	    }
6360 	}
6361 	if (errmsg == NULL)
6362 	{
6363 	    /* canonize the value, so that STRCMP() can be used on it */
6364 	    p = enc_canonize(*varp);
6365 	    if (p != NULL)
6366 	    {
6367 		vim_free(*varp);
6368 		*varp = p;
6369 	    }
6370 	    if (varp == &p_enc)
6371 	    {
6372 		errmsg = mb_init();
6373 # ifdef FEAT_TITLE
6374 		redraw_titles();
6375 # endif
6376 	    }
6377 	}
6378 
6379 # if defined(FEAT_GUI_GTK)
6380 	if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6381 	{
6382 	    /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6383 	    if (STRCMP(p_tenc, "utf-8") != 0)
6384 		errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6385 	}
6386 # endif
6387 
6388 	if (errmsg == NULL)
6389 	{
6390 # ifdef FEAT_KEYMAP
6391 	    /* When 'keymap' is used and 'encoding' changes, reload the keymap
6392 	     * (with another encoding). */
6393 	    if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6394 		(void)keymap_init();
6395 # endif
6396 
6397 	    /* When 'termencoding' is not empty and 'encoding' changes or when
6398 	     * 'termencoding' changes, need to setup for keyboard input and
6399 	     * display output conversion. */
6400 	    if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6401 	    {
6402 		convert_setup(&input_conv, p_tenc, p_enc);
6403 		convert_setup(&output_conv, p_enc, p_tenc);
6404 	    }
6405 
6406 # if defined(WIN3264) && defined(FEAT_MBYTE)
6407 	    /* $HOME may have characters in active code page. */
6408 	    if (varp == &p_enc)
6409 		init_homedir();
6410 # endif
6411 	}
6412     }
6413 #endif
6414 
6415 #if defined(FEAT_POSTSCRIPT)
6416     else if (varp == &p_penc)
6417     {
6418 	/* Canonize printencoding if VIM standard one */
6419 	p = enc_canonize(p_penc);
6420 	if (p != NULL)
6421 	{
6422 	    vim_free(p_penc);
6423 	    p_penc = p;
6424 	}
6425 	else
6426 	{
6427 	    /* Ensure lower case and '-' for '_' */
6428 	    for (s = p_penc; *s != NUL; s++)
6429 	    {
6430 		if (*s == '_')
6431 		    *s = '-';
6432 		else
6433 		    *s = TOLOWER_ASC(*s);
6434 	    }
6435 	}
6436     }
6437 #endif
6438 
6439 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
6440     else if (varp == &p_imak)
6441     {
6442 	if (!im_xim_isvalid_imactivate())
6443 	    errmsg = e_invarg;
6444     }
6445 #endif
6446 
6447 #ifdef FEAT_KEYMAP
6448     else if (varp == &curbuf->b_p_keymap)
6449     {
6450 	if (!valid_filetype(*varp))
6451 	    errmsg = e_invarg;
6452 	else
6453 	    /* load or unload key mapping tables */
6454 	    errmsg = keymap_init();
6455 
6456 	if (errmsg == NULL)
6457 	{
6458 	    if (*curbuf->b_p_keymap != NUL)
6459 	    {
6460 		/* Installed a new keymap, switch on using it. */
6461 		curbuf->b_p_iminsert = B_IMODE_LMAP;
6462 		if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6463 		    curbuf->b_p_imsearch = B_IMODE_LMAP;
6464 	    }
6465 	    else
6466 	    {
6467 		/* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6468 		if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6469 		    curbuf->b_p_iminsert = B_IMODE_NONE;
6470 		if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6471 		    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6472 	    }
6473 	    if ((opt_flags & OPT_LOCAL) == 0)
6474 	    {
6475 		set_iminsert_global();
6476 		set_imsearch_global();
6477 	    }
6478 # ifdef FEAT_WINDOWS
6479 	    status_redraw_curbuf();
6480 # endif
6481 	}
6482     }
6483 #endif
6484 
6485     /* 'fileformat' */
6486     else if (gvarp == &p_ff)
6487     {
6488 	if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6489 	    errmsg = e_modifiable;
6490 	else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6491 	    errmsg = e_invarg;
6492 	else
6493 	{
6494 	    /* may also change 'textmode' */
6495 	    if (get_fileformat(curbuf) == EOL_DOS)
6496 		curbuf->b_p_tx = TRUE;
6497 	    else
6498 		curbuf->b_p_tx = FALSE;
6499 #ifdef FEAT_TITLE
6500 	    redraw_titles();
6501 #endif
6502 	    /* update flag in swap file */
6503 	    ml_setflags(curbuf);
6504 	    /* Redraw needed when switching to/from "mac": a CR in the text
6505 	     * will be displayed differently. */
6506 	    if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6507 		redraw_curbuf_later(NOT_VALID);
6508 	}
6509     }
6510 
6511     /* 'fileformats' */
6512     else if (varp == &p_ffs)
6513     {
6514 	if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6515 	    errmsg = e_invarg;
6516 	else
6517 	{
6518 	    /* also change 'textauto' */
6519 	    if (*p_ffs == NUL)
6520 		p_ta = FALSE;
6521 	    else
6522 		p_ta = TRUE;
6523 	}
6524     }
6525 
6526 #if defined(FEAT_CRYPT)
6527     /* 'cryptkey' */
6528     else if (gvarp == &p_key)
6529     {
6530 # if defined(FEAT_CMDHIST)
6531 	/* Make sure the ":set" command doesn't show the new value in the
6532 	 * history. */
6533 	remove_key_from_history();
6534 # endif
6535 	if (STRCMP(curbuf->b_p_key, oldval) != 0)
6536 	    /* Need to update the swapfile. */
6537 	    ml_set_crypt_key(curbuf, oldval,
6538 			      *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
6539     }
6540 
6541     else if (gvarp == &p_cm)
6542     {
6543 	if (opt_flags & OPT_LOCAL)
6544 	    p = curbuf->b_p_cm;
6545 	else
6546 	    p = p_cm;
6547 	if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6548 	    errmsg = e_invarg;
6549 	else if (crypt_self_test() == FAIL)
6550 	    errmsg = e_invarg;
6551 	else
6552 	{
6553 	    /* When setting the global value to empty, make it "zip". */
6554 	    if (*p_cm == NUL)
6555 	    {
6556 		if (new_value_alloced)
6557 		    free_string_option(p_cm);
6558 		p_cm = vim_strsave((char_u *)"zip");
6559 		new_value_alloced = TRUE;
6560 	    }
6561 	    /* When using ":set cm=name" the local value is going to be empty.
6562 	     * Do that here, otherwise the crypt functions will still use the
6563 	     * local value. */
6564 	    if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6565 	    {
6566 		free_string_option(curbuf->b_p_cm);
6567 		curbuf->b_p_cm = empty_option;
6568 	    }
6569 
6570 	    /* Need to update the swapfile when the effective method changed.
6571 	     * Set "s" to the effective old value, "p" to the effective new
6572 	     * method and compare. */
6573 	    if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6574 		s = p_cm;  /* was previously using the global value */
6575 	    else
6576 		s = oldval;
6577 	    if (*curbuf->b_p_cm == NUL)
6578 		p = p_cm;  /* is now using the global value */
6579 	    else
6580 		p = curbuf->b_p_cm;
6581 	    if (STRCMP(s, p) != 0)
6582 		ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
6583 
6584 	    /* If the global value changes need to update the swapfile for all
6585 	     * buffers using that value. */
6586 	    if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6587 	    {
6588 		buf_T	*buf;
6589 
6590 		FOR_ALL_BUFFERS(buf)
6591 		    if (buf != curbuf && *buf->b_p_cm == NUL)
6592 			ml_set_crypt_key(buf, buf->b_p_key, oldval);
6593 	    }
6594 	}
6595     }
6596 #endif
6597 
6598     /* 'matchpairs' */
6599     else if (gvarp == &p_mps)
6600     {
6601 #ifdef FEAT_MBYTE
6602 	if (has_mbyte)
6603 	{
6604 	    for (p = *varp; *p != NUL; ++p)
6605 	    {
6606 		int x2 = -1;
6607 		int x3 = -1;
6608 
6609 		if (*p != NUL)
6610 		    p += mb_ptr2len(p);
6611 		if (*p != NUL)
6612 		    x2 = *p++;
6613 		if (*p != NUL)
6614 		{
6615 		    x3 = mb_ptr2char(p);
6616 		    p += mb_ptr2len(p);
6617 		}
6618 		if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
6619 		{
6620 		    errmsg = e_invarg;
6621 		    break;
6622 		}
6623 		if (*p == NUL)
6624 		    break;
6625 	    }
6626 	}
6627 	else
6628 #endif
6629 	{
6630 	    /* Check for "x:y,x:y" */
6631 	    for (p = *varp; *p != NUL; p += 4)
6632 	    {
6633 		if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6634 		{
6635 		    errmsg = e_invarg;
6636 		    break;
6637 		}
6638 		if (p[3] == NUL)
6639 		    break;
6640 	    }
6641 	}
6642     }
6643 
6644 #ifdef FEAT_COMMENTS
6645     /* 'comments' */
6646     else if (gvarp == &p_com)
6647     {
6648 	for (s = *varp; *s; )
6649 	{
6650 	    while (*s && *s != ':')
6651 	    {
6652 		if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6653 					     && !VIM_ISDIGIT(*s) && *s != '-')
6654 		{
6655 		    errmsg = illegal_char(errbuf, *s);
6656 		    break;
6657 		}
6658 		++s;
6659 	    }
6660 	    if (*s++ == NUL)
6661 		errmsg = (char_u *)N_("E524: Missing colon");
6662 	    else if (*s == ',' || *s == NUL)
6663 		errmsg = (char_u *)N_("E525: Zero length string");
6664 	    if (errmsg != NULL)
6665 		break;
6666 	    while (*s && *s != ',')
6667 	    {
6668 		if (*s == '\\' && s[1] != NUL)
6669 		    ++s;
6670 		++s;
6671 	    }
6672 	    s = skip_to_option_part(s);
6673 	}
6674     }
6675 #endif
6676 
6677     /* 'listchars' */
6678     else if (varp == &p_lcs)
6679     {
6680 	errmsg = set_chars_option(varp);
6681     }
6682 
6683 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6684     /* 'fillchars' */
6685     else if (varp == &p_fcs)
6686     {
6687 	errmsg = set_chars_option(varp);
6688     }
6689 #endif
6690 
6691 #ifdef FEAT_CMDWIN
6692     /* 'cedit' */
6693     else if (varp == &p_cedit)
6694     {
6695 	errmsg = check_cedit();
6696     }
6697 #endif
6698 
6699     /* 'verbosefile' */
6700     else if (varp == &p_vfile)
6701     {
6702 	verbose_stop();
6703 	if (*p_vfile != NUL && verbose_open() == FAIL)
6704 	    errmsg = e_invarg;
6705     }
6706 
6707 #ifdef FEAT_VIMINFO
6708     /* 'viminfo' */
6709     else if (varp == &p_viminfo)
6710     {
6711 	for (s = p_viminfo; *s;)
6712 	{
6713 	    /* Check it's a valid character */
6714 	    if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6715 	    {
6716 		errmsg = illegal_char(errbuf, *s);
6717 		break;
6718 	    }
6719 	    if (*s == 'n')	/* name is always last one */
6720 	    {
6721 		break;
6722 	    }
6723 	    else if (*s == 'r') /* skip until next ',' */
6724 	    {
6725 		while (*++s && *s != ',')
6726 		    ;
6727 	    }
6728 	    else if (*s == '%')
6729 	    {
6730 		/* optional number */
6731 		while (vim_isdigit(*++s))
6732 		    ;
6733 	    }
6734 	    else if (*s == '!' || *s == 'h' || *s == 'c')
6735 		++s;		/* no extra chars */
6736 	    else		/* must have a number */
6737 	    {
6738 		while (vim_isdigit(*++s))
6739 		    ;
6740 
6741 		if (!VIM_ISDIGIT(*(s - 1)))
6742 		{
6743 		    if (errbuf != NULL)
6744 		    {
6745 			sprintf((char *)errbuf,
6746 					 _("E526: Missing number after <%s>"),
6747 						    transchar_byte(*(s - 1)));
6748 			errmsg = errbuf;
6749 		    }
6750 		    else
6751 			errmsg = (char_u *)"";
6752 		    break;
6753 		}
6754 	    }
6755 	    if (*s == ',')
6756 		++s;
6757 	    else if (*s)
6758 	    {
6759 		if (errbuf != NULL)
6760 		    errmsg = (char_u *)N_("E527: Missing comma");
6761 		else
6762 		    errmsg = (char_u *)"";
6763 		break;
6764 	    }
6765 	}
6766 	if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6767 	    errmsg = (char_u *)N_("E528: Must specify a ' value");
6768     }
6769 #endif /* FEAT_VIMINFO */
6770 
6771     /* terminal options */
6772     else if (istermoption(&options[opt_idx]) && full_screen)
6773     {
6774 	/* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6775 	if (varp == &T_CCO)
6776 	{
6777 	    int colors = atoi((char *)T_CCO);
6778 
6779 	    /* Only reinitialize colors if t_Co value has really changed to
6780 	     * avoid expensive reload of colorscheme if t_Co is set to the
6781 	     * same value multiple times. */
6782 	    if (colors != t_colors)
6783 	    {
6784 		t_colors = colors;
6785 		if (t_colors <= 1)
6786 		{
6787 		    if (new_value_alloced)
6788 			vim_free(T_CCO);
6789 		    T_CCO = empty_option;
6790 		}
6791 		/* We now have a different color setup, initialize it again. */
6792 		init_highlight(TRUE, FALSE);
6793 	    }
6794 	}
6795 	ttest(FALSE);
6796 	if (varp == &T_ME)
6797 	{
6798 	    out_str(T_ME);
6799 	    redraw_later(CLEAR);
6800 #if defined(WIN3264) && !defined(FEAT_GUI_W32)
6801 	    /* Since t_me has been set, this probably means that the user
6802 	     * wants to use this as default colors.  Need to reset default
6803 	     * background/foreground colors. */
6804 	    mch_set_normal_colors();
6805 #endif
6806 	}
6807 	if (varp == &T_BE && termcap_active)
6808 	{
6809 	    if (*T_BE == NUL)
6810 		/* When clearing t_BE we assume the user no longer wants
6811 		 * bracketed paste, thus disable it by writing t_BD. */
6812 		out_str(T_BD);
6813 	    else
6814 		out_str(T_BE);
6815 	}
6816     }
6817 
6818 #ifdef FEAT_LINEBREAK
6819     /* 'showbreak' */
6820     else if (varp == &p_sbr)
6821     {
6822 	for (s = p_sbr; *s; )
6823 	{
6824 	    if (ptr2cells(s) != 1)
6825 		errmsg = (char_u *)N_("E595: contains unprintable or wide character");
6826 	    MB_PTR_ADV(s);
6827 	}
6828     }
6829 #endif
6830 
6831 #ifdef FEAT_GUI
6832     /* 'guifont' */
6833     else if (varp == &p_guifont)
6834     {
6835 	if (gui.in_use)
6836 	{
6837 	    p = p_guifont;
6838 # if defined(FEAT_GUI_GTK)
6839 	    /*
6840 	     * Put up a font dialog and let the user select a new value.
6841 	     * If this is cancelled go back to the old value but don't
6842 	     * give an error message.
6843 	     */
6844 	    if (STRCMP(p, "*") == 0)
6845 	    {
6846 		p = gui_mch_font_dialog(oldval);
6847 
6848 		if (new_value_alloced)
6849 		    free_string_option(p_guifont);
6850 
6851 		p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6852 		new_value_alloced = TRUE;
6853 	    }
6854 # endif
6855 	    if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6856 	    {
6857 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6858 		if (STRCMP(p_guifont, "*") == 0)
6859 		{
6860 		    /* Dialog was cancelled: Keep the old value without giving
6861 		     * an error message. */
6862 		    if (new_value_alloced)
6863 			free_string_option(p_guifont);
6864 		    p_guifont = vim_strsave(oldval);
6865 		    new_value_alloced = TRUE;
6866 		}
6867 		else
6868 # endif
6869 		    errmsg = (char_u *)N_("E596: Invalid font(s)");
6870 	    }
6871 	}
6872 	redraw_gui_only = TRUE;
6873     }
6874 # ifdef FEAT_XFONTSET
6875     else if (varp == &p_guifontset)
6876     {
6877 	if (STRCMP(p_guifontset, "*") == 0)
6878 	    errmsg = (char_u *)N_("E597: can't select fontset");
6879 	else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6880 	    errmsg = (char_u *)N_("E598: Invalid fontset");
6881 	redraw_gui_only = TRUE;
6882     }
6883 # endif
6884 # ifdef FEAT_MBYTE
6885     else if (varp == &p_guifontwide)
6886     {
6887 	if (STRCMP(p_guifontwide, "*") == 0)
6888 	    errmsg = (char_u *)N_("E533: can't select wide font");
6889 	else if (gui_get_wide_font() == FAIL)
6890 	    errmsg = (char_u *)N_("E534: Invalid wide font");
6891 	redraw_gui_only = TRUE;
6892     }
6893 # endif
6894 #endif
6895 
6896 #ifdef CURSOR_SHAPE
6897     /* 'guicursor' */
6898     else if (varp == &p_guicursor)
6899 	errmsg = parse_shape_opt(SHAPE_CURSOR);
6900 #endif
6901 
6902 #ifdef FEAT_MOUSESHAPE
6903     /* 'mouseshape' */
6904     else if (varp == &p_mouseshape)
6905     {
6906 	errmsg = parse_shape_opt(SHAPE_MOUSE);
6907 	update_mouseshape(-1);
6908     }
6909 #endif
6910 
6911 #ifdef FEAT_PRINTER
6912     else if (varp == &p_popt)
6913 	errmsg = parse_printoptions();
6914 # if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
6915     else if (varp == &p_pmfn)
6916 	errmsg = parse_printmbfont();
6917 # endif
6918 #endif
6919 
6920 #ifdef FEAT_LANGMAP
6921     /* 'langmap' */
6922     else if (varp == &p_langmap)
6923 	langmap_set();
6924 #endif
6925 
6926 #ifdef FEAT_LINEBREAK
6927     /* 'breakat' */
6928     else if (varp == &p_breakat)
6929 	fill_breakat_flags();
6930 #endif
6931 
6932 #ifdef FEAT_TITLE
6933     /* 'titlestring' and 'iconstring' */
6934     else if (varp == &p_titlestring || varp == &p_iconstring)
6935     {
6936 # ifdef FEAT_STL_OPT
6937 	int	flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6938 
6939 	/* NULL => statusline syntax */
6940 	if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6941 	    stl_syntax |= flagval;
6942 	else
6943 	    stl_syntax &= ~flagval;
6944 # endif
6945 	did_set_title(varp == &p_iconstring);
6946 
6947     }
6948 #endif
6949 
6950 #ifdef FEAT_GUI
6951     /* 'guioptions' */
6952     else if (varp == &p_go)
6953     {
6954 	gui_init_which_components(oldval);
6955 	redraw_gui_only = TRUE;
6956     }
6957 #endif
6958 
6959 #if defined(FEAT_GUI_TABLINE)
6960     /* 'guitablabel' */
6961     else if (varp == &p_gtl)
6962     {
6963 	redraw_tabline = TRUE;
6964 	redraw_gui_only = TRUE;
6965     }
6966     /* 'guitabtooltip' */
6967     else if (varp == &p_gtt)
6968     {
6969 	redraw_gui_only = TRUE;
6970     }
6971 #endif
6972 
6973 #if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6974     /* 'ttymouse' */
6975     else if (varp == &p_ttym)
6976     {
6977 	/* Switch the mouse off before changing the escape sequences used for
6978 	 * that. */
6979 	mch_setmouse(FALSE);
6980 	if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6981 	    errmsg = e_invarg;
6982 	else
6983 	    check_mouse_termcode();
6984 	if (termcap_active)
6985 	    setmouse();		/* may switch it on again */
6986     }
6987 #endif
6988 
6989     /* 'selection' */
6990     else if (varp == &p_sel)
6991     {
6992 	if (*p_sel == NUL
6993 		|| check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6994 	    errmsg = e_invarg;
6995     }
6996 
6997     /* 'selectmode' */
6998     else if (varp == &p_slm)
6999     {
7000 	if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7001 	    errmsg = e_invarg;
7002     }
7003 
7004 #ifdef FEAT_BROWSE
7005     /* 'browsedir' */
7006     else if (varp == &p_bsdir)
7007     {
7008 	if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7009 		&& !mch_isdir(p_bsdir))
7010 	    errmsg = e_invarg;
7011     }
7012 #endif
7013 
7014     /* 'keymodel' */
7015     else if (varp == &p_km)
7016     {
7017 	if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7018 	    errmsg = e_invarg;
7019 	else
7020 	{
7021 	    km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7022 	    km_startsel = (vim_strchr(p_km, 'a') != NULL);
7023 	}
7024     }
7025 
7026     /* 'mousemodel' */
7027     else if (varp == &p_mousem)
7028     {
7029 	if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7030 	    errmsg = e_invarg;
7031 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7032 	else if (*p_mousem != *oldval)
7033 	    /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7034 	     * to create or delete the popup menus. */
7035 	    gui_motif_update_mousemodel(root_menu);
7036 #endif
7037     }
7038 
7039     /* 'switchbuf' */
7040     else if (varp == &p_swb)
7041     {
7042 	if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
7043 	    errmsg = e_invarg;
7044     }
7045 
7046     /* 'debug' */
7047     else if (varp == &p_debug)
7048     {
7049 	if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
7050 	    errmsg = e_invarg;
7051     }
7052 
7053     /* 'display' */
7054     else if (varp == &p_dy)
7055     {
7056 	if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7057 	    errmsg = e_invarg;
7058 	else
7059 	    (void)init_chartab();
7060 
7061     }
7062 
7063 #ifdef FEAT_WINDOWS
7064     /* 'eadirection' */
7065     else if (varp == &p_ead)
7066     {
7067 	if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7068 	    errmsg = e_invarg;
7069     }
7070 #endif
7071 
7072 #ifdef FEAT_CLIPBOARD
7073     /* 'clipboard' */
7074     else if (varp == &p_cb)
7075 	errmsg = check_clipboard_option();
7076 #endif
7077 
7078 #ifdef FEAT_SPELL
7079     /* When 'spelllang' or 'spellfile' is set and there is a window for this
7080      * buffer in which 'spell' is set load the wordlists. */
7081     else if (varp == &(curwin->w_s->b_p_spl)
7082 	    || varp == &(curwin->w_s->b_p_spf))
7083     {
7084 	errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
7085     }
7086     /* When 'spellcapcheck' is set compile the regexp program. */
7087     else if (varp == &(curwin->w_s->b_p_spc))
7088     {
7089 	errmsg = compile_cap_prog(curwin->w_s);
7090     }
7091     /* 'spellsuggest' */
7092     else if (varp == &p_sps)
7093     {
7094 	if (spell_check_sps() != OK)
7095 	    errmsg = e_invarg;
7096     }
7097     /* 'mkspellmem' */
7098     else if (varp == &p_msm)
7099     {
7100 	if (spell_check_msm() != OK)
7101 	    errmsg = e_invarg;
7102     }
7103 #endif
7104 
7105     /* When 'bufhidden' is set, check for valid value. */
7106     else if (gvarp == &p_bh)
7107     {
7108 	if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7109 	    errmsg = e_invarg;
7110     }
7111 
7112     /* When 'buftype' is set, check for valid value. */
7113     else if (gvarp == &p_bt)
7114     {
7115 	if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7116 	    errmsg = e_invarg;
7117 	else
7118 	{
7119 #ifdef FEAT_WINDOWS
7120 	    if (curwin->w_status_height)
7121 	    {
7122 		curwin->w_redr_status = TRUE;
7123 		redraw_later(VALID);
7124 	    }
7125 #endif
7126 	    curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
7127 #ifdef FEAT_TITLE
7128 	    redraw_titles();
7129 #endif
7130 	}
7131     }
7132 
7133 #ifdef FEAT_STL_OPT
7134     /* 'statusline' or 'rulerformat' */
7135     else if (gvarp == &p_stl || varp == &p_ruf)
7136     {
7137 	int wid;
7138 
7139 	if (varp == &p_ruf)	/* reset ru_wid first */
7140 	    ru_wid = 0;
7141 	s = *varp;
7142 	if (varp == &p_ruf && *s == '%')
7143 	{
7144 	    /* set ru_wid if 'ruf' starts with "%99(" */
7145 	    if (*++s == '-')	/* ignore a '-' */
7146 		s++;
7147 	    wid = getdigits(&s);
7148 	    if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7149 		ru_wid = wid;
7150 	    else
7151 		errmsg = check_stl_option(p_ruf);
7152 	}
7153 	/* check 'statusline' only if it doesn't start with "%!" */
7154 	else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
7155 	    errmsg = check_stl_option(s);
7156 	if (varp == &p_ruf && errmsg == NULL)
7157 	    comp_col();
7158     }
7159 #endif
7160 
7161 #ifdef FEAT_INS_EXPAND
7162     /* check if it is a valid value for 'complete' -- Acevedo */
7163     else if (gvarp == &p_cpt)
7164     {
7165 	for (s = *varp; *s;)
7166 	{
7167 	    while (*s == ',' || *s == ' ')
7168 		s++;
7169 	    if (!*s)
7170 		break;
7171 	    if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7172 	    {
7173 		errmsg = illegal_char(errbuf, *s);
7174 		break;
7175 	    }
7176 	    if (*++s != NUL && *s != ',' && *s != ' ')
7177 	    {
7178 		if (s[-1] == 'k' || s[-1] == 's')
7179 		{
7180 		    /* skip optional filename after 'k' and 's' */
7181 		    while (*s && *s != ',' && *s != ' ')
7182 		    {
7183 			if (*s == '\\' && s[1] != NUL)
7184 			    ++s;
7185 			++s;
7186 		    }
7187 		}
7188 		else
7189 		{
7190 		    if (errbuf != NULL)
7191 		    {
7192 			sprintf((char *)errbuf,
7193 				     _("E535: Illegal character after <%c>"),
7194 				     *--s);
7195 			errmsg = errbuf;
7196 		    }
7197 		    else
7198 			errmsg = (char_u *)"";
7199 		    break;
7200 		}
7201 	    }
7202 	}
7203     }
7204 
7205     /* 'completeopt' */
7206     else if (varp == &p_cot)
7207     {
7208 	if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7209 	    errmsg = e_invarg;
7210 	else
7211 	    completeopt_was_set();
7212     }
7213 #endif /* FEAT_INS_EXPAND */
7214 
7215 #ifdef FEAT_SIGNS
7216     /* 'signcolumn' */
7217     else if (varp == &curwin->w_p_scl)
7218     {
7219 	if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7220 	    errmsg = e_invarg;
7221     }
7222 #endif
7223 
7224 
7225 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
7226     /* 'toolbar' */
7227     else if (varp == &p_toolbar)
7228     {
7229 	if (opt_strings_flags(p_toolbar, p_toolbar_values,
7230 			      &toolbar_flags, TRUE) != OK)
7231 	    errmsg = e_invarg;
7232 	else
7233 	{
7234 	    out_flush();
7235 	    gui_mch_show_toolbar((toolbar_flags &
7236 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7237 	}
7238     }
7239 #endif
7240 
7241 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
7242     /* 'toolbariconsize': GTK+ 2 only */
7243     else if (varp == &p_tbis)
7244     {
7245 	if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7246 	    errmsg = e_invarg;
7247 	else
7248 	{
7249 	    out_flush();
7250 	    gui_mch_show_toolbar((toolbar_flags &
7251 				  (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7252 	}
7253     }
7254 #endif
7255 
7256     /* 'pastetoggle': translate key codes like in a mapping */
7257     else if (varp == &p_pt)
7258     {
7259 	if (*p_pt)
7260 	{
7261 	    (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
7262 	    if (p != NULL)
7263 	    {
7264 		if (new_value_alloced)
7265 		    free_string_option(p_pt);
7266 		p_pt = p;
7267 		new_value_alloced = TRUE;
7268 	    }
7269 	}
7270     }
7271 
7272     /* 'backspace' */
7273     else if (varp == &p_bs)
7274     {
7275 	if (VIM_ISDIGIT(*p_bs))
7276 	{
7277 	    if (*p_bs > '2' || p_bs[1] != NUL)
7278 		errmsg = e_invarg;
7279 	}
7280 	else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7281 	    errmsg = e_invarg;
7282     }
7283     else if (varp == &p_bo)
7284     {
7285 	if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7286 	    errmsg = e_invarg;
7287     }
7288 
7289     /* 'tagcase' */
7290     else if (gvarp == &p_tc)
7291     {
7292 	unsigned int	*flags;
7293 
7294 	if (opt_flags & OPT_LOCAL)
7295 	{
7296 	    p = curbuf->b_p_tc;
7297 	    flags = &curbuf->b_tc_flags;
7298 	}
7299 	else
7300 	{
7301 	    p = p_tc;
7302 	    flags = &tc_flags;
7303 	}
7304 
7305 	if ((opt_flags & OPT_LOCAL) && *p == NUL)
7306 	    /* make the local value empty: use the global value */
7307 	    *flags = 0;
7308 	else if (*p == NUL
7309 		|| opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7310 	    errmsg = e_invarg;
7311     }
7312 
7313 #ifdef FEAT_MBYTE
7314     /* 'casemap' */
7315     else if (varp == &p_cmp)
7316     {
7317 	if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7318 	    errmsg = e_invarg;
7319     }
7320 #endif
7321 
7322 #ifdef FEAT_DIFF
7323     /* 'diffopt' */
7324     else if (varp == &p_dip)
7325     {
7326 	if (diffopt_changed() == FAIL)
7327 	    errmsg = e_invarg;
7328     }
7329 #endif
7330 
7331 #ifdef FEAT_FOLDING
7332     /* 'foldmethod' */
7333     else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7334     {
7335 	if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7336 		|| *curwin->w_p_fdm == NUL)
7337 	    errmsg = e_invarg;
7338 	else
7339 	{
7340 	    foldUpdateAll(curwin);
7341 	    if (foldmethodIsDiff(curwin))
7342 		newFoldLevel();
7343 	}
7344     }
7345 # ifdef FEAT_EVAL
7346     /* 'foldexpr' */
7347     else if (varp == &curwin->w_p_fde)
7348     {
7349 	if (foldmethodIsExpr(curwin))
7350 	    foldUpdateAll(curwin);
7351     }
7352 # endif
7353     /* 'foldmarker' */
7354     else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7355     {
7356 	p = vim_strchr(*varp, ',');
7357 	if (p == NULL)
7358 	    errmsg = (char_u *)N_("E536: comma required");
7359 	else if (p == *varp || p[1] == NUL)
7360 	    errmsg = e_invarg;
7361 	else if (foldmethodIsMarker(curwin))
7362 	    foldUpdateAll(curwin);
7363     }
7364     /* 'commentstring' */
7365     else if (gvarp == &p_cms)
7366     {
7367 	if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7368 	    errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7369     }
7370     /* 'foldopen' */
7371     else if (varp == &p_fdo)
7372     {
7373 	if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7374 	    errmsg = e_invarg;
7375     }
7376     /* 'foldclose' */
7377     else if (varp == &p_fcl)
7378     {
7379 	if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7380 	    errmsg = e_invarg;
7381     }
7382     /* 'foldignore' */
7383     else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7384     {
7385 	if (foldmethodIsIndent(curwin))
7386 	    foldUpdateAll(curwin);
7387     }
7388 #endif
7389 
7390 #ifdef FEAT_VIRTUALEDIT
7391     /* 'virtualedit' */
7392     else if (varp == &p_ve)
7393     {
7394 	if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7395 	    errmsg = e_invarg;
7396 	else if (STRCMP(p_ve, oldval) != 0)
7397 	{
7398 	    /* Recompute cursor position in case the new 've' setting
7399 	     * changes something. */
7400 	    validate_virtcol();
7401 	    coladvance(curwin->w_virtcol);
7402 	}
7403     }
7404 #endif
7405 
7406 #if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7407     else if (varp == &p_csqf)
7408     {
7409 	if (p_csqf != NULL)
7410 	{
7411 	    p = p_csqf;
7412 	    while (*p != NUL)
7413 	    {
7414 		if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7415 			|| p[1] == NUL
7416 			|| vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7417 			|| (p[2] != NUL && p[2] != ','))
7418 		{
7419 		    errmsg = e_invarg;
7420 		    break;
7421 		}
7422 		else if (p[2] == NUL)
7423 		    break;
7424 		else
7425 		    p += 3;
7426 	    }
7427 	}
7428     }
7429 #endif
7430 
7431 #ifdef FEAT_CINDENT
7432     /* 'cinoptions' */
7433     else if (gvarp == &p_cino)
7434     {
7435 	/* TODO: recognize errors */
7436 	parse_cino(curbuf);
7437     }
7438 #endif
7439 
7440 #if defined(FEAT_RENDER_OPTIONS)
7441     /* 'renderoptions' */
7442     else if (varp == &p_rop && gui.in_use)
7443     {
7444 	if (!gui_mch_set_rendering_options(p_rop))
7445 	    errmsg = e_invarg;
7446     }
7447 #endif
7448 
7449 #ifdef FEAT_AUTOCMD
7450     else if (gvarp == &p_ft)
7451     {
7452 	if (!valid_filetype(*varp))
7453 	    errmsg = e_invarg;
7454 	else
7455 	    ft_changed = STRCMP(oldval, *varp) != 0;
7456     }
7457 #endif
7458 
7459 #ifdef FEAT_SYN_HL
7460     else if (gvarp == &p_syn)
7461     {
7462 	if (!valid_filetype(*varp))
7463 	    errmsg = e_invarg;
7464     }
7465 #endif
7466 
7467 #ifdef FEAT_TERMINAL
7468     /* 'termkey' */
7469     else if (varp == &curwin->w_p_tk)
7470     {
7471 	if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7472 	    errmsg = e_invarg;
7473     }
7474     /* 'termsize' */
7475     else if (varp == &curwin->w_p_tms)
7476     {
7477 	if (*curwin->w_p_tms != NUL)
7478 	{
7479 	    p = skipdigits(curwin->w_p_tms);
7480 	    if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7481 		errmsg = e_invarg;
7482 	}
7483     }
7484 #endif
7485 
7486     /* Options that are a list of flags. */
7487     else
7488     {
7489 	p = NULL;
7490 	if (varp == &p_ww) /* 'whichwrap' */
7491 	    p = (char_u *)WW_ALL;
7492 	if (varp == &p_shm) /* 'shortmess' */
7493 	    p = (char_u *)SHM_ALL;
7494 	else if (varp == &(p_cpo)) /* 'cpoptions' */
7495 	    p = (char_u *)CPO_ALL;
7496 	else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
7497 	    p = (char_u *)FO_ALL;
7498 #ifdef FEAT_CONCEAL
7499 	else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
7500 	    p = (char_u *)COCU_ALL;
7501 #endif
7502 	else if (varp == &p_mouse) /* 'mouse' */
7503 	{
7504 #ifdef FEAT_MOUSE
7505 	    p = (char_u *)MOUSE_ALL;
7506 #else
7507 	    if (*p_mouse != NUL)
7508 		errmsg = (char_u *)N_("E538: No mouse support");
7509 #endif
7510 	}
7511 #if defined(FEAT_GUI)
7512 	else if (varp == &p_go) /* 'guioptions' */
7513 	    p = (char_u *)GO_ALL;
7514 #endif
7515 	if (p != NULL)
7516 	{
7517 	    for (s = *varp; *s; ++s)
7518 		if (vim_strchr(p, *s) == NULL)
7519 		{
7520 		    errmsg = illegal_char(errbuf, *s);
7521 		    break;
7522 		}
7523 	}
7524     }
7525 
7526     /*
7527      * If error detected, restore the previous value.
7528      */
7529     if (errmsg != NULL)
7530     {
7531 	if (new_value_alloced)
7532 	    free_string_option(*varp);
7533 	*varp = oldval;
7534 	/*
7535 	 * When resetting some values, need to act on it.
7536 	 */
7537 	if (did_chartab)
7538 	    (void)init_chartab();
7539 	if (varp == &p_hl)
7540 	    (void)highlight_changed();
7541     }
7542     else
7543     {
7544 #ifdef FEAT_EVAL
7545 	/* Remember where the option was set. */
7546 	set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
7547 #endif
7548 	/*
7549 	 * Free string options that are in allocated memory.
7550 	 * Use "free_oldval", because recursiveness may change the flags under
7551 	 * our fingers (esp. init_highlight()).
7552 	 */
7553 	if (free_oldval)
7554 	    free_string_option(oldval);
7555 	if (new_value_alloced)
7556 	    options[opt_idx].flags |= P_ALLOCED;
7557 	else
7558 	    options[opt_idx].flags &= ~P_ALLOCED;
7559 
7560 	if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
7561 		&& ((int)options[opt_idx].indir & PV_BOTH))
7562 	{
7563 	    /* global option with local value set to use global value; free
7564 	     * the local value and make it empty */
7565 	    p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7566 	    free_string_option(*(char_u **)p);
7567 	    *(char_u **)p = empty_option;
7568 	}
7569 
7570 	/* May set global value for local option. */
7571 	else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7572 	    set_string_option_global(opt_idx, varp);
7573 
7574 #ifdef FEAT_AUTOCMD
7575 	/*
7576 	 * Trigger the autocommand only after setting the flags.
7577 	 */
7578 # ifdef FEAT_SYN_HL
7579 	/* When 'syntax' is set, load the syntax of that name */
7580 	if (varp == &(curbuf->b_p_syn))
7581 	{
7582 	    apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7583 					       curbuf->b_fname, TRUE, curbuf);
7584 	}
7585 # endif
7586 	else if (varp == &(curbuf->b_p_ft))
7587 	{
7588 	    /* 'filetype' is set, trigger the FileType autocommand.
7589 	     * Skip this when called from a modeline and the filetype was
7590 	     * already set to this value. */
7591 	    if (!(opt_flags & OPT_MODELINE) || ft_changed)
7592 	    {
7593 		did_filetype = TRUE;
7594 		apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7595 					       curbuf->b_fname, TRUE, curbuf);
7596 		/* Just in case the old "curbuf" is now invalid. */
7597 		if (varp != &(curbuf->b_p_ft))
7598 		    varp = NULL;
7599 	    }
7600 	}
7601 #endif
7602 #ifdef FEAT_SPELL
7603 	if (varp == &(curwin->w_s->b_p_spl))
7604 	{
7605 	    char_u	fname[200];
7606 	    char_u	*q = curwin->w_s->b_p_spl;
7607 
7608 	    /* Skip the first name if it is "cjk". */
7609 	    if (STRNCMP(q, "cjk,", 4) == 0)
7610 		q += 4;
7611 
7612 	    /*
7613 	     * Source the spell/LANG.vim in 'runtimepath'.
7614 	     * They could set 'spellcapcheck' depending on the language.
7615 	     * Use the first name in 'spelllang' up to '_region' or
7616 	     * '.encoding'.
7617 	     */
7618 	    for (p = q; *p != NUL; ++p)
7619 		if (vim_strchr((char_u *)"_.,", *p) != NULL)
7620 		    break;
7621 	    vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7622 	    source_runtime(fname, DIP_ALL);
7623 	}
7624 #endif
7625     }
7626 
7627 #ifdef FEAT_MOUSE
7628     if (varp == &p_mouse)
7629     {
7630 # ifdef FEAT_MOUSE_TTY
7631 	if (*p_mouse == NUL)
7632 	    mch_setmouse(FALSE);    /* switch mouse off */
7633 	else
7634 # endif
7635 	    setmouse();		    /* in case 'mouse' changed */
7636     }
7637 #endif
7638 
7639     if (curwin->w_curswant != MAXCOL
7640 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
7641 	curwin->w_set_curswant = TRUE;
7642 
7643 #ifdef FEAT_GUI
7644     /* check redraw when it's not a GUI option or the GUI is active. */
7645     if (!redraw_gui_only || gui.in_use)
7646 #endif
7647 	check_redraw(options[opt_idx].flags);
7648 
7649     return errmsg;
7650 }
7651 
7652 #if defined(FEAT_SYN_HL) || defined(PROTO)
7653 /*
7654  * Simple int comparison function for use with qsort()
7655  */
7656     static int
7657 int_cmp(const void *a, const void *b)
7658 {
7659     return *(const int *)a - *(const int *)b;
7660 }
7661 
7662 /*
7663  * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7664  * Returns error message, NULL if it's OK.
7665  */
7666     char_u *
7667 check_colorcolumn(win_T *wp)
7668 {
7669     char_u	*s;
7670     int		col;
7671     int		count = 0;
7672     int		color_cols[256];
7673     int		i;
7674     int		j = 0;
7675 
7676     if (wp->w_buffer == NULL)
7677 	return NULL;  /* buffer was closed */
7678 
7679     for (s = wp->w_p_cc; *s != NUL && count < 255;)
7680     {
7681 	if (*s == '-' || *s == '+')
7682 	{
7683 	    /* -N and +N: add to 'textwidth' */
7684 	    col = (*s == '-') ? -1 : 1;
7685 	    ++s;
7686 	    if (!VIM_ISDIGIT(*s))
7687 		return e_invarg;
7688 	    col = col * getdigits(&s);
7689 	    if (wp->w_buffer->b_p_tw == 0)
7690 		goto skip;  /* 'textwidth' not set, skip this item */
7691 	    col += wp->w_buffer->b_p_tw;
7692 	    if (col < 0)
7693 		goto skip;
7694 	}
7695 	else if (VIM_ISDIGIT(*s))
7696 	    col = getdigits(&s);
7697 	else
7698 	    return e_invarg;
7699 	color_cols[count++] = col - 1;  /* 1-based to 0-based */
7700 skip:
7701 	if (*s == NUL)
7702 	    break;
7703 	if (*s != ',')
7704 	    return e_invarg;
7705 	if (*++s == NUL)
7706 	    return e_invarg;  /* illegal trailing comma as in "set cc=80," */
7707     }
7708 
7709     vim_free(wp->w_p_cc_cols);
7710     if (count == 0)
7711 	wp->w_p_cc_cols = NULL;
7712     else
7713     {
7714 	wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7715 	if (wp->w_p_cc_cols != NULL)
7716 	{
7717 	    /* sort the columns for faster usage on screen redraw inside
7718 	     * win_line() */
7719 	    qsort(color_cols, count, sizeof(int), int_cmp);
7720 
7721 	    for (i = 0; i < count; ++i)
7722 		/* skip duplicates */
7723 		if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7724 		    wp->w_p_cc_cols[j++] = color_cols[i];
7725 	    wp->w_p_cc_cols[j] = -1;  /* end marker */
7726 	}
7727     }
7728 
7729     return NULL;  /* no error */
7730 }
7731 #endif
7732 
7733 /*
7734  * Handle setting 'listchars' or 'fillchars'.
7735  * Returns error message, NULL if it's OK.
7736  */
7737     static char_u *
7738 set_chars_option(char_u **varp)
7739 {
7740     int		round, i, len, entries;
7741     char_u	*p, *s;
7742     int		c1, c2 = 0;
7743     struct charstab
7744     {
7745 	int	*cp;
7746 	char	*name;
7747     };
7748 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7749     static struct charstab filltab[] =
7750     {
7751 	{&fill_stl,	"stl"},
7752 	{&fill_stlnc,	"stlnc"},
7753 	{&fill_vert,	"vert"},
7754 	{&fill_fold,	"fold"},
7755 	{&fill_diff,	"diff"},
7756     };
7757 #endif
7758     static struct charstab lcstab[] =
7759     {
7760 	{&lcs_eol,	"eol"},
7761 	{&lcs_ext,	"extends"},
7762 	{&lcs_nbsp,	"nbsp"},
7763 	{&lcs_prec,	"precedes"},
7764 	{&lcs_space,	"space"},
7765 	{&lcs_tab2,	"tab"},
7766 	{&lcs_trail,	"trail"},
7767 #ifdef FEAT_CONCEAL
7768 	{&lcs_conceal,	"conceal"},
7769 #else
7770 	{NULL,		"conceal"},
7771 #endif
7772     };
7773     struct charstab *tab;
7774 
7775 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7776     if (varp == &p_lcs)
7777 #endif
7778     {
7779 	tab = lcstab;
7780 	entries = sizeof(lcstab) / sizeof(struct charstab);
7781     }
7782 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7783     else
7784     {
7785 	tab = filltab;
7786 	entries = sizeof(filltab) / sizeof(struct charstab);
7787     }
7788 #endif
7789 
7790     /* first round: check for valid value, second round: assign values */
7791     for (round = 0; round <= 1; ++round)
7792     {
7793 	if (round > 0)
7794 	{
7795 	    /* After checking that the value is valid: set defaults: space for
7796 	     * 'fillchars', NUL for 'listchars' */
7797 	    for (i = 0; i < entries; ++i)
7798 		if (tab[i].cp != NULL)
7799 		    *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
7800 	    if (varp == &p_lcs)
7801 		lcs_tab1 = NUL;
7802 #if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7803 	    else
7804 		fill_diff = '-';
7805 #endif
7806 	}
7807 	p = *varp;
7808 	while (*p)
7809 	{
7810 	    for (i = 0; i < entries; ++i)
7811 	    {
7812 		len = (int)STRLEN(tab[i].name);
7813 		if (STRNCMP(p, tab[i].name, len) == 0
7814 			&& p[len] == ':'
7815 			&& p[len + 1] != NUL)
7816 		{
7817 		    s = p + len + 1;
7818 #ifdef FEAT_MBYTE
7819 		    c1 = mb_ptr2char_adv(&s);
7820 		    if (mb_char2cells(c1) > 1)
7821 			continue;
7822 #else
7823 		    c1 = *s++;
7824 #endif
7825 		    if (tab[i].cp == &lcs_tab2)
7826 		    {
7827 			if (*s == NUL)
7828 			    continue;
7829 #ifdef FEAT_MBYTE
7830 			c2 = mb_ptr2char_adv(&s);
7831 			if (mb_char2cells(c2) > 1)
7832 			    continue;
7833 #else
7834 			c2 = *s++;
7835 #endif
7836 		    }
7837 		    if (*s == ',' || *s == NUL)
7838 		    {
7839 			if (round)
7840 			{
7841 			    if (tab[i].cp == &lcs_tab2)
7842 			    {
7843 				lcs_tab1 = c1;
7844 				lcs_tab2 = c2;
7845 			    }
7846 			    else if (tab[i].cp != NULL)
7847 				*(tab[i].cp) = c1;
7848 
7849 			}
7850 			p = s;
7851 			break;
7852 		    }
7853 		}
7854 	    }
7855 
7856 	    if (i == entries)
7857 		return e_invarg;
7858 	    if (*p == ',')
7859 		++p;
7860 	}
7861     }
7862 
7863     return NULL;	/* no error */
7864 }
7865 
7866 #ifdef FEAT_STL_OPT
7867 /*
7868  * Check validity of options with the 'statusline' format.
7869  * Return error message or NULL.
7870  */
7871     char_u *
7872 check_stl_option(char_u *s)
7873 {
7874     int		itemcnt = 0;
7875     int		groupdepth = 0;
7876     static char_u   errbuf[80];
7877 
7878     while (*s && itemcnt < STL_MAX_ITEM)
7879     {
7880 	/* Check for valid keys after % sequences */
7881 	while (*s && *s != '%')
7882 	    s++;
7883 	if (!*s)
7884 	    break;
7885 	s++;
7886 	if (*s != '%' && *s != ')')
7887 	    ++itemcnt;
7888 	if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7889 	{
7890 	    s++;
7891 	    continue;
7892 	}
7893 	if (*s == ')')
7894 	{
7895 	    s++;
7896 	    if (--groupdepth < 0)
7897 		break;
7898 	    continue;
7899 	}
7900 	if (*s == '-')
7901 	    s++;
7902 	while (VIM_ISDIGIT(*s))
7903 	    s++;
7904 	if (*s == STL_USER_HL)
7905 	    continue;
7906 	if (*s == '.')
7907 	{
7908 	    s++;
7909 	    while (*s && VIM_ISDIGIT(*s))
7910 		s++;
7911 	}
7912 	if (*s == '(')
7913 	{
7914 	    groupdepth++;
7915 	    continue;
7916 	}
7917 	if (vim_strchr(STL_ALL, *s) == NULL)
7918 	{
7919 	    return illegal_char(errbuf, *s);
7920 	}
7921 	if (*s == '{')
7922 	{
7923 	    s++;
7924 	    while (*s != '}' && *s)
7925 		s++;
7926 	    if (*s != '}')
7927 		return (char_u *)N_("E540: Unclosed expression sequence");
7928 	}
7929     }
7930     if (itemcnt >= STL_MAX_ITEM)
7931 	return (char_u *)N_("E541: too many items");
7932     if (groupdepth != 0)
7933 	return (char_u *)N_("E542: unbalanced groups");
7934     return NULL;
7935 }
7936 #endif
7937 
7938 #ifdef FEAT_CLIPBOARD
7939 /*
7940  * Extract the items in the 'clipboard' option and set global values.
7941  */
7942     static char_u *
7943 check_clipboard_option(void)
7944 {
7945     int		new_unnamed = 0;
7946     int		new_autoselect_star = FALSE;
7947     int		new_autoselect_plus = FALSE;
7948     int		new_autoselectml = FALSE;
7949     int		new_html = FALSE;
7950     regprog_T	*new_exclude_prog = NULL;
7951     char_u	*errmsg = NULL;
7952     char_u	*p;
7953 
7954     for (p = p_cb; *p != NUL; )
7955     {
7956 	if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7957 	{
7958 	    new_unnamed |= CLIP_UNNAMED;
7959 	    p += 7;
7960 	}
7961 	else if (STRNCMP(p, "unnamedplus", 11) == 0
7962 					    && (p[11] == ',' || p[11] == NUL))
7963 	{
7964 	    new_unnamed |= CLIP_UNNAMED_PLUS;
7965 	    p += 11;
7966 	}
7967 	else if (STRNCMP(p, "autoselect", 10) == 0
7968 					    && (p[10] == ',' || p[10] == NUL))
7969 	{
7970 	    new_autoselect_star = TRUE;
7971 	    p += 10;
7972 	}
7973 	else if (STRNCMP(p, "autoselectplus", 14) == 0
7974 					    && (p[14] == ',' || p[14] == NUL))
7975 	{
7976 	    new_autoselect_plus = TRUE;
7977 	    p += 14;
7978 	}
7979 	else if (STRNCMP(p, "autoselectml", 12) == 0
7980 					    && (p[12] == ',' || p[12] == NUL))
7981 	{
7982 	    new_autoselectml = TRUE;
7983 	    p += 12;
7984 	}
7985 	else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7986 	{
7987 	    new_html = TRUE;
7988 	    p += 4;
7989 	}
7990 	else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7991 	{
7992 	    p += 8;
7993 	    new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7994 	    if (new_exclude_prog == NULL)
7995 		errmsg = e_invarg;
7996 	    break;
7997 	}
7998 	else
7999 	{
8000 	    errmsg = e_invarg;
8001 	    break;
8002 	}
8003 	if (*p == ',')
8004 	    ++p;
8005     }
8006     if (errmsg == NULL)
8007     {
8008 	clip_unnamed = new_unnamed;
8009 	clip_autoselect_star = new_autoselect_star;
8010 	clip_autoselect_plus = new_autoselect_plus;
8011 	clip_autoselectml = new_autoselectml;
8012 	clip_html = new_html;
8013 	vim_regfree(clip_exclude_prog);
8014 	clip_exclude_prog = new_exclude_prog;
8015 #ifdef FEAT_GUI_GTK
8016 	if (gui.in_use)
8017 	{
8018 	    gui_gtk_set_selection_targets();
8019 	    gui_gtk_set_dnd_targets();
8020 	}
8021 #endif
8022     }
8023     else
8024 	vim_regfree(new_exclude_prog);
8025 
8026     return errmsg;
8027 }
8028 #endif
8029 
8030 #ifdef FEAT_SPELL
8031     static char_u *
8032 did_set_spell_option(int is_spellfile)
8033 {
8034     char_u  *errmsg = NULL;
8035     win_T   *wp;
8036     int	    l;
8037 
8038     if (is_spellfile)
8039     {
8040 	l = (int)STRLEN(curwin->w_s->b_p_spf);
8041 	if (l > 0 && (l < 4
8042 			|| STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8043 	    errmsg = e_invarg;
8044     }
8045 
8046     if (errmsg == NULL)
8047     {
8048 	FOR_ALL_WINDOWS(wp)
8049 	    if (wp->w_buffer == curbuf && wp->w_p_spell)
8050 	    {
8051 		errmsg = did_set_spelllang(wp);
8052 # ifdef FEAT_WINDOWS
8053 		break;
8054 # endif
8055 	    }
8056     }
8057     return errmsg;
8058 }
8059 
8060 /*
8061  * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8062  * Return error message when failed, NULL when OK.
8063  */
8064     static char_u *
8065 compile_cap_prog(synblock_T *synblock)
8066 {
8067     regprog_T   *rp = synblock->b_cap_prog;
8068     char_u	*re;
8069 
8070     if (*synblock->b_p_spc == NUL)
8071 	synblock->b_cap_prog = NULL;
8072     else
8073     {
8074 	/* Prepend a ^ so that we only match at one column */
8075 	re = concat_str((char_u *)"^", synblock->b_p_spc);
8076 	if (re != NULL)
8077 	{
8078 	    synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
8079 	    vim_free(re);
8080 	    if (synblock->b_cap_prog == NULL)
8081 	    {
8082 		synblock->b_cap_prog = rp; /* restore the previous program */
8083 		return e_invarg;
8084 	    }
8085 	}
8086     }
8087 
8088     vim_regfree(rp);
8089     return NULL;
8090 }
8091 #endif
8092 
8093 #if defined(FEAT_EVAL) || defined(PROTO)
8094 /*
8095  * Set the scriptID for an option, taking care of setting the buffer- or
8096  * window-local value.
8097  */
8098     static void
8099 set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
8100 {
8101     int		both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8102     int		indir = (int)options[opt_idx].indir;
8103 
8104     /* Remember where the option was set.  For local options need to do that
8105      * in the buffer or window structure. */
8106     if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
8107 	options[opt_idx].scriptID = id;
8108     if (both || (opt_flags & OPT_LOCAL))
8109     {
8110 	if (indir & PV_BUF)
8111 	    curbuf->b_p_scriptID[indir & PV_MASK] = id;
8112 	else if (indir & PV_WIN)
8113 	    curwin->w_p_scriptID[indir & PV_MASK] = id;
8114     }
8115 }
8116 #endif
8117 
8118 /*
8119  * Set the value of a boolean option, and take care of side effects.
8120  * Returns NULL for success, or an error message for an error.
8121  */
8122     static char_u *
8123 set_bool_option(
8124     int		opt_idx,		/* index in options[] table */
8125     char_u	*varp,			/* pointer to the option variable */
8126     int		value,			/* new value */
8127     int		opt_flags)		/* OPT_LOCAL and/or OPT_GLOBAL */
8128 {
8129     int		old_value = *(int *)varp;
8130 
8131     /* Disallow changing some options from secure mode */
8132     if ((secure
8133 #ifdef HAVE_SANDBOX
8134 		|| sandbox != 0
8135 #endif
8136 		) && (options[opt_idx].flags & P_SECURE))
8137 	return e_secure;
8138 
8139     *(int *)varp = value;	    /* set the new value */
8140 #ifdef FEAT_EVAL
8141     /* Remember where the option was set. */
8142     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
8143 #endif
8144 
8145 #ifdef FEAT_GUI
8146     need_mouse_correct = TRUE;
8147 #endif
8148 
8149     /* May set global value for local option. */
8150     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8151 	*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8152 
8153     /*
8154      * Handle side effects of changing a bool option.
8155      */
8156 
8157     /* 'compatible' */
8158     if ((int *)varp == &p_cp)
8159     {
8160 	compatible_set();
8161     }
8162 
8163 #ifdef FEAT_LANGMAP
8164     if ((int *)varp == &p_lrm)
8165 	/* 'langremap' -> !'langnoremap' */
8166 	p_lnr = !p_lrm;
8167     else if ((int *)varp == &p_lnr)
8168 	/* 'langnoremap' -> !'langremap' */
8169 	p_lrm = !p_lnr;
8170 #endif
8171 
8172 #ifdef FEAT_PERSISTENT_UNDO
8173     /* 'undofile' */
8174     else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8175     {
8176 	/* Only take action when the option was set. When reset we do not
8177 	 * delete the undo file, the option may be set again without making
8178 	 * any changes in between. */
8179 	if (curbuf->b_p_udf || p_udf)
8180 	{
8181 	    char_u	hash[UNDO_HASH_SIZE];
8182 	    buf_T	*save_curbuf = curbuf;
8183 
8184 	    FOR_ALL_BUFFERS(curbuf)
8185 	    {
8186 		/* When 'undofile' is set globally: for every buffer, otherwise
8187 		 * only for the current buffer: Try to read in the undofile,
8188 		 * if one exists, the buffer wasn't changed and the buffer was
8189 		 * loaded */
8190 		if ((curbuf == save_curbuf
8191 				|| (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8192 			&& !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8193 		{
8194 		    u_compute_hash(hash);
8195 		    u_read_undo(NULL, hash, curbuf->b_fname);
8196 		}
8197 	    }
8198 	    curbuf = save_curbuf;
8199 	}
8200     }
8201 #endif
8202 
8203     else if ((int *)varp == &curbuf->b_p_ro)
8204     {
8205 	/* when 'readonly' is reset globally, also reset readonlymode */
8206 	if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8207 	    readonlymode = FALSE;
8208 
8209 	/* when 'readonly' is set may give W10 again */
8210 	if (curbuf->b_p_ro)
8211 	    curbuf->b_did_warn = FALSE;
8212 
8213 #ifdef FEAT_TITLE
8214 	redraw_titles();
8215 #endif
8216     }
8217 
8218 #ifdef FEAT_GUI
8219     else if ((int *)varp == &p_mh)
8220     {
8221 	if (!p_mh)
8222 	    gui_mch_mousehide(FALSE);
8223     }
8224 #endif
8225 
8226     /* when 'modifiable' is changed, redraw the window title */
8227     else if ((int *)varp == &curbuf->b_p_ma)
8228     {
8229 # ifdef FEAT_TERMINAL
8230 	/* Cannot set 'modifiable' when in Terminal mode. */
8231 	if (term_in_normal_mode()
8232 			 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
8233 	{
8234 	    curbuf->b_p_ma = FALSE;
8235 	    return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8236 	}
8237 # endif
8238 # ifdef FEAT_TITLE
8239 	redraw_titles();
8240 # endif
8241     }
8242 #ifdef FEAT_TITLE
8243     /* when 'endofline' is changed, redraw the window title */
8244     else if ((int *)varp == &curbuf->b_p_eol)
8245     {
8246 	redraw_titles();
8247     }
8248     /* when 'fixeol' is changed, redraw the window title */
8249     else if ((int *)varp == &curbuf->b_p_fixeol)
8250     {
8251 	redraw_titles();
8252     }
8253 # ifdef FEAT_MBYTE
8254     /* when 'bomb' is changed, redraw the window title and tab page text */
8255     else if ((int *)varp == &curbuf->b_p_bomb)
8256     {
8257 	redraw_titles();
8258     }
8259 # endif
8260 #endif
8261 
8262     /* when 'bin' is set also set some other options */
8263     else if ((int *)varp == &curbuf->b_p_bin)
8264     {
8265 	set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8266 #ifdef FEAT_TITLE
8267 	redraw_titles();
8268 #endif
8269     }
8270 
8271 #ifdef FEAT_AUTOCMD
8272     /* when 'buflisted' changes, trigger autocommands */
8273     else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8274     {
8275 	apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8276 						    NULL, NULL, TRUE, curbuf);
8277     }
8278 #endif
8279 
8280     /* when 'swf' is set, create swapfile, when reset remove swapfile */
8281     else if ((int *)varp == &curbuf->b_p_swf)
8282     {
8283 	if (curbuf->b_p_swf && p_uc)
8284 	    ml_open_file(curbuf);		/* create the swap file */
8285 	else
8286 	    /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8287 	     * buf->b_p_swf */
8288 	    mf_close_file(curbuf, TRUE);	/* remove the swap file */
8289     }
8290 
8291     /* when 'terse' is set change 'shortmess' */
8292     else if ((int *)varp == &p_terse)
8293     {
8294 	char_u	*p;
8295 
8296 	p = vim_strchr(p_shm, SHM_SEARCH);
8297 
8298 	/* insert 's' in p_shm */
8299 	if (p_terse && p == NULL)
8300 	{
8301 	    STRCPY(IObuff, p_shm);
8302 	    STRCAT(IObuff, "s");
8303 	    set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
8304 	}
8305 	/* remove 's' from p_shm */
8306 	else if (!p_terse && p != NULL)
8307 	    STRMOVE(p, p + 1);
8308     }
8309 
8310     /* when 'paste' is set or reset also change other options */
8311     else if ((int *)varp == &p_paste)
8312     {
8313 	paste_option_changed();
8314     }
8315 
8316     /* when 'insertmode' is set from an autocommand need to do work here */
8317     else if ((int *)varp == &p_im)
8318     {
8319 	if (p_im)
8320 	{
8321 	    if ((State & INSERT) == 0)
8322 		need_start_insertmode = TRUE;
8323 	    stop_insert_mode = FALSE;
8324 	}
8325 	/* only reset if it was set previously */
8326 	else if (old_value)
8327 	{
8328 	    need_start_insertmode = FALSE;
8329 	    stop_insert_mode = TRUE;
8330 	    if (restart_edit != 0 && mode_displayed)
8331 		clear_cmdline = TRUE;	/* remove "(insert)" */
8332 	    restart_edit = 0;
8333 	}
8334     }
8335 
8336     /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8337     else if ((int *)varp == &p_ic && p_hls)
8338     {
8339 	redraw_all_later(SOME_VALID);
8340     }
8341 
8342 #ifdef FEAT_SEARCH_EXTRA
8343     /* when 'hlsearch' is set or reset: reset no_hlsearch */
8344     else if ((int *)varp == &p_hls)
8345     {
8346 	SET_NO_HLSEARCH(FALSE);
8347     }
8348 #endif
8349 
8350 #ifdef FEAT_SCROLLBIND
8351     /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8352      * at the end of normal_cmd() */
8353     else if ((int *)varp == &curwin->w_p_scb)
8354     {
8355 	if (curwin->w_p_scb)
8356 	{
8357 	    do_check_scrollbind(FALSE);
8358 	    curwin->w_scbind_pos = curwin->w_topline;
8359 	}
8360     }
8361 #endif
8362 
8363 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8364     /* There can be only one window with 'previewwindow' set. */
8365     else if ((int *)varp == &curwin->w_p_pvw)
8366     {
8367 	if (curwin->w_p_pvw)
8368 	{
8369 	    win_T	*win;
8370 
8371 	    FOR_ALL_WINDOWS(win)
8372 		if (win->w_p_pvw && win != curwin)
8373 		{
8374 		    curwin->w_p_pvw = FALSE;
8375 		    return (char_u *)N_("E590: A preview window already exists");
8376 		}
8377 	}
8378     }
8379 #endif
8380 
8381     /* when 'textmode' is set or reset also change 'fileformat' */
8382     else if ((int *)varp == &curbuf->b_p_tx)
8383     {
8384 	set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8385     }
8386 
8387     /* when 'textauto' is set or reset also change 'fileformats' */
8388     else if ((int *)varp == &p_ta)
8389 	set_string_option_direct((char_u *)"ffs", -1,
8390 				 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
8391 						     OPT_FREE | opt_flags, 0);
8392 
8393     /*
8394      * When 'lisp' option changes include/exclude '-' in
8395      * keyword characters.
8396      */
8397 #ifdef FEAT_LISP
8398     else if (varp == (char_u *)&(curbuf->b_p_lisp))
8399     {
8400 	(void)buf_init_chartab(curbuf, FALSE);	    /* ignore errors */
8401     }
8402 #endif
8403 
8404 #ifdef FEAT_TITLE
8405     /* when 'title' changed, may need to change the title; same for 'icon' */
8406     else if ((int *)varp == &p_title)
8407     {
8408 	did_set_title(FALSE);
8409     }
8410 
8411     else if ((int *)varp == &p_icon)
8412     {
8413 	did_set_title(TRUE);
8414     }
8415 #endif
8416 
8417     else if ((int *)varp == &curbuf->b_changed)
8418     {
8419 	if (!value)
8420 	    save_file_ff(curbuf);	/* Buffer is unchanged */
8421 #ifdef FEAT_TITLE
8422 	redraw_titles();
8423 #endif
8424 #ifdef FEAT_AUTOCMD
8425 	modified_was_set = value;
8426 #endif
8427     }
8428 
8429 #ifdef BACKSLASH_IN_FILENAME
8430     else if ((int *)varp == &p_ssl)
8431     {
8432 	if (p_ssl)
8433 	{
8434 	    psepc = '/';
8435 	    psepcN = '\\';
8436 	    pseps[0] = '/';
8437 	}
8438 	else
8439 	{
8440 	    psepc = '\\';
8441 	    psepcN = '/';
8442 	    pseps[0] = '\\';
8443 	}
8444 
8445 	/* need to adjust the file name arguments and buffer names. */
8446 	buflist_slash_adjust();
8447 	alist_slash_adjust();
8448 # ifdef FEAT_EVAL
8449 	scriptnames_slash_adjust();
8450 # endif
8451     }
8452 #endif
8453 
8454     /* If 'wrap' is set, set w_leftcol to zero. */
8455     else if ((int *)varp == &curwin->w_p_wrap)
8456     {
8457 	if (curwin->w_p_wrap)
8458 	    curwin->w_leftcol = 0;
8459     }
8460 
8461 #ifdef FEAT_WINDOWS
8462     else if ((int *)varp == &p_ea)
8463     {
8464 	if (p_ea && !old_value)
8465 	    win_equal(curwin, FALSE, 0);
8466     }
8467 #endif
8468 
8469     else if ((int *)varp == &p_wiv)
8470     {
8471 	/*
8472 	 * When 'weirdinvert' changed, set/reset 't_xs'.
8473 	 * Then set 'weirdinvert' according to value of 't_xs'.
8474 	 */
8475 	if (p_wiv && !old_value)
8476 	    T_XS = (char_u *)"y";
8477 	else if (!p_wiv && old_value)
8478 	    T_XS = empty_option;
8479 	p_wiv = (*T_XS != NUL);
8480     }
8481 
8482 #ifdef FEAT_BEVAL
8483     else if ((int *)varp == &p_beval)
8484     {
8485 	if (p_beval && !old_value)
8486 	    gui_mch_enable_beval_area(balloonEval);
8487 	else if (!p_beval && old_value)
8488 	    gui_mch_disable_beval_area(balloonEval);
8489     }
8490 #endif
8491 
8492 #ifdef FEAT_AUTOCHDIR
8493     else if ((int *)varp == &p_acd)
8494     {
8495 	/* Change directories when the 'acd' option is set now. */
8496 	DO_AUTOCHDIR
8497     }
8498 #endif
8499 
8500 #ifdef FEAT_DIFF
8501     /* 'diff' */
8502     else if ((int *)varp == &curwin->w_p_diff)
8503     {
8504 	/* May add or remove the buffer from the list of diff buffers. */
8505 	diff_buf_adjust(curwin);
8506 # ifdef FEAT_FOLDING
8507 	if (foldmethodIsDiff(curwin))
8508 	    foldUpdateAll(curwin);
8509 # endif
8510     }
8511 #endif
8512 
8513 #ifdef USE_IM_CONTROL
8514     /* 'imdisable' */
8515     else if ((int *)varp == &p_imdisable)
8516     {
8517 	/* Only de-activate it here, it will be enabled when changing mode. */
8518 	if (p_imdisable)
8519 	    im_set_active(FALSE);
8520 	else if (State & INSERT)
8521 	    /* When the option is set from an autocommand, it may need to take
8522 	     * effect right away. */
8523 	    im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
8524     }
8525 #endif
8526 
8527 #ifdef FEAT_SPELL
8528     /* 'spell' */
8529     else if ((int *)varp == &curwin->w_p_spell)
8530     {
8531 	if (curwin->w_p_spell)
8532 	{
8533 	    char_u	*errmsg = did_set_spelllang(curwin);
8534 	    if (errmsg != NULL)
8535 		EMSG(_(errmsg));
8536 	}
8537     }
8538 #endif
8539 
8540 #ifdef FEAT_FKMAP
8541     else if ((int *)varp == &p_altkeymap)
8542     {
8543 	if (old_value != p_altkeymap)
8544 	{
8545 	    if (!p_altkeymap)
8546 	    {
8547 		p_hkmap = p_fkmap;
8548 		p_fkmap = 0;
8549 	    }
8550 	    else
8551 	    {
8552 		p_fkmap = p_hkmap;
8553 		p_hkmap = 0;
8554 	    }
8555 	    (void)init_chartab();
8556 	}
8557     }
8558 
8559     /*
8560      * In case some second language keymapping options have changed, check
8561      * and correct the setting in a consistent way.
8562      */
8563 
8564     /*
8565      * If hkmap or fkmap are set, reset Arabic keymapping.
8566      */
8567     if ((p_hkmap || p_fkmap) && p_altkeymap)
8568     {
8569 	p_altkeymap = p_fkmap;
8570 # ifdef FEAT_ARABIC
8571 	curwin->w_p_arab = FALSE;
8572 # endif
8573 	(void)init_chartab();
8574     }
8575 
8576     /*
8577      * If hkmap set, reset Farsi keymapping.
8578      */
8579     if (p_hkmap && p_altkeymap)
8580     {
8581 	p_altkeymap = 0;
8582 	p_fkmap = 0;
8583 # ifdef FEAT_ARABIC
8584 	curwin->w_p_arab = FALSE;
8585 # endif
8586 	(void)init_chartab();
8587     }
8588 
8589     /*
8590      * If fkmap set, reset Hebrew keymapping.
8591      */
8592     if (p_fkmap && !p_altkeymap)
8593     {
8594 	p_altkeymap = 1;
8595 	p_hkmap = 0;
8596 # ifdef FEAT_ARABIC
8597 	curwin->w_p_arab = FALSE;
8598 # endif
8599 	(void)init_chartab();
8600     }
8601 #endif
8602 
8603 #ifdef FEAT_ARABIC
8604     if ((int *)varp == &curwin->w_p_arab)
8605     {
8606 	if (curwin->w_p_arab)
8607 	{
8608 	    /*
8609 	     * 'arabic' is set, handle various sub-settings.
8610 	     */
8611 	    if (!p_tbidi)
8612 	    {
8613 		/* set rightleft mode */
8614 		if (!curwin->w_p_rl)
8615 		{
8616 		    curwin->w_p_rl = TRUE;
8617 		    changed_window_setting();
8618 		}
8619 
8620 		/* Enable Arabic shaping (major part of what Arabic requires) */
8621 		if (!p_arshape)
8622 		{
8623 		    p_arshape = TRUE;
8624 		    redraw_later_clear();
8625 		}
8626 	    }
8627 
8628 	    /* Arabic requires a utf-8 encoding, inform the user if its not
8629 	     * set. */
8630 	    if (STRCMP(p_enc, "utf-8") != 0)
8631 	    {
8632 		static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8633 
8634 		msg_source(HL_ATTR(HLF_W));
8635 		MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
8636 #ifdef FEAT_EVAL
8637 		set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8638 #endif
8639 	    }
8640 
8641 # ifdef FEAT_MBYTE
8642 	    /* set 'delcombine' */
8643 	    p_deco = TRUE;
8644 # endif
8645 
8646 # ifdef FEAT_KEYMAP
8647 	    /* Force-set the necessary keymap for arabic */
8648 	    set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8649 								   OPT_LOCAL);
8650 # endif
8651 # ifdef FEAT_FKMAP
8652 	    p_altkeymap = 0;
8653 	    p_hkmap = 0;
8654 	    p_fkmap = 0;
8655 	    (void)init_chartab();
8656 # endif
8657 	}
8658 	else
8659 	{
8660 	    /*
8661 	     * 'arabic' is reset, handle various sub-settings.
8662 	     */
8663 	    if (!p_tbidi)
8664 	    {
8665 		/* reset rightleft mode */
8666 		if (curwin->w_p_rl)
8667 		{
8668 		    curwin->w_p_rl = FALSE;
8669 		    changed_window_setting();
8670 		}
8671 
8672 		/* 'arabicshape' isn't reset, it is a global option and
8673 		 * another window may still need it "on". */
8674 	    }
8675 
8676 	    /* 'delcombine' isn't reset, it is a global option and another
8677 	     * window may still want it "on". */
8678 
8679 # ifdef FEAT_KEYMAP
8680 	    /* Revert to the default keymap */
8681 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8682 	    curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8683 # endif
8684 	}
8685     }
8686 
8687 #endif
8688 
8689 #ifdef FEAT_TERMGUICOLORS
8690     /* 'termguicolors' */
8691     else if ((int *)varp == &p_tgc)
8692     {
8693 # ifdef FEAT_GUI
8694 	if (!gui.in_use && !gui.starting)
8695 # endif
8696 	    highlight_gui_started();
8697     }
8698 #endif
8699 
8700     /*
8701      * End of handling side effects for bool options.
8702      */
8703 
8704     /* after handling side effects, call autocommand */
8705 
8706     options[opt_idx].flags |= P_WAS_SET;
8707 
8708 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8709     if (!starting)
8710     {
8711 	char_u buf_old[2], buf_new[2], buf_type[7];
8712 	vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8713 	vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8714 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
8715 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8716 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8717 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8718 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8719 	reset_v_option_vars();
8720     }
8721 #endif
8722 
8723     comp_col();			    /* in case 'ruler' or 'showcmd' changed */
8724     if (curwin->w_curswant != MAXCOL
8725 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
8726 	curwin->w_set_curswant = TRUE;
8727     check_redraw(options[opt_idx].flags);
8728 
8729     return NULL;
8730 }
8731 
8732 /*
8733  * Set the value of a number option, and take care of side effects.
8734  * Returns NULL for success, or an error message for an error.
8735  */
8736     static char_u *
8737 set_num_option(
8738     int		opt_idx,		/* index in options[] table */
8739     char_u	*varp,			/* pointer to the option variable */
8740     long	value,			/* new value */
8741     char_u	*errbuf,		/* buffer for error messages */
8742     size_t	errbuflen,		/* length of "errbuf" */
8743     int		opt_flags)		/* OPT_LOCAL, OPT_GLOBAL and
8744 					   OPT_MODELINE */
8745 {
8746     char_u	*errmsg = NULL;
8747     long	old_value = *(long *)varp;
8748     long	old_Rows = Rows;	/* remember old Rows */
8749     long	old_Columns = Columns;	/* remember old Columns */
8750     long	*pp = (long *)varp;
8751 
8752     /* Disallow changing some options from secure mode. */
8753     if ((secure
8754 #ifdef HAVE_SANDBOX
8755 		|| sandbox != 0
8756 #endif
8757 		) && (options[opt_idx].flags & P_SECURE))
8758 	return e_secure;
8759 
8760     *pp = value;
8761 #ifdef FEAT_EVAL
8762     /* Remember where the option was set. */
8763     set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
8764 #endif
8765 #ifdef FEAT_GUI
8766     need_mouse_correct = TRUE;
8767 #endif
8768 
8769     if (curbuf->b_p_sw < 0)
8770     {
8771 	errmsg = e_positive;
8772 	curbuf->b_p_sw = curbuf->b_p_ts;
8773     }
8774 
8775     /*
8776      * Number options that need some action when changed
8777      */
8778 #ifdef FEAT_WINDOWS
8779     if (pp == &p_wh || pp == &p_hh)
8780     {
8781 	if (p_wh < 1)
8782 	{
8783 	    errmsg = e_positive;
8784 	    p_wh = 1;
8785 	}
8786 	if (p_wmh > p_wh)
8787 	{
8788 	    errmsg = e_winheight;
8789 	    p_wh = p_wmh;
8790 	}
8791 	if (p_hh < 0)
8792 	{
8793 	    errmsg = e_positive;
8794 	    p_hh = 0;
8795 	}
8796 
8797 	/* Change window height NOW */
8798 	if (!ONE_WINDOW)
8799 	{
8800 	    if (pp == &p_wh && curwin->w_height < p_wh)
8801 		win_setheight((int)p_wh);
8802 	    if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8803 		win_setheight((int)p_hh);
8804 	}
8805     }
8806 
8807     /* 'winminheight' */
8808     else if (pp == &p_wmh)
8809     {
8810 	if (p_wmh < 0)
8811 	{
8812 	    errmsg = e_positive;
8813 	    p_wmh = 0;
8814 	}
8815 	if (p_wmh > p_wh)
8816 	{
8817 	    errmsg = e_winheight;
8818 	    p_wmh = p_wh;
8819 	}
8820 	win_setminheight();
8821     }
8822 
8823 # ifdef FEAT_WINDOWS
8824     else if (pp == &p_wiw)
8825     {
8826 	if (p_wiw < 1)
8827 	{
8828 	    errmsg = e_positive;
8829 	    p_wiw = 1;
8830 	}
8831 	if (p_wmw > p_wiw)
8832 	{
8833 	    errmsg = e_winwidth;
8834 	    p_wiw = p_wmw;
8835 	}
8836 
8837 	/* Change window width NOW */
8838 	if (!ONE_WINDOW && curwin->w_width < p_wiw)
8839 	    win_setwidth((int)p_wiw);
8840     }
8841 
8842     /* 'winminwidth' */
8843     else if (pp == &p_wmw)
8844     {
8845 	if (p_wmw < 0)
8846 	{
8847 	    errmsg = e_positive;
8848 	    p_wmw = 0;
8849 	}
8850 	if (p_wmw > p_wiw)
8851 	{
8852 	    errmsg = e_winwidth;
8853 	    p_wmw = p_wiw;
8854 	}
8855 	win_setminheight();
8856     }
8857 # endif
8858 
8859 #endif
8860 
8861 #ifdef FEAT_WINDOWS
8862     /* (re)set last window status line */
8863     else if (pp == &p_ls)
8864     {
8865 	last_status(FALSE);
8866     }
8867 
8868     /* (re)set tab page line */
8869     else if (pp == &p_stal)
8870     {
8871 	shell_new_rows();	/* recompute window positions and heights */
8872     }
8873 #endif
8874 
8875 #ifdef FEAT_GUI
8876     else if (pp == &p_linespace)
8877     {
8878 	/* Recompute gui.char_height and resize the Vim window to keep the
8879 	 * same number of lines. */
8880 	if (gui.in_use && gui_mch_adjust_charheight() == OK)
8881 	    gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
8882     }
8883 #endif
8884 
8885 #ifdef FEAT_FOLDING
8886     /* 'foldlevel' */
8887     else if (pp == &curwin->w_p_fdl)
8888     {
8889 	if (curwin->w_p_fdl < 0)
8890 	    curwin->w_p_fdl = 0;
8891 	newFoldLevel();
8892     }
8893 
8894     /* 'foldminlines' */
8895     else if (pp == &curwin->w_p_fml)
8896     {
8897 	foldUpdateAll(curwin);
8898     }
8899 
8900     /* 'foldnestmax' */
8901     else if (pp == &curwin->w_p_fdn)
8902     {
8903 	if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8904 	    foldUpdateAll(curwin);
8905     }
8906 
8907     /* 'foldcolumn' */
8908     else if (pp == &curwin->w_p_fdc)
8909     {
8910 	if (curwin->w_p_fdc < 0)
8911 	{
8912 	    errmsg = e_positive;
8913 	    curwin->w_p_fdc = 0;
8914 	}
8915 	else if (curwin->w_p_fdc > 12)
8916 	{
8917 	    errmsg = e_invarg;
8918 	    curwin->w_p_fdc = 12;
8919 	}
8920     }
8921 #endif /* FEAT_FOLDING */
8922 
8923 #if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
8924     /* 'shiftwidth' or 'tabstop' */
8925     else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8926     {
8927 # ifdef FEAT_FOLDING
8928 	if (foldmethodIsIndent(curwin))
8929 	    foldUpdateAll(curwin);
8930 # endif
8931 # ifdef FEAT_CINDENT
8932 	/* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8933 	 * parse 'cinoptions'. */
8934 	if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8935 	    parse_cino(curbuf);
8936 # endif
8937     }
8938 #endif
8939 
8940 #ifdef FEAT_MBYTE
8941     /* 'maxcombine' */
8942     else if (pp == &p_mco)
8943     {
8944 	if (p_mco > MAX_MCO)
8945 	    p_mco = MAX_MCO;
8946 	else if (p_mco < 0)
8947 	    p_mco = 0;
8948 	screenclear();	    /* will re-allocate the screen */
8949     }
8950 #endif
8951 
8952     else if (pp == &curbuf->b_p_iminsert)
8953     {
8954 	if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8955 	{
8956 	    errmsg = e_invarg;
8957 	    curbuf->b_p_iminsert = B_IMODE_NONE;
8958 	}
8959 	p_iminsert = curbuf->b_p_iminsert;
8960 	if (termcap_active)	/* don't do this in the alternate screen */
8961 	    showmode();
8962 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8963 	/* Show/unshow value of 'keymap' in status lines. */
8964 	status_redraw_curbuf();
8965 #endif
8966     }
8967 
8968     else if (pp == &p_window)
8969     {
8970 	if (p_window < 1)
8971 	    p_window = 1;
8972 	else if (p_window >= Rows)
8973 	    p_window = Rows - 1;
8974     }
8975 
8976     else if (pp == &curbuf->b_p_imsearch)
8977     {
8978 	if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8979 	{
8980 	    errmsg = e_invarg;
8981 	    curbuf->b_p_imsearch = B_IMODE_NONE;
8982 	}
8983 	p_imsearch = curbuf->b_p_imsearch;
8984     }
8985 
8986 #ifdef FEAT_TITLE
8987     /* if 'titlelen' has changed, redraw the title */
8988     else if (pp == &p_titlelen)
8989     {
8990 	if (p_titlelen < 0)
8991 	{
8992 	    errmsg = e_positive;
8993 	    p_titlelen = 85;
8994 	}
8995 	if (starting != NO_SCREEN && old_value != p_titlelen)
8996 	    need_maketitle = TRUE;
8997     }
8998 #endif
8999 
9000     /* if p_ch changed value, change the command line height */
9001     else if (pp == &p_ch)
9002     {
9003 	if (p_ch < 1)
9004 	{
9005 	    errmsg = e_positive;
9006 	    p_ch = 1;
9007 	}
9008 	if (p_ch > Rows - min_rows() + 1)
9009 	    p_ch = Rows - min_rows() + 1;
9010 
9011 	/* Only compute the new window layout when startup has been
9012 	 * completed. Otherwise the frame sizes may be wrong. */
9013 	if (p_ch != old_value && full_screen
9014 #ifdef FEAT_GUI
9015 		&& !gui.starting
9016 #endif
9017 	   )
9018 	    command_height();
9019     }
9020 
9021     /* when 'updatecount' changes from zero to non-zero, open swap files */
9022     else if (pp == &p_uc)
9023     {
9024 	if (p_uc < 0)
9025 	{
9026 	    errmsg = e_positive;
9027 	    p_uc = 100;
9028 	}
9029 	if (p_uc && !old_value)
9030 	    ml_open_files();
9031     }
9032 #ifdef FEAT_CONCEAL
9033     else if (pp == &curwin->w_p_cole)
9034     {
9035 	if (curwin->w_p_cole < 0)
9036 	{
9037 	    errmsg = e_positive;
9038 	    curwin->w_p_cole = 0;
9039 	}
9040 	else if (curwin->w_p_cole > 3)
9041 	{
9042 	    errmsg = e_invarg;
9043 	    curwin->w_p_cole = 3;
9044 	}
9045     }
9046 #endif
9047 #ifdef MZSCHEME_GUI_THREADS
9048     else if (pp == &p_mzq)
9049 	mzvim_reset_timer();
9050 #endif
9051 
9052 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9053     /* 'pyxversion' */
9054     else if (pp == &p_pyx)
9055     {
9056 	if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9057 	    errmsg = e_invarg;
9058     }
9059 #endif
9060 
9061     /* sync undo before 'undolevels' changes */
9062     else if (pp == &p_ul)
9063     {
9064 	/* use the old value, otherwise u_sync() may not work properly */
9065 	p_ul = old_value;
9066 	u_sync(TRUE);
9067 	p_ul = value;
9068     }
9069     else if (pp == &curbuf->b_p_ul)
9070     {
9071 	/* use the old value, otherwise u_sync() may not work properly */
9072 	curbuf->b_p_ul = old_value;
9073 	u_sync(TRUE);
9074 	curbuf->b_p_ul = value;
9075     }
9076 
9077 #ifdef FEAT_LINEBREAK
9078     /* 'numberwidth' must be positive */
9079     else if (pp == &curwin->w_p_nuw)
9080     {
9081 	if (curwin->w_p_nuw < 1)
9082 	{
9083 	    errmsg = e_positive;
9084 	    curwin->w_p_nuw = 1;
9085 	}
9086 	if (curwin->w_p_nuw > 10)
9087 	{
9088 	    errmsg = e_invarg;
9089 	    curwin->w_p_nuw = 10;
9090 	}
9091 	curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
9092     }
9093 #endif
9094 
9095     else if (pp == &curbuf->b_p_tw)
9096     {
9097 	if (curbuf->b_p_tw < 0)
9098 	{
9099 	    errmsg = e_positive;
9100 	    curbuf->b_p_tw = 0;
9101 	}
9102 #ifdef FEAT_SYN_HL
9103 # ifdef FEAT_WINDOWS
9104 	{
9105 	    win_T	*wp;
9106 	    tabpage_T	*tp;
9107 
9108 	    FOR_ALL_TAB_WINDOWS(tp, wp)
9109 		check_colorcolumn(wp);
9110 	}
9111 # else
9112 	check_colorcolumn(curwin);
9113 # endif
9114 #endif
9115     }
9116 
9117     /*
9118      * Check the bounds for numeric options here
9119      */
9120     if (Rows < min_rows() && full_screen)
9121     {
9122 	if (errbuf != NULL)
9123 	{
9124 	    vim_snprintf((char *)errbuf, errbuflen,
9125 			       _("E593: Need at least %d lines"), min_rows());
9126 	    errmsg = errbuf;
9127 	}
9128 	Rows = min_rows();
9129     }
9130     if (Columns < MIN_COLUMNS && full_screen)
9131     {
9132 	if (errbuf != NULL)
9133 	{
9134 	    vim_snprintf((char *)errbuf, errbuflen,
9135 			    _("E594: Need at least %d columns"), MIN_COLUMNS);
9136 	    errmsg = errbuf;
9137 	}
9138 	Columns = MIN_COLUMNS;
9139     }
9140     limit_screen_size();
9141 
9142     /*
9143      * If the screen (shell) height has been changed, assume it is the
9144      * physical screenheight.
9145      */
9146     if (old_Rows != Rows || old_Columns != Columns)
9147     {
9148 	/* Changing the screen size is not allowed while updating the screen. */
9149 	if (updating_screen)
9150 	    *pp = old_value;
9151 	else if (full_screen
9152 #ifdef FEAT_GUI
9153 		&& !gui.starting
9154 #endif
9155 	    )
9156 	    set_shellsize((int)Columns, (int)Rows, TRUE);
9157 	else
9158 	{
9159 	    /* Postpone the resizing; check the size and cmdline position for
9160 	     * messages. */
9161 	    check_shellsize();
9162 	    if (cmdline_row > Rows - p_ch && Rows > p_ch)
9163 		cmdline_row = Rows - p_ch;
9164 	}
9165 	if (p_window >= Rows || !option_was_set((char_u *)"window"))
9166 	    p_window = Rows - 1;
9167     }
9168 
9169     if (curbuf->b_p_ts <= 0)
9170     {
9171 	errmsg = e_positive;
9172 	curbuf->b_p_ts = 8;
9173     }
9174     if (p_tm < 0)
9175     {
9176 	errmsg = e_positive;
9177 	p_tm = 0;
9178     }
9179     if ((curwin->w_p_scr <= 0
9180 		|| (curwin->w_p_scr > curwin->w_height
9181 		    && curwin->w_height > 0))
9182 	    && full_screen)
9183     {
9184 	if (pp == &(curwin->w_p_scr))
9185 	{
9186 	    if (curwin->w_p_scr != 0)
9187 		errmsg = e_scroll;
9188 	    win_comp_scroll(curwin);
9189 	}
9190 	/* If 'scroll' became invalid because of a side effect silently adjust
9191 	 * it. */
9192 	else if (curwin->w_p_scr <= 0)
9193 	    curwin->w_p_scr = 1;
9194 	else /* curwin->w_p_scr > curwin->w_height */
9195 	    curwin->w_p_scr = curwin->w_height;
9196     }
9197     if (p_hi < 0)
9198     {
9199 	errmsg = e_positive;
9200 	p_hi = 0;
9201     }
9202     else if (p_hi > 10000)
9203     {
9204 	errmsg = e_invarg;
9205 	p_hi = 10000;
9206     }
9207     if (p_re < 0 || p_re > 2)
9208     {
9209 	errmsg = e_invarg;
9210 	p_re = 0;
9211     }
9212     if (p_report < 0)
9213     {
9214 	errmsg = e_positive;
9215 	p_report = 1;
9216     }
9217     if ((p_sj < -100 || p_sj >= Rows) && full_screen)
9218     {
9219 	if (Rows != old_Rows)	/* Rows changed, just adjust p_sj */
9220 	    p_sj = Rows / 2;
9221 	else
9222 	{
9223 	    errmsg = e_scroll;
9224 	    p_sj = 1;
9225 	}
9226     }
9227     if (p_so < 0 && full_screen)
9228     {
9229 	errmsg = e_scroll;
9230 	p_so = 0;
9231     }
9232     if (p_siso < 0 && full_screen)
9233     {
9234 	errmsg = e_positive;
9235 	p_siso = 0;
9236     }
9237 #ifdef FEAT_CMDWIN
9238     if (p_cwh < 1)
9239     {
9240 	errmsg = e_positive;
9241 	p_cwh = 1;
9242     }
9243 #endif
9244     if (p_ut < 0)
9245     {
9246 	errmsg = e_positive;
9247 	p_ut = 2000;
9248     }
9249     if (p_ss < 0)
9250     {
9251 	errmsg = e_positive;
9252 	p_ss = 0;
9253     }
9254 
9255     /* May set global value for local option. */
9256     if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9257 	*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9258 
9259     options[opt_idx].flags |= P_WAS_SET;
9260 
9261 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9262     if (!starting && errmsg == NULL)
9263     {
9264 	char_u buf_old[11], buf_new[11], buf_type[7];
9265 	vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9266 	vim_snprintf((char *)buf_new, 10, "%ld", value);
9267 	vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
9268 	set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9269 	set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9270 	set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9271 	apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9272 	reset_v_option_vars();
9273     }
9274 #endif
9275 
9276     comp_col();			    /* in case 'columns' or 'ls' changed */
9277     if (curwin->w_curswant != MAXCOL
9278 		     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
9279 	curwin->w_set_curswant = TRUE;
9280     check_redraw(options[opt_idx].flags);
9281 
9282     return errmsg;
9283 }
9284 
9285 /*
9286  * Called after an option changed: check if something needs to be redrawn.
9287  */
9288     static void
9289 check_redraw(long_u flags)
9290 {
9291     /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
9292     int		doclear = (flags & P_RCLR) == P_RCLR;
9293     int		all = ((flags & P_RALL) == P_RALL || doclear);
9294 
9295 #ifdef FEAT_WINDOWS
9296     if ((flags & P_RSTAT) || all)	/* mark all status lines dirty */
9297 	status_redraw_all();
9298 #endif
9299 
9300     if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9301 	changed_window_setting();
9302     if (flags & P_RBUF)
9303 	redraw_curbuf_later(NOT_VALID);
9304     if (flags & P_RWINONLY)
9305 	redraw_later(NOT_VALID);
9306     if (doclear)
9307 	redraw_all_later(CLEAR);
9308     else if (all)
9309 	redraw_all_later(NOT_VALID);
9310 }
9311 
9312 /*
9313  * Find index for option 'arg'.
9314  * Return -1 if not found.
9315  */
9316     static int
9317 findoption(char_u *arg)
9318 {
9319     int		    opt_idx;
9320     char	    *s, *p;
9321     static short    quick_tab[27] = {0, 0};	/* quick access table */
9322     int		    is_term_opt;
9323 
9324     /*
9325      * For first call: Initialize the quick-access table.
9326      * It contains the index for the first option that starts with a certain
9327      * letter.  There are 26 letters, plus the first "t_" option.
9328      */
9329     if (quick_tab[1] == 0)
9330     {
9331 	p = options[0].fullname;
9332 	for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9333 	{
9334 	    if (s[0] != p[0])
9335 	    {
9336 		if (s[0] == 't' && s[1] == '_')
9337 		    quick_tab[26] = opt_idx;
9338 		else
9339 		    quick_tab[CharOrdLow(s[0])] = opt_idx;
9340 	    }
9341 	    p = s;
9342 	}
9343     }
9344 
9345     /*
9346      * Check for name starting with an illegal character.
9347      */
9348 #ifdef EBCDIC
9349     if (!islower(arg[0]))
9350 #else
9351     if (arg[0] < 'a' || arg[0] > 'z')
9352 #endif
9353 	return -1;
9354 
9355     is_term_opt = (arg[0] == 't' && arg[1] == '_');
9356     if (is_term_opt)
9357 	opt_idx = quick_tab[26];
9358     else
9359 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9360     for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9361     {
9362 	if (STRCMP(arg, s) == 0)		    /* match full name */
9363 	    break;
9364     }
9365     if (s == NULL && !is_term_opt)
9366     {
9367 	opt_idx = quick_tab[CharOrdLow(arg[0])];
9368 	for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9369 	{
9370 	    s = options[opt_idx].shortname;
9371 	    if (s != NULL && STRCMP(arg, s) == 0)   /* match short name */
9372 		break;
9373 	    s = NULL;
9374 	}
9375     }
9376     if (s == NULL)
9377 	opt_idx = -1;
9378     return opt_idx;
9379 }
9380 
9381 #if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
9382 /*
9383  * Get the value for an option.
9384  *
9385  * Returns:
9386  * Number or Toggle option: 1, *numval gets value.
9387  *	     String option: 0, *stringval gets allocated string.
9388  * Hidden Number or Toggle option: -1.
9389  *	     hidden String option: -2.
9390  *		   unknown option: -3.
9391  */
9392     int
9393 get_option_value(
9394     char_u	*name,
9395     long	*numval,
9396     char_u	**stringval,	    /* NULL when only checking existence */
9397     int		opt_flags)
9398 {
9399     int		opt_idx;
9400     char_u	*varp;
9401 
9402     opt_idx = findoption(name);
9403     if (opt_idx < 0)		    /* unknown option */
9404     {
9405 	int key;
9406 
9407 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9408 		&& (key = find_key_option(name)) != 0)
9409 	{
9410 	    char_u key_name[2];
9411 	    char_u *p;
9412 
9413 	    if (key < 0)
9414 	    {
9415 		key_name[0] = KEY2TERMCAP0(key);
9416 		key_name[1] = KEY2TERMCAP1(key);
9417 	    }
9418 	    else
9419 	    {
9420 		key_name[0] = KS_KEY;
9421 		key_name[1] = (key & 0xff);
9422 	    }
9423 	    p = find_termcode(key_name);
9424 	    if (p != NULL)
9425 	    {
9426 		if (stringval != NULL)
9427 		    *stringval = vim_strsave(p);
9428 		return 0;
9429 	    }
9430 	}
9431 	return -3;
9432     }
9433 
9434     varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9435 
9436     if (options[opt_idx].flags & P_STRING)
9437     {
9438 	if (varp == NULL)		    /* hidden option */
9439 	    return -2;
9440 	if (stringval != NULL)
9441 	{
9442 #ifdef FEAT_CRYPT
9443 	    /* never return the value of the crypt key */
9444 	    if ((char_u **)varp == &curbuf->b_p_key
9445 						&& **(char_u **)(varp) != NUL)
9446 		*stringval = vim_strsave((char_u *)"*****");
9447 	    else
9448 #endif
9449 		*stringval = vim_strsave(*(char_u **)(varp));
9450 	}
9451 	return 0;
9452     }
9453 
9454     if (varp == NULL)		    /* hidden option */
9455 	return -1;
9456     if (options[opt_idx].flags & P_NUM)
9457 	*numval = *(long *)varp;
9458     else
9459     {
9460 	/* Special case: 'modified' is b_changed, but we also want to consider
9461 	 * it set when 'ff' or 'fenc' changed. */
9462 	if ((int *)varp == &curbuf->b_changed)
9463 	    *numval = curbufIsChanged();
9464 	else
9465 	    *numval = (long) *(int *)varp;
9466     }
9467     return 1;
9468 }
9469 #endif
9470 
9471 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9472 /*
9473  * Returns the option attributes and its value. Unlike the above function it
9474  * will return either global value or local value of the option depending on
9475  * what was requested, but it will never return global value if it was
9476  * requested to return local one and vice versa. Neither it will return
9477  * buffer-local value if it was requested to return window-local one.
9478  *
9479  * Pretends that option is absent if it is not present in the requested scope
9480  * (i.e. has no global, window-local or buffer-local value depending on
9481  * opt_type). Uses
9482  *
9483  * Returned flags:
9484  *       0 hidden or unknown option, also option that does not have requested
9485  *	   type (see SREQ_* in vim.h)
9486  *  see SOPT_* in vim.h for other flags
9487  *
9488  * Possible opt_type values: see SREQ_* in vim.h
9489  */
9490     int
9491 get_option_value_strict(
9492     char_u	*name,
9493     long	*numval,
9494     char_u	**stringval,	    /* NULL when only obtaining attributes */
9495     int		opt_type,
9496     void	*from)
9497 {
9498     int		opt_idx;
9499     char_u	*varp = NULL;
9500     struct vimoption *p;
9501     int		r = 0;
9502 
9503     opt_idx = findoption(name);
9504     if (opt_idx < 0)
9505 	return 0;
9506 
9507     p = &(options[opt_idx]);
9508 
9509     /* Hidden option */
9510     if (p->var == NULL)
9511 	return 0;
9512 
9513     if (p->flags & P_BOOL)
9514 	r |= SOPT_BOOL;
9515     else if (p->flags & P_NUM)
9516 	r |= SOPT_NUM;
9517     else if (p->flags & P_STRING)
9518 	r |= SOPT_STRING;
9519 
9520     if (p->indir == PV_NONE)
9521     {
9522 	if (opt_type == SREQ_GLOBAL)
9523 	    r |= SOPT_GLOBAL;
9524 	else
9525 	    return 0; /* Did not request global-only option */
9526     }
9527     else
9528     {
9529 	if (p->indir & PV_BOTH)
9530 	    r |= SOPT_GLOBAL;
9531 	else if (opt_type == SREQ_GLOBAL)
9532 	    return 0; /* Requested global option */
9533 
9534 	if (p->indir & PV_WIN)
9535 	{
9536 	    if (opt_type == SREQ_BUF)
9537 		return 0; /* Did not request window-local option */
9538 	    else
9539 		r |= SOPT_WIN;
9540 	}
9541 	else if (p->indir & PV_BUF)
9542 	{
9543 	    if (opt_type == SREQ_WIN)
9544 		return 0; /* Did not request buffer-local option */
9545 	    else
9546 		r |= SOPT_BUF;
9547 	}
9548     }
9549 
9550     if (stringval == NULL)
9551 	return r;
9552 
9553     if (opt_type == SREQ_GLOBAL)
9554 	varp = p->var;
9555     else
9556     {
9557 	if (opt_type == SREQ_BUF)
9558 	{
9559 	    /* Special case: 'modified' is b_changed, but we also want to
9560 	     * consider it set when 'ff' or 'fenc' changed. */
9561 	    if (p->indir == PV_MOD)
9562 	    {
9563 		*numval = bufIsChanged((buf_T *) from);
9564 		varp = NULL;
9565 	    }
9566 #ifdef FEAT_CRYPT
9567 	    else if (p->indir == PV_KEY)
9568 	    {
9569 		/* never return the value of the crypt key */
9570 		*stringval = NULL;
9571 		varp = NULL;
9572 	    }
9573 #endif
9574 	    else
9575 	    {
9576 		aco_save_T	aco;
9577 		aucmd_prepbuf(&aco, (buf_T *) from);
9578 		varp = get_varp(p);
9579 		aucmd_restbuf(&aco);
9580 	    }
9581 	}
9582 	else if (opt_type == SREQ_WIN)
9583 	{
9584 	    win_T	*save_curwin;
9585 	    save_curwin = curwin;
9586 	    curwin = (win_T *) from;
9587 	    curbuf = curwin->w_buffer;
9588 	    varp = get_varp(p);
9589 	    curwin = save_curwin;
9590 	    curbuf = curwin->w_buffer;
9591 	}
9592 	if (varp == p->var)
9593 	    return (r | SOPT_UNSET);
9594     }
9595 
9596     if (varp != NULL)
9597     {
9598 	if (p->flags & P_STRING)
9599 	    *stringval = vim_strsave(*(char_u **)(varp));
9600 	else if (p->flags & P_NUM)
9601 	    *numval = *(long *) varp;
9602 	else
9603 	    *numval = *(int *)varp;
9604     }
9605 
9606     return r;
9607 }
9608 
9609 /*
9610  * Iterate over options. First argument is a pointer to a pointer to a
9611  * structure inside options[] array, second is option type like in the above
9612  * function.
9613  *
9614  * If first argument points to NULL it is assumed that iteration just started
9615  * and caller needs the very first value.
9616  * If first argument points to the end marker function returns NULL and sets
9617  * first argument to NULL.
9618  *
9619  * Returns full option name for current option on each call.
9620  */
9621     char_u *
9622 option_iter_next(void **option, int opt_type)
9623 {
9624     struct vimoption	*ret = NULL;
9625     do
9626     {
9627 	if (*option == NULL)
9628 	    *option = (void *) options;
9629 	else if (((struct vimoption *) (*option))->fullname == NULL)
9630 	{
9631 	    *option = NULL;
9632 	    return NULL;
9633 	}
9634 	else
9635 	    *option = (void *) (((struct vimoption *) (*option)) + 1);
9636 
9637 	ret = ((struct vimoption *) (*option));
9638 
9639 	/* Hidden option */
9640 	if (ret->var == NULL)
9641 	{
9642 	    ret = NULL;
9643 	    continue;
9644 	}
9645 
9646 	switch (opt_type)
9647 	{
9648 	    case SREQ_GLOBAL:
9649 		if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9650 		    ret = NULL;
9651 		break;
9652 	    case SREQ_BUF:
9653 		if (!(ret->indir & PV_BUF))
9654 		    ret = NULL;
9655 		break;
9656 	    case SREQ_WIN:
9657 		if (!(ret->indir & PV_WIN))
9658 		    ret = NULL;
9659 		break;
9660 	    default:
9661 		internal_error("option_iter_next()");
9662 		return NULL;
9663 	}
9664     }
9665     while (ret == NULL);
9666 
9667     return (char_u *)ret->fullname;
9668 }
9669 #endif
9670 
9671 /*
9672  * Set the value of option "name".
9673  * Use "string" for string options, use "number" for other options.
9674  *
9675  * Returns NULL on success or error message on error.
9676  */
9677     char_u *
9678 set_option_value(
9679     char_u	*name,
9680     long	number,
9681     char_u	*string,
9682     int		opt_flags)	/* OPT_LOCAL or 0 (both) */
9683 {
9684     int		opt_idx;
9685     char_u	*varp;
9686     long_u	flags;
9687 
9688     opt_idx = findoption(name);
9689     if (opt_idx < 0)
9690     {
9691 	int key;
9692 
9693 	if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9694 		&& (key = find_key_option(name)) != 0)
9695 	{
9696 	    char_u key_name[2];
9697 
9698 	    if (key < 0)
9699 	    {
9700 		key_name[0] = KEY2TERMCAP0(key);
9701 		key_name[1] = KEY2TERMCAP1(key);
9702 	    }
9703 	    else
9704 	    {
9705 		key_name[0] = KS_KEY;
9706 		key_name[1] = (key & 0xff);
9707 	    }
9708 	    add_termcode(key_name, string, FALSE);
9709 	    if (full_screen)
9710 		ttest(FALSE);
9711 	    redraw_all_later(CLEAR);
9712 	    return NULL;
9713 	}
9714 
9715 	EMSG2(_("E355: Unknown option: %s"), name);
9716     }
9717     else
9718     {
9719 	flags = options[opt_idx].flags;
9720 #ifdef HAVE_SANDBOX
9721 	/* Disallow changing some options in the sandbox */
9722 	if (sandbox > 0 && (flags & P_SECURE))
9723 	{
9724 	    EMSG(_(e_sandbox));
9725 	    return NULL;
9726 	}
9727 #endif
9728 	if (flags & P_STRING)
9729 	    return set_string_option(opt_idx, string, opt_flags);
9730 	else
9731 	{
9732 	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9733 	    if (varp != NULL)	/* hidden option is not changed */
9734 	    {
9735 		if (number == 0 && string != NULL)
9736 		{
9737 		    int idx;
9738 
9739 		    /* Either we are given a string or we are setting option
9740 		     * to zero. */
9741 		    for (idx = 0; string[idx] == '0'; ++idx)
9742 			;
9743 		    if (string[idx] != NUL || idx == 0)
9744 		    {
9745 			/* There's another character after zeros or the string
9746 			 * is empty.  In both cases, we are trying to set a
9747 			 * num option using a string. */
9748 			EMSG3(_("E521: Number required: &%s = '%s'"),
9749 								name, string);
9750 			return NULL;     /* do nothing as we hit an error */
9751 
9752 		    }
9753 		}
9754 		if (flags & P_NUM)
9755 		    return set_num_option(opt_idx, varp, number,
9756 							  NULL, 0, opt_flags);
9757 		else
9758 		    return set_bool_option(opt_idx, varp, (int)number,
9759 								   opt_flags);
9760 	    }
9761 	}
9762     }
9763     return NULL;
9764 }
9765 
9766 /*
9767  * Get the terminal code for a terminal option.
9768  * Returns NULL when not found.
9769  */
9770     char_u *
9771 get_term_code(char_u *tname)
9772 {
9773     int	    opt_idx;
9774     char_u  *varp;
9775 
9776     if (tname[0] != 't' || tname[1] != '_' ||
9777 	    tname[2] == NUL || tname[3] == NUL)
9778 	return NULL;
9779     if ((opt_idx = findoption(tname)) >= 0)
9780     {
9781 	varp = get_varp(&(options[opt_idx]));
9782 	if (varp != NULL)
9783 	    varp = *(char_u **)(varp);
9784 	return varp;
9785     }
9786     return find_termcode(tname + 2);
9787 }
9788 
9789     char_u *
9790 get_highlight_default(void)
9791 {
9792     int i;
9793 
9794     i = findoption((char_u *)"hl");
9795     if (i >= 0)
9796 	return options[i].def_val[VI_DEFAULT];
9797     return (char_u *)NULL;
9798 }
9799 
9800 #if defined(FEAT_MBYTE) || defined(PROTO)
9801     char_u *
9802 get_encoding_default(void)
9803 {
9804     int i;
9805 
9806     i = findoption((char_u *)"enc");
9807     if (i >= 0)
9808 	return options[i].def_val[VI_DEFAULT];
9809     return (char_u *)NULL;
9810 }
9811 #endif
9812 
9813 /*
9814  * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9815  */
9816     static int
9817 find_key_option(char_u *arg)
9818 {
9819     int		key;
9820     int		modifiers;
9821 
9822     /*
9823      * Don't use get_special_key_code() for t_xx, we don't want it to call
9824      * add_termcap_entry().
9825      */
9826     if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9827 	key = TERMCAP2KEY(arg[2], arg[3]);
9828     else
9829     {
9830 	--arg;			    /* put arg at the '<' */
9831 	modifiers = 0;
9832 	key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
9833 	if (modifiers)		    /* can't handle modifiers here */
9834 	    key = 0;
9835     }
9836     return key;
9837 }
9838 
9839 /*
9840  * if 'all' == 0: show changed options
9841  * if 'all' == 1: show all normal options
9842  * if 'all' == 2: show all terminal options
9843  */
9844     static void
9845 showoptions(
9846     int		all,
9847     int		opt_flags)	/* OPT_LOCAL and/or OPT_GLOBAL */
9848 {
9849     struct vimoption	*p;
9850     int			col;
9851     int			isterm;
9852     char_u		*varp;
9853     struct vimoption	**items;
9854     int			item_count;
9855     int			run;
9856     int			row, rows;
9857     int			cols;
9858     int			i;
9859     int			len;
9860 
9861 #define INC 20
9862 #define GAP 3
9863 
9864     items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9865 								PARAM_COUNT));
9866     if (items == NULL)
9867 	return;
9868 
9869     /* Highlight title */
9870     if (all == 2)
9871 	MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9872     else if (opt_flags & OPT_GLOBAL)
9873 	MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9874     else if (opt_flags & OPT_LOCAL)
9875 	MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9876     else
9877 	MSG_PUTS_TITLE(_("\n--- Options ---"));
9878 
9879     /*
9880      * do the loop two times:
9881      * 1. display the short items
9882      * 2. display the long items (only strings and numbers)
9883      */
9884     for (run = 1; run <= 2 && !got_int; ++run)
9885     {
9886 	/*
9887 	 * collect the items in items[]
9888 	 */
9889 	item_count = 0;
9890 	for (p = &options[0]; p->fullname != NULL; p++)
9891 	{
9892 	    varp = NULL;
9893 	    isterm = istermoption(p);
9894 	    if (opt_flags != 0)
9895 	    {
9896 		if (p->indir != PV_NONE && !isterm)
9897 		    varp = get_varp_scope(p, opt_flags);
9898 	    }
9899 	    else
9900 		varp = get_varp(p);
9901 	    if (varp != NULL
9902 		    && ((all == 2 && isterm)
9903 			|| (all == 1 && !isterm)
9904 			|| (all == 0 && !optval_default(p, varp))))
9905 	    {
9906 		if (p->flags & P_BOOL)
9907 		    len = 1;		/* a toggle option fits always */
9908 		else
9909 		{
9910 		    option_value2string(p, opt_flags);
9911 		    len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9912 		}
9913 		if ((len <= INC - GAP && run == 1) ||
9914 						(len > INC - GAP && run == 2))
9915 		    items[item_count++] = p;
9916 	    }
9917 	}
9918 
9919 	/*
9920 	 * display the items
9921 	 */
9922 	if (run == 1)
9923 	{
9924 	    cols = (Columns + GAP - 3) / INC;
9925 	    if (cols == 0)
9926 		cols = 1;
9927 	    rows = (item_count + cols - 1) / cols;
9928 	}
9929 	else	/* run == 2 */
9930 	    rows = item_count;
9931 	for (row = 0; row < rows && !got_int; ++row)
9932 	{
9933 	    msg_putchar('\n');			/* go to next line */
9934 	    if (got_int)			/* 'q' typed in more */
9935 		break;
9936 	    col = 0;
9937 	    for (i = row; i < item_count; i += rows)
9938 	    {
9939 		msg_col = col;			/* make columns */
9940 		showoneopt(items[i], opt_flags);
9941 		col += INC;
9942 	    }
9943 	    out_flush();
9944 	    ui_breakcheck();
9945 	}
9946     }
9947     vim_free(items);
9948 }
9949 
9950 /*
9951  * Return TRUE if option "p" has its default value.
9952  */
9953     static int
9954 optval_default(struct vimoption *p, char_u *varp)
9955 {
9956     int		dvi;
9957 
9958     if (varp == NULL)
9959 	return TRUE;	    /* hidden option is always at default */
9960     dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9961     if (p->flags & P_NUM)
9962 	return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
9963     if (p->flags & P_BOOL)
9964 			/* the cast to long is required for Manx C, long_i is
9965 			 * needed for MSVC */
9966 	return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
9967     /* P_STRING */
9968     return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9969 }
9970 
9971 /*
9972  * showoneopt: show the value of one option
9973  * must not be called with a hidden option!
9974  */
9975     static void
9976 showoneopt(
9977     struct vimoption	*p,
9978     int			opt_flags)	/* OPT_LOCAL or OPT_GLOBAL */
9979 {
9980     char_u	*varp;
9981     int		save_silent = silent_mode;
9982 
9983     silent_mode = FALSE;
9984     info_message = TRUE;	/* use mch_msg(), not mch_errmsg() */
9985 
9986     varp = get_varp_scope(p, opt_flags);
9987 
9988     /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9989     if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9990 					? !curbufIsChanged() : !*(int *)varp))
9991 	MSG_PUTS("no");
9992     else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9993 	MSG_PUTS("--");
9994     else
9995 	MSG_PUTS("  ");
9996     MSG_PUTS(p->fullname);
9997     if (!(p->flags & P_BOOL))
9998     {
9999 	msg_putchar('=');
10000 	/* put value string in NameBuff */
10001 	option_value2string(p, opt_flags);
10002 	msg_outtrans(NameBuff);
10003     }
10004 
10005     silent_mode = save_silent;
10006     info_message = FALSE;
10007 }
10008 
10009 /*
10010  * Write modified options as ":set" commands to a file.
10011  *
10012  * There are three values for "opt_flags":
10013  * OPT_GLOBAL:		   Write global option values and fresh values of
10014  *			   buffer-local options (used for start of a session
10015  *			   file).
10016  * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10017  *			   curwin (used for a vimrc file).
10018  * OPT_LOCAL:		   Write buffer-local option values for curbuf, fresh
10019  *			   and local values for window-local options of
10020  *			   curwin.  Local values are also written when at the
10021  *			   default value, because a modeline or autocommand
10022  *			   may have set them when doing ":edit file" and the
10023  *			   user has set them back at the default or fresh
10024  *			   value.
10025  *			   When "local_only" is TRUE, don't write fresh
10026  *			   values, only local values (for ":mkview").
10027  * (fresh value = value used for a new buffer or window for a local option).
10028  *
10029  * Return FAIL on error, OK otherwise.
10030  */
10031     int
10032 makeset(FILE *fd, int opt_flags, int local_only)
10033 {
10034     struct vimoption	*p;
10035     char_u		*varp;			/* currently used value */
10036     char_u		*varp_fresh;		/* local value */
10037     char_u		*varp_local = NULL;	/* fresh value */
10038     char		*cmd;
10039     int			round;
10040     int			pri;
10041 
10042     /*
10043      * The options that don't have a default (terminal name, columns, lines)
10044      * are never written.  Terminal options are also not written.
10045      * Do the loop over "options[]" twice: once for options with the
10046      * P_PRI_MKRC flag and once without.
10047      */
10048     for (pri = 1; pri >= 0; --pri)
10049     {
10050       for (p = &options[0]; !istermoption(p); p++)
10051 	if (!(p->flags & P_NO_MKRC)
10052 		&& !istermoption(p)
10053 		&& ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
10054 	{
10055 	    /* skip global option when only doing locals */
10056 	    if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10057 		continue;
10058 
10059 	    /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10060 	     * file, they are always buffer-specific. */
10061 	    if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10062 		continue;
10063 
10064 	    /* Global values are only written when not at the default value. */
10065 	    varp = get_varp_scope(p, opt_flags);
10066 	    if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10067 		continue;
10068 
10069 	    round = 2;
10070 	    if (p->indir != PV_NONE)
10071 	    {
10072 		if (p->var == VAR_WIN)
10073 		{
10074 		    /* skip window-local option when only doing globals */
10075 		    if (!(opt_flags & OPT_LOCAL))
10076 			continue;
10077 		    /* When fresh value of window-local option is not at the
10078 		     * default, need to write it too. */
10079 		    if (!(opt_flags & OPT_GLOBAL) && !local_only)
10080 		    {
10081 			varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10082 			if (!optval_default(p, varp_fresh))
10083 			{
10084 			    round = 1;
10085 			    varp_local = varp;
10086 			    varp = varp_fresh;
10087 			}
10088 		    }
10089 		}
10090 	    }
10091 
10092 	    /* Round 1: fresh value for window-local options.
10093 	     * Round 2: other values */
10094 	    for ( ; round <= 2; varp = varp_local, ++round)
10095 	    {
10096 		if (round == 1 || (opt_flags & OPT_GLOBAL))
10097 		    cmd = "set";
10098 		else
10099 		    cmd = "setlocal";
10100 
10101 		if (p->flags & P_BOOL)
10102 		{
10103 		    if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10104 			return FAIL;
10105 		}
10106 		else if (p->flags & P_NUM)
10107 		{
10108 		    if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10109 			return FAIL;
10110 		}
10111 		else    /* P_STRING */
10112 		{
10113 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10114 		    int		do_endif = FALSE;
10115 
10116 		    /* Don't set 'syntax' and 'filetype' again if the value is
10117 		     * already right, avoids reloading the syntax file. */
10118 		    if (
10119 # if defined(FEAT_SYN_HL)
10120 			    p->indir == PV_SYN
10121 #  if defined(FEAT_AUTOCMD)
10122 			    ||
10123 #  endif
10124 # endif
10125 # if defined(FEAT_AUTOCMD)
10126 			    p->indir == PV_FT
10127 # endif
10128 			    )
10129 		    {
10130 			if (fprintf(fd, "if &%s != '%s'", p->fullname,
10131 						       *(char_u **)(varp)) < 0
10132 				|| put_eol(fd) < 0)
10133 			    return FAIL;
10134 			do_endif = TRUE;
10135 		    }
10136 #endif
10137 		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10138 					  (p->flags & P_EXPAND) != 0) == FAIL)
10139 			return FAIL;
10140 #if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10141 		    if (do_endif)
10142 		    {
10143 			if (put_line(fd, "endif") == FAIL)
10144 			    return FAIL;
10145 		    }
10146 #endif
10147 		}
10148 	    }
10149 	}
10150     }
10151     return OK;
10152 }
10153 
10154 #if defined(FEAT_FOLDING) || defined(PROTO)
10155 /*
10156  * Generate set commands for the local fold options only.  Used when
10157  * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10158  */
10159     int
10160 makefoldset(FILE *fd)
10161 {
10162     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10163 # ifdef FEAT_EVAL
10164 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10165 								       == FAIL
10166 # endif
10167 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10168 								       == FAIL
10169 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10170 								       == FAIL
10171 	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10172 	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10173 	    || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10174 	    || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10175 	    )
10176 	return FAIL;
10177 
10178     return OK;
10179 }
10180 #endif
10181 
10182     static int
10183 put_setstring(
10184     FILE	*fd,
10185     char	*cmd,
10186     char	*name,
10187     char_u	**valuep,
10188     int		expand)
10189 {
10190     char_u	*s;
10191     char_u	*buf;
10192 
10193     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10194 	return FAIL;
10195     if (*valuep != NULL)
10196     {
10197 	/* Output 'pastetoggle' as key names.  For other
10198 	 * options some characters have to be escaped with
10199 	 * CTRL-V or backslash */
10200 	if (valuep == &p_pt)
10201 	{
10202 	    s = *valuep;
10203 	    while (*s != NUL)
10204 		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
10205 		    return FAIL;
10206 	}
10207 	else if (expand)
10208 	{
10209 	    buf = alloc(MAXPATHL);
10210 	    if (buf == NULL)
10211 		return FAIL;
10212 	    home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10213 	    if (put_escstr(fd, buf, 2) == FAIL)
10214 	    {
10215 		vim_free(buf);
10216 		return FAIL;
10217 	    }
10218 	    vim_free(buf);
10219 	}
10220 	else if (put_escstr(fd, *valuep, 2) == FAIL)
10221 	    return FAIL;
10222     }
10223     if (put_eol(fd) < 0)
10224 	return FAIL;
10225     return OK;
10226 }
10227 
10228     static int
10229 put_setnum(
10230     FILE	*fd,
10231     char	*cmd,
10232     char	*name,
10233     long	*valuep)
10234 {
10235     long	wc;
10236 
10237     if (fprintf(fd, "%s %s=", cmd, name) < 0)
10238 	return FAIL;
10239     if (wc_use_keyname((char_u *)valuep, &wc))
10240     {
10241 	/* print 'wildchar' and 'wildcharm' as a key name */
10242 	if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10243 	    return FAIL;
10244     }
10245     else if (fprintf(fd, "%ld", *valuep) < 0)
10246 	return FAIL;
10247     if (put_eol(fd) < 0)
10248 	return FAIL;
10249     return OK;
10250 }
10251 
10252     static int
10253 put_setbool(
10254     FILE	*fd,
10255     char	*cmd,
10256     char	*name,
10257     int		value)
10258 {
10259     if (value < 0)	/* global/local option using global value */
10260 	return OK;
10261     if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10262 	    || put_eol(fd) < 0)
10263 	return FAIL;
10264     return OK;
10265 }
10266 
10267 /*
10268  * Clear all the terminal options.
10269  * If the option has been allocated, free the memory.
10270  * Terminal options are never hidden or indirect.
10271  */
10272     void
10273 clear_termoptions(void)
10274 {
10275     /*
10276      * Reset a few things before clearing the old options. This may cause
10277      * outputting a few things that the terminal doesn't understand, but the
10278      * screen will be cleared later, so this is OK.
10279      */
10280 #ifdef FEAT_MOUSE_TTY
10281     mch_setmouse(FALSE);	    /* switch mouse off */
10282 #endif
10283 #ifdef FEAT_TITLE
10284     mch_restore_title(3);	    /* restore window titles */
10285 #endif
10286 #if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10287     /* When starting the GUI close the display opened for the clipboard.
10288      * After restoring the title, because that will need the display. */
10289     if (gui.starting)
10290 	clear_xterm_clip();
10291 #endif
10292     stoptermcap();			/* stop termcap mode */
10293 
10294     free_termoptions();
10295 }
10296 
10297     void
10298 free_termoptions(void)
10299 {
10300     struct vimoption   *p;
10301 
10302     for (p = &options[0]; p->fullname != NULL; p++)
10303 	if (istermoption(p))
10304 	{
10305 	    if (p->flags & P_ALLOCED)
10306 		free_string_option(*(char_u **)(p->var));
10307 	    if (p->flags & P_DEF_ALLOCED)
10308 		free_string_option(p->def_val[VI_DEFAULT]);
10309 	    *(char_u **)(p->var) = empty_option;
10310 	    p->def_val[VI_DEFAULT] = empty_option;
10311 	    p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10312 	}
10313     clear_termcodes();
10314 }
10315 
10316 /*
10317  * Free the string for one term option, if it was allocated.
10318  * Set the string to empty_option and clear allocated flag.
10319  * "var" points to the option value.
10320  */
10321     void
10322 free_one_termoption(char_u *var)
10323 {
10324     struct vimoption   *p;
10325 
10326     for (p = &options[0]; p->fullname != NULL; p++)
10327 	if (p->var == var)
10328 	{
10329 	    if (p->flags & P_ALLOCED)
10330 		free_string_option(*(char_u **)(p->var));
10331 	    *(char_u **)(p->var) = empty_option;
10332 	    p->flags &= ~P_ALLOCED;
10333 	    break;
10334 	}
10335 }
10336 
10337 /*
10338  * Set the terminal option defaults to the current value.
10339  * Used after setting the terminal name.
10340  */
10341     void
10342 set_term_defaults(void)
10343 {
10344     struct vimoption   *p;
10345 
10346     for (p = &options[0]; p->fullname != NULL; p++)
10347     {
10348 	if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10349 	{
10350 	    if (p->flags & P_DEF_ALLOCED)
10351 	    {
10352 		free_string_option(p->def_val[VI_DEFAULT]);
10353 		p->flags &= ~P_DEF_ALLOCED;
10354 	    }
10355 	    p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10356 	    if (p->flags & P_ALLOCED)
10357 	    {
10358 		p->flags |= P_DEF_ALLOCED;
10359 		p->flags &= ~P_ALLOCED;	 /* don't free the value now */
10360 	    }
10361 	}
10362     }
10363 }
10364 
10365 /*
10366  * return TRUE if 'p' starts with 't_'
10367  */
10368     static int
10369 istermoption(struct vimoption *p)
10370 {
10371     return (p->fullname[0] == 't' && p->fullname[1] == '_');
10372 }
10373 
10374 /*
10375  * Compute columns for ruler and shown command. 'sc_col' is also used to
10376  * decide what the maximum length of a message on the status line can be.
10377  * If there is a status line for the last window, 'sc_col' is independent
10378  * of 'ru_col'.
10379  */
10380 
10381 #define COL_RULER 17	    /* columns needed by standard ruler */
10382 
10383     void
10384 comp_col(void)
10385 {
10386 #if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10387     int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
10388 
10389     sc_col = 0;
10390     ru_col = 0;
10391     if (p_ru)
10392     {
10393 #ifdef FEAT_STL_OPT
10394 	ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10395 #else
10396 	ru_col = COL_RULER + 1;
10397 #endif
10398 	/* no last status line, adjust sc_col */
10399 	if (!last_has_status)
10400 	    sc_col = ru_col;
10401     }
10402     if (p_sc)
10403     {
10404 	sc_col += SHOWCMD_COLS;
10405 	if (!p_ru || last_has_status)	    /* no need for separating space */
10406 	    ++sc_col;
10407     }
10408     sc_col = Columns - sc_col;
10409     ru_col = Columns - ru_col;
10410     if (sc_col <= 0)		/* screen too narrow, will become a mess */
10411 	sc_col = 1;
10412     if (ru_col <= 0)
10413 	ru_col = 1;
10414 #else
10415     sc_col = Columns;
10416     ru_col = Columns;
10417 #endif
10418 }
10419 
10420 /*
10421  * Unset local option value, similar to ":set opt<".
10422  */
10423     void
10424 unset_global_local_option(char_u *name, void *from)
10425 {
10426     struct vimoption *p;
10427     int		opt_idx;
10428     buf_T	*buf = (buf_T *)from;
10429 
10430     opt_idx = findoption(name);
10431     if (opt_idx < 0)
10432 	return;
10433     p = &(options[opt_idx]);
10434 
10435     switch ((int)p->indir)
10436     {
10437 	/* global option with local value: use local value if it's been set */
10438 	case PV_EP:
10439 	    clear_string_option(&buf->b_p_ep);
10440 	    break;
10441 	case PV_KP:
10442 	    clear_string_option(&buf->b_p_kp);
10443 	    break;
10444 	case PV_PATH:
10445 	    clear_string_option(&buf->b_p_path);
10446 	    break;
10447 	case PV_AR:
10448 	    buf->b_p_ar = -1;
10449 	    break;
10450 	case PV_BKC:
10451 	    clear_string_option(&buf->b_p_bkc);
10452 	    buf->b_bkc_flags = 0;
10453 	    break;
10454 	case PV_TAGS:
10455 	    clear_string_option(&buf->b_p_tags);
10456 	    break;
10457 	case PV_TC:
10458 	    clear_string_option(&buf->b_p_tc);
10459 	    buf->b_tc_flags = 0;
10460 	    break;
10461 #ifdef FEAT_FIND_ID
10462 	case PV_DEF:
10463 	    clear_string_option(&buf->b_p_def);
10464 	    break;
10465 	case PV_INC:
10466 	    clear_string_option(&buf->b_p_inc);
10467 	    break;
10468 #endif
10469 #ifdef FEAT_INS_EXPAND
10470 	case PV_DICT:
10471 	    clear_string_option(&buf->b_p_dict);
10472 	    break;
10473 	case PV_TSR:
10474 	    clear_string_option(&buf->b_p_tsr);
10475 	    break;
10476 #endif
10477 	case PV_FP:
10478 	    clear_string_option(&buf->b_p_fp);
10479 	    break;
10480 #ifdef FEAT_QUICKFIX
10481 	case PV_EFM:
10482 	    clear_string_option(&buf->b_p_efm);
10483 	    break;
10484 	case PV_GP:
10485 	    clear_string_option(&buf->b_p_gp);
10486 	    break;
10487 	case PV_MP:
10488 	    clear_string_option(&buf->b_p_mp);
10489 	    break;
10490 #endif
10491 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10492 	case PV_BEXPR:
10493 	    clear_string_option(&buf->b_p_bexpr);
10494 	    break;
10495 #endif
10496 #if defined(FEAT_CRYPT)
10497 	case PV_CM:
10498 	    clear_string_option(&buf->b_p_cm);
10499 	    break;
10500 #endif
10501 #ifdef FEAT_STL_OPT
10502 	case PV_STL:
10503 	    clear_string_option(&((win_T *)from)->w_p_stl);
10504 	    break;
10505 #endif
10506 	case PV_UL:
10507 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10508 	    break;
10509 #ifdef FEAT_LISP
10510 	case PV_LW:
10511 	    clear_string_option(&buf->b_p_lw);
10512 	    break;
10513 #endif
10514 #ifdef FEAT_MBYTE
10515 	case PV_MENC:
10516 	    clear_string_option(&buf->b_p_menc);
10517 	    break;
10518 #endif
10519     }
10520 }
10521 
10522 /*
10523  * Get pointer to option variable, depending on local or global scope.
10524  */
10525     static char_u *
10526 get_varp_scope(struct vimoption *p, int opt_flags)
10527 {
10528     if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10529     {
10530 	if (p->var == VAR_WIN)
10531 	    return (char_u *)GLOBAL_WO(get_varp(p));
10532 	return p->var;
10533     }
10534     if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
10535     {
10536 	switch ((int)p->indir)
10537 	{
10538 	    case PV_FP:   return (char_u *)&(curbuf->b_p_fp);
10539 #ifdef FEAT_QUICKFIX
10540 	    case PV_EFM:  return (char_u *)&(curbuf->b_p_efm);
10541 	    case PV_GP:   return (char_u *)&(curbuf->b_p_gp);
10542 	    case PV_MP:   return (char_u *)&(curbuf->b_p_mp);
10543 #endif
10544 	    case PV_EP:   return (char_u *)&(curbuf->b_p_ep);
10545 	    case PV_KP:   return (char_u *)&(curbuf->b_p_kp);
10546 	    case PV_PATH: return (char_u *)&(curbuf->b_p_path);
10547 	    case PV_AR:   return (char_u *)&(curbuf->b_p_ar);
10548 	    case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
10549 	    case PV_TC:   return (char_u *)&(curbuf->b_p_tc);
10550 #ifdef FEAT_FIND_ID
10551 	    case PV_DEF:  return (char_u *)&(curbuf->b_p_def);
10552 	    case PV_INC:  return (char_u *)&(curbuf->b_p_inc);
10553 #endif
10554 #ifdef FEAT_INS_EXPAND
10555 	    case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10556 	    case PV_TSR:  return (char_u *)&(curbuf->b_p_tsr);
10557 #endif
10558 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10559 	    case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10560 #endif
10561 #if defined(FEAT_CRYPT)
10562 	    case PV_CM:	  return (char_u *)&(curbuf->b_p_cm);
10563 #endif
10564 #ifdef FEAT_STL_OPT
10565 	    case PV_STL:  return (char_u *)&(curwin->w_p_stl);
10566 #endif
10567 	    case PV_UL:   return (char_u *)&(curbuf->b_p_ul);
10568 #ifdef FEAT_LISP
10569 	    case PV_LW:   return (char_u *)&(curbuf->b_p_lw);
10570 #endif
10571 	    case PV_BKC:  return (char_u *)&(curbuf->b_p_bkc);
10572 #ifdef FEAT_MBYTE
10573 	    case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10574 #endif
10575 	}
10576 	return NULL; /* "cannot happen" */
10577     }
10578     return get_varp(p);
10579 }
10580 
10581 /*
10582  * Get pointer to option variable.
10583  */
10584     static char_u *
10585 get_varp(struct vimoption *p)
10586 {
10587     /* hidden option, always return NULL */
10588     if (p->var == NULL)
10589 	return NULL;
10590 
10591     switch ((int)p->indir)
10592     {
10593 	case PV_NONE:	return p->var;
10594 
10595 	/* global option with local value: use local value if it's been set */
10596 	case PV_EP:	return *curbuf->b_p_ep != NUL
10597 				    ? (char_u *)&curbuf->b_p_ep : p->var;
10598 	case PV_KP:	return *curbuf->b_p_kp != NUL
10599 				    ? (char_u *)&curbuf->b_p_kp : p->var;
10600 	case PV_PATH:	return *curbuf->b_p_path != NUL
10601 				    ? (char_u *)&(curbuf->b_p_path) : p->var;
10602 	case PV_AR:	return curbuf->b_p_ar >= 0
10603 				    ? (char_u *)&(curbuf->b_p_ar) : p->var;
10604 	case PV_TAGS:	return *curbuf->b_p_tags != NUL
10605 				    ? (char_u *)&(curbuf->b_p_tags) : p->var;
10606 	case PV_TC:	return *curbuf->b_p_tc != NUL
10607 				    ? (char_u *)&(curbuf->b_p_tc) : p->var;
10608 	case PV_BKC:	return *curbuf->b_p_bkc != NUL
10609 				    ? (char_u *)&(curbuf->b_p_bkc) : p->var;
10610 #ifdef FEAT_FIND_ID
10611 	case PV_DEF:	return *curbuf->b_p_def != NUL
10612 				    ? (char_u *)&(curbuf->b_p_def) : p->var;
10613 	case PV_INC:	return *curbuf->b_p_inc != NUL
10614 				    ? (char_u *)&(curbuf->b_p_inc) : p->var;
10615 #endif
10616 #ifdef FEAT_INS_EXPAND
10617 	case PV_DICT:	return *curbuf->b_p_dict != NUL
10618 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
10619 	case PV_TSR:	return *curbuf->b_p_tsr != NUL
10620 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10621 #endif
10622 	case PV_FP:	return *curbuf->b_p_fp != NUL
10623 				    ? (char_u *)&(curbuf->b_p_fp) : p->var;
10624 #ifdef FEAT_QUICKFIX
10625 	case PV_EFM:	return *curbuf->b_p_efm != NUL
10626 				    ? (char_u *)&(curbuf->b_p_efm) : p->var;
10627 	case PV_GP:	return *curbuf->b_p_gp != NUL
10628 				    ? (char_u *)&(curbuf->b_p_gp) : p->var;
10629 	case PV_MP:	return *curbuf->b_p_mp != NUL
10630 				    ? (char_u *)&(curbuf->b_p_mp) : p->var;
10631 #endif
10632 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10633 	case PV_BEXPR:	return *curbuf->b_p_bexpr != NUL
10634 				    ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10635 #endif
10636 #if defined(FEAT_CRYPT)
10637 	case PV_CM:	return *curbuf->b_p_cm != NUL
10638 				    ? (char_u *)&(curbuf->b_p_cm) : p->var;
10639 #endif
10640 #ifdef FEAT_STL_OPT
10641 	case PV_STL:	return *curwin->w_p_stl != NUL
10642 				    ? (char_u *)&(curwin->w_p_stl) : p->var;
10643 #endif
10644 	case PV_UL:	return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10645 				    ? (char_u *)&(curbuf->b_p_ul) : p->var;
10646 #ifdef FEAT_LISP
10647 	case PV_LW:	return *curbuf->b_p_lw != NUL
10648 				    ? (char_u *)&(curbuf->b_p_lw) : p->var;
10649 #endif
10650 #ifdef FEAT_MBYTE
10651 	case PV_MENC:	return *curbuf->b_p_menc != NUL
10652 				    ? (char_u *)&(curbuf->b_p_menc) : p->var;
10653 #endif
10654 
10655 #ifdef FEAT_ARABIC
10656 	case PV_ARAB:	return (char_u *)&(curwin->w_p_arab);
10657 #endif
10658 	case PV_LIST:	return (char_u *)&(curwin->w_p_list);
10659 #ifdef FEAT_SPELL
10660 	case PV_SPELL:	return (char_u *)&(curwin->w_p_spell);
10661 #endif
10662 #ifdef FEAT_SYN_HL
10663 	case PV_CUC:	return (char_u *)&(curwin->w_p_cuc);
10664 	case PV_CUL:	return (char_u *)&(curwin->w_p_cul);
10665 	case PV_CC:	return (char_u *)&(curwin->w_p_cc);
10666 #endif
10667 #ifdef FEAT_DIFF
10668 	case PV_DIFF:	return (char_u *)&(curwin->w_p_diff);
10669 #endif
10670 #ifdef FEAT_FOLDING
10671 	case PV_FDC:	return (char_u *)&(curwin->w_p_fdc);
10672 	case PV_FEN:	return (char_u *)&(curwin->w_p_fen);
10673 	case PV_FDI:	return (char_u *)&(curwin->w_p_fdi);
10674 	case PV_FDL:	return (char_u *)&(curwin->w_p_fdl);
10675 	case PV_FDM:	return (char_u *)&(curwin->w_p_fdm);
10676 	case PV_FML:	return (char_u *)&(curwin->w_p_fml);
10677 	case PV_FDN:	return (char_u *)&(curwin->w_p_fdn);
10678 # ifdef FEAT_EVAL
10679 	case PV_FDE:	return (char_u *)&(curwin->w_p_fde);
10680 	case PV_FDT:	return (char_u *)&(curwin->w_p_fdt);
10681 # endif
10682 	case PV_FMR:	return (char_u *)&(curwin->w_p_fmr);
10683 #endif
10684 	case PV_NU:	return (char_u *)&(curwin->w_p_nu);
10685 	case PV_RNU:	return (char_u *)&(curwin->w_p_rnu);
10686 #ifdef FEAT_LINEBREAK
10687 	case PV_NUW:	return (char_u *)&(curwin->w_p_nuw);
10688 #endif
10689 #ifdef FEAT_WINDOWS
10690 	case PV_WFH:	return (char_u *)&(curwin->w_p_wfh);
10691 	case PV_WFW:	return (char_u *)&(curwin->w_p_wfw);
10692 #endif
10693 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10694 	case PV_PVW:	return (char_u *)&(curwin->w_p_pvw);
10695 #endif
10696 #ifdef FEAT_RIGHTLEFT
10697 	case PV_RL:	return (char_u *)&(curwin->w_p_rl);
10698 	case PV_RLC:	return (char_u *)&(curwin->w_p_rlc);
10699 #endif
10700 	case PV_SCROLL:	return (char_u *)&(curwin->w_p_scr);
10701 	case PV_WRAP:	return (char_u *)&(curwin->w_p_wrap);
10702 #ifdef FEAT_LINEBREAK
10703 	case PV_LBR:	return (char_u *)&(curwin->w_p_lbr);
10704 	case PV_BRI:	return (char_u *)&(curwin->w_p_bri);
10705 	case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
10706 #endif
10707 #ifdef FEAT_SCROLLBIND
10708 	case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10709 #endif
10710 #ifdef FEAT_CURSORBIND
10711 	case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10712 #endif
10713 #ifdef FEAT_CONCEAL
10714 	case PV_COCU:   return (char_u *)&(curwin->w_p_cocu);
10715 	case PV_COLE:   return (char_u *)&(curwin->w_p_cole);
10716 #endif
10717 #ifdef FEAT_TERMINAL
10718 	case PV_TK:     return (char_u *)&(curwin->w_p_tk);
10719 	case PV_TMS:    return (char_u *)&(curwin->w_p_tms);
10720 #endif
10721 
10722 	case PV_AI:	return (char_u *)&(curbuf->b_p_ai);
10723 	case PV_BIN:	return (char_u *)&(curbuf->b_p_bin);
10724 #ifdef FEAT_MBYTE
10725 	case PV_BOMB:	return (char_u *)&(curbuf->b_p_bomb);
10726 #endif
10727 	case PV_BH:	return (char_u *)&(curbuf->b_p_bh);
10728 	case PV_BT:	return (char_u *)&(curbuf->b_p_bt);
10729 	case PV_BL:	return (char_u *)&(curbuf->b_p_bl);
10730 	case PV_CI:	return (char_u *)&(curbuf->b_p_ci);
10731 #ifdef FEAT_CINDENT
10732 	case PV_CIN:	return (char_u *)&(curbuf->b_p_cin);
10733 	case PV_CINK:	return (char_u *)&(curbuf->b_p_cink);
10734 	case PV_CINO:	return (char_u *)&(curbuf->b_p_cino);
10735 #endif
10736 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10737 	case PV_CINW:	return (char_u *)&(curbuf->b_p_cinw);
10738 #endif
10739 #ifdef FEAT_COMMENTS
10740 	case PV_COM:	return (char_u *)&(curbuf->b_p_com);
10741 #endif
10742 #ifdef FEAT_FOLDING
10743 	case PV_CMS:	return (char_u *)&(curbuf->b_p_cms);
10744 #endif
10745 #ifdef FEAT_INS_EXPAND
10746 	case PV_CPT:	return (char_u *)&(curbuf->b_p_cpt);
10747 #endif
10748 #ifdef FEAT_COMPL_FUNC
10749 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
10750 	case PV_OFU:	return (char_u *)&(curbuf->b_p_ofu);
10751 #endif
10752 	case PV_EOL:	return (char_u *)&(curbuf->b_p_eol);
10753 	case PV_FIXEOL:	return (char_u *)&(curbuf->b_p_fixeol);
10754 	case PV_ET:	return (char_u *)&(curbuf->b_p_et);
10755 #ifdef FEAT_MBYTE
10756 	case PV_FENC:	return (char_u *)&(curbuf->b_p_fenc);
10757 #endif
10758 	case PV_FF:	return (char_u *)&(curbuf->b_p_ff);
10759 #ifdef FEAT_AUTOCMD
10760 	case PV_FT:	return (char_u *)&(curbuf->b_p_ft);
10761 #endif
10762 	case PV_FO:	return (char_u *)&(curbuf->b_p_fo);
10763 	case PV_FLP:	return (char_u *)&(curbuf->b_p_flp);
10764 	case PV_IMI:	return (char_u *)&(curbuf->b_p_iminsert);
10765 	case PV_IMS:	return (char_u *)&(curbuf->b_p_imsearch);
10766 	case PV_INF:	return (char_u *)&(curbuf->b_p_inf);
10767 	case PV_ISK:	return (char_u *)&(curbuf->b_p_isk);
10768 #ifdef FEAT_FIND_ID
10769 # ifdef FEAT_EVAL
10770 	case PV_INEX:	return (char_u *)&(curbuf->b_p_inex);
10771 # endif
10772 #endif
10773 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10774 	case PV_INDE:	return (char_u *)&(curbuf->b_p_inde);
10775 	case PV_INDK:	return (char_u *)&(curbuf->b_p_indk);
10776 #endif
10777 #ifdef FEAT_EVAL
10778 	case PV_FEX:	return (char_u *)&(curbuf->b_p_fex);
10779 #endif
10780 #ifdef FEAT_CRYPT
10781 	case PV_KEY:	return (char_u *)&(curbuf->b_p_key);
10782 #endif
10783 #ifdef FEAT_LISP
10784 	case PV_LISP:	return (char_u *)&(curbuf->b_p_lisp);
10785 #endif
10786 	case PV_ML:	return (char_u *)&(curbuf->b_p_ml);
10787 	case PV_MPS:	return (char_u *)&(curbuf->b_p_mps);
10788 	case PV_MA:	return (char_u *)&(curbuf->b_p_ma);
10789 	case PV_MOD:	return (char_u *)&(curbuf->b_changed);
10790 	case PV_NF:	return (char_u *)&(curbuf->b_p_nf);
10791 	case PV_PI:	return (char_u *)&(curbuf->b_p_pi);
10792 #ifdef FEAT_TEXTOBJ
10793 	case PV_QE:	return (char_u *)&(curbuf->b_p_qe);
10794 #endif
10795 	case PV_RO:	return (char_u *)&(curbuf->b_p_ro);
10796 #ifdef FEAT_SMARTINDENT
10797 	case PV_SI:	return (char_u *)&(curbuf->b_p_si);
10798 #endif
10799 	case PV_SN:	return (char_u *)&(curbuf->b_p_sn);
10800 	case PV_STS:	return (char_u *)&(curbuf->b_p_sts);
10801 #ifdef FEAT_SEARCHPATH
10802 	case PV_SUA:	return (char_u *)&(curbuf->b_p_sua);
10803 #endif
10804 	case PV_SWF:	return (char_u *)&(curbuf->b_p_swf);
10805 #ifdef FEAT_SYN_HL
10806 	case PV_SMC:	return (char_u *)&(curbuf->b_p_smc);
10807 	case PV_SYN:	return (char_u *)&(curbuf->b_p_syn);
10808 #endif
10809 #ifdef FEAT_SPELL
10810 	case PV_SPC:	return (char_u *)&(curwin->w_s->b_p_spc);
10811 	case PV_SPF:	return (char_u *)&(curwin->w_s->b_p_spf);
10812 	case PV_SPL:	return (char_u *)&(curwin->w_s->b_p_spl);
10813 #endif
10814 	case PV_SW:	return (char_u *)&(curbuf->b_p_sw);
10815 	case PV_TS:	return (char_u *)&(curbuf->b_p_ts);
10816 	case PV_TW:	return (char_u *)&(curbuf->b_p_tw);
10817 	case PV_TX:	return (char_u *)&(curbuf->b_p_tx);
10818 #ifdef FEAT_PERSISTENT_UNDO
10819 	case PV_UDF:	return (char_u *)&(curbuf->b_p_udf);
10820 #endif
10821 	case PV_WM:	return (char_u *)&(curbuf->b_p_wm);
10822 #ifdef FEAT_KEYMAP
10823 	case PV_KMAP:	return (char_u *)&(curbuf->b_p_keymap);
10824 #endif
10825 #ifdef FEAT_SIGNS
10826 	case PV_SCL:	return (char_u *)&(curwin->w_p_scl);
10827 #endif
10828 	default:	IEMSG(_("E356: get_varp ERROR"));
10829     }
10830     /* always return a valid pointer to avoid a crash! */
10831     return (char_u *)&(curbuf->b_p_wm);
10832 }
10833 
10834 /*
10835  * Get the value of 'equalprg', either the buffer-local one or the global one.
10836  */
10837     char_u *
10838 get_equalprg(void)
10839 {
10840     if (*curbuf->b_p_ep == NUL)
10841 	return p_ep;
10842     return curbuf->b_p_ep;
10843 }
10844 
10845 #if defined(FEAT_WINDOWS) || defined(PROTO)
10846 /*
10847  * Copy options from one window to another.
10848  * Used when splitting a window.
10849  */
10850     void
10851 win_copy_options(win_T *wp_from, win_T *wp_to)
10852 {
10853     copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10854     copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10855 # ifdef FEAT_RIGHTLEFT
10856 #  ifdef FEAT_FKMAP
10857     /* Is this right? */
10858     wp_to->w_farsi = wp_from->w_farsi;
10859 #  endif
10860 # endif
10861 #if defined(FEAT_LINEBREAK)
10862     briopt_check(wp_to);
10863 #endif
10864 }
10865 #endif
10866 
10867 /*
10868  * Copy the options from one winopt_T to another.
10869  * Doesn't free the old option values in "to", use clear_winopt() for that.
10870  * The 'scroll' option is not copied, because it depends on the window height.
10871  * The 'previewwindow' option is reset, there can be only one preview window.
10872  */
10873     void
10874 copy_winopt(winopt_T *from, winopt_T *to)
10875 {
10876 #ifdef FEAT_ARABIC
10877     to->wo_arab = from->wo_arab;
10878 #endif
10879     to->wo_list = from->wo_list;
10880     to->wo_nu = from->wo_nu;
10881     to->wo_rnu = from->wo_rnu;
10882 #ifdef FEAT_LINEBREAK
10883     to->wo_nuw = from->wo_nuw;
10884 #endif
10885 #ifdef FEAT_RIGHTLEFT
10886     to->wo_rl  = from->wo_rl;
10887     to->wo_rlc = vim_strsave(from->wo_rlc);
10888 #endif
10889 #ifdef FEAT_STL_OPT
10890     to->wo_stl = vim_strsave(from->wo_stl);
10891 #endif
10892     to->wo_wrap = from->wo_wrap;
10893 #ifdef FEAT_DIFF
10894     to->wo_wrap_save = from->wo_wrap_save;
10895 #endif
10896 #ifdef FEAT_LINEBREAK
10897     to->wo_lbr = from->wo_lbr;
10898     to->wo_bri = from->wo_bri;
10899     to->wo_briopt = vim_strsave(from->wo_briopt);
10900 #endif
10901 #ifdef FEAT_SCROLLBIND
10902     to->wo_scb = from->wo_scb;
10903     to->wo_scb_save = from->wo_scb_save;
10904 #endif
10905 #ifdef FEAT_CURSORBIND
10906     to->wo_crb = from->wo_crb;
10907     to->wo_crb_save = from->wo_crb_save;
10908 #endif
10909 #ifdef FEAT_SPELL
10910     to->wo_spell = from->wo_spell;
10911 #endif
10912 #ifdef FEAT_SYN_HL
10913     to->wo_cuc = from->wo_cuc;
10914     to->wo_cul = from->wo_cul;
10915     to->wo_cc = vim_strsave(from->wo_cc);
10916 #endif
10917 #ifdef FEAT_DIFF
10918     to->wo_diff = from->wo_diff;
10919     to->wo_diff_saved = from->wo_diff_saved;
10920 #endif
10921 #ifdef FEAT_CONCEAL
10922     to->wo_cocu = vim_strsave(from->wo_cocu);
10923     to->wo_cole = from->wo_cole;
10924 #endif
10925 #ifdef FEAT_TERMINAL
10926     to->wo_tk = vim_strsave(from->wo_tk);
10927     to->wo_tms = vim_strsave(from->wo_tms);
10928 #endif
10929 #ifdef FEAT_FOLDING
10930     to->wo_fdc = from->wo_fdc;
10931     to->wo_fdc_save = from->wo_fdc_save;
10932     to->wo_fen = from->wo_fen;
10933     to->wo_fen_save = from->wo_fen_save;
10934     to->wo_fdi = vim_strsave(from->wo_fdi);
10935     to->wo_fml = from->wo_fml;
10936     to->wo_fdl = from->wo_fdl;
10937     to->wo_fdl_save = from->wo_fdl_save;
10938     to->wo_fdm = vim_strsave(from->wo_fdm);
10939     to->wo_fdm_save = from->wo_diff_saved
10940 			      ? vim_strsave(from->wo_fdm_save) : empty_option;
10941     to->wo_fdn = from->wo_fdn;
10942 # ifdef FEAT_EVAL
10943     to->wo_fde = vim_strsave(from->wo_fde);
10944     to->wo_fdt = vim_strsave(from->wo_fdt);
10945 # endif
10946     to->wo_fmr = vim_strsave(from->wo_fmr);
10947 #endif
10948 #ifdef FEAT_SIGNS
10949     to->wo_scl = vim_strsave(from->wo_scl);
10950 #endif
10951     check_winopt(to);		/* don't want NULL pointers */
10952 }
10953 
10954 /*
10955  * Check string options in a window for a NULL value.
10956  */
10957     void
10958 check_win_options(win_T *win)
10959 {
10960     check_winopt(&win->w_onebuf_opt);
10961     check_winopt(&win->w_allbuf_opt);
10962 }
10963 
10964 /*
10965  * Check for NULL pointers in a winopt_T and replace them with empty_option.
10966  */
10967     static void
10968 check_winopt(winopt_T *wop UNUSED)
10969 {
10970 #ifdef FEAT_FOLDING
10971     check_string_option(&wop->wo_fdi);
10972     check_string_option(&wop->wo_fdm);
10973     check_string_option(&wop->wo_fdm_save);
10974 # ifdef FEAT_EVAL
10975     check_string_option(&wop->wo_fde);
10976     check_string_option(&wop->wo_fdt);
10977 # endif
10978     check_string_option(&wop->wo_fmr);
10979 #endif
10980 #ifdef FEAT_SIGNS
10981     check_string_option(&wop->wo_scl);
10982 #endif
10983 #ifdef FEAT_RIGHTLEFT
10984     check_string_option(&wop->wo_rlc);
10985 #endif
10986 #ifdef FEAT_STL_OPT
10987     check_string_option(&wop->wo_stl);
10988 #endif
10989 #ifdef FEAT_SYN_HL
10990     check_string_option(&wop->wo_cc);
10991 #endif
10992 #ifdef FEAT_CONCEAL
10993     check_string_option(&wop->wo_cocu);
10994 #endif
10995 #ifdef FEAT_TERMINAL
10996     check_string_option(&wop->wo_tk);
10997     check_string_option(&wop->wo_tms);
10998 #endif
10999 #ifdef FEAT_LINEBREAK
11000     check_string_option(&wop->wo_briopt);
11001 #endif
11002 }
11003 
11004 /*
11005  * Free the allocated memory inside a winopt_T.
11006  */
11007     void
11008 clear_winopt(winopt_T *wop UNUSED)
11009 {
11010 #ifdef FEAT_FOLDING
11011     clear_string_option(&wop->wo_fdi);
11012     clear_string_option(&wop->wo_fdm);
11013     clear_string_option(&wop->wo_fdm_save);
11014 # ifdef FEAT_EVAL
11015     clear_string_option(&wop->wo_fde);
11016     clear_string_option(&wop->wo_fdt);
11017 # endif
11018     clear_string_option(&wop->wo_fmr);
11019 #endif
11020 #ifdef FEAT_SIGNS
11021     clear_string_option(&wop->wo_scl);
11022 #endif
11023 #ifdef FEAT_LINEBREAK
11024     clear_string_option(&wop->wo_briopt);
11025 #endif
11026 #ifdef FEAT_RIGHTLEFT
11027     clear_string_option(&wop->wo_rlc);
11028 #endif
11029 #ifdef FEAT_STL_OPT
11030     clear_string_option(&wop->wo_stl);
11031 #endif
11032 #ifdef FEAT_SYN_HL
11033     clear_string_option(&wop->wo_cc);
11034 #endif
11035 #ifdef FEAT_CONCEAL
11036     clear_string_option(&wop->wo_cocu);
11037 #endif
11038 #ifdef FEAT_TERMINAL
11039     clear_string_option(&wop->wo_tk);
11040     clear_string_option(&wop->wo_tms);
11041 #endif
11042 }
11043 
11044 /*
11045  * Copy global option values to local options for one buffer.
11046  * Used when creating a new buffer and sometimes when entering a buffer.
11047  * flags:
11048  * BCO_ENTER	We will enter the buf buffer.
11049  * BCO_ALWAYS	Always copy the options, but only set b_p_initialized when
11050  *		appropriate.
11051  * BCO_NOHELP	Don't copy the values to a help buffer.
11052  */
11053     void
11054 buf_copy_options(buf_T *buf, int flags)
11055 {
11056     int		should_copy = TRUE;
11057     char_u	*save_p_isk = NULL;	    /* init for GCC */
11058     int		dont_do_help;
11059     int		did_isk = FALSE;
11060 
11061     /*
11062      * Skip this when the option defaults have not been set yet.  Happens when
11063      * main() allocates the first buffer.
11064      */
11065     if (p_cpo != NULL)
11066     {
11067 	/*
11068 	 * Always copy when entering and 'cpo' contains 'S'.
11069 	 * Don't copy when already initialized.
11070 	 * Don't copy when 'cpo' contains 's' and not entering.
11071 	 * 'S'	BCO_ENTER  initialized	's'  should_copy
11072 	 * yes	  yes	       X	 X	TRUE
11073 	 * yes	  no	      yes	 X	FALSE
11074 	 * no	   X	      yes	 X	FALSE
11075 	 *  X	  no	      no	yes	FALSE
11076 	 *  X	  no	      no	no	TRUE
11077 	 * no	  yes	      no	 X	TRUE
11078 	 */
11079 	if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11080 		&& (buf->b_p_initialized
11081 		    || (!(flags & BCO_ENTER)
11082 			&& vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11083 	    should_copy = FALSE;
11084 
11085 	if (should_copy || (flags & BCO_ALWAYS))
11086 	{
11087 	    /* Don't copy the options specific to a help buffer when
11088 	     * BCO_NOHELP is given or the options were initialized already
11089 	     * (jumping back to a help file with CTRL-T or CTRL-O) */
11090 	    dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11091 						       || buf->b_p_initialized;
11092 	    if (dont_do_help)		/* don't free b_p_isk */
11093 	    {
11094 		save_p_isk = buf->b_p_isk;
11095 		buf->b_p_isk = NULL;
11096 	    }
11097 	    /*
11098 	     * Always free the allocated strings.
11099 	     * If not already initialized, set 'readonly' and copy 'fileformat'.
11100 	     */
11101 	    if (!buf->b_p_initialized)
11102 	    {
11103 		free_buf_options(buf, TRUE);
11104 		buf->b_p_ro = FALSE;		/* don't copy readonly */
11105 		buf->b_p_tx = p_tx;
11106 #ifdef FEAT_MBYTE
11107 		buf->b_p_fenc = vim_strsave(p_fenc);
11108 #endif
11109 		switch (*p_ffs)
11110 		{
11111 		    case 'm':
11112 			buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11113 		    case 'd':
11114 			buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11115 		    case 'u':
11116 			buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11117 		    default:
11118 			buf->b_p_ff = vim_strsave(p_ff);
11119 		}
11120 		if (buf->b_p_ff != NULL)
11121 		    buf->b_start_ffc = *buf->b_p_ff;
11122 		buf->b_p_bh = empty_option;
11123 		buf->b_p_bt = empty_option;
11124 	    }
11125 	    else
11126 		free_buf_options(buf, FALSE);
11127 
11128 	    buf->b_p_ai = p_ai;
11129 	    buf->b_p_ai_nopaste = p_ai_nopaste;
11130 	    buf->b_p_sw = p_sw;
11131 	    buf->b_p_tw = p_tw;
11132 	    buf->b_p_tw_nopaste = p_tw_nopaste;
11133 	    buf->b_p_tw_nobin = p_tw_nobin;
11134 	    buf->b_p_wm = p_wm;
11135 	    buf->b_p_wm_nopaste = p_wm_nopaste;
11136 	    buf->b_p_wm_nobin = p_wm_nobin;
11137 	    buf->b_p_bin = p_bin;
11138 #ifdef FEAT_MBYTE
11139 	    buf->b_p_bomb = p_bomb;
11140 #endif
11141 	    buf->b_p_fixeol = p_fixeol;
11142 	    buf->b_p_et = p_et;
11143 	    buf->b_p_et_nobin = p_et_nobin;
11144 	    buf->b_p_et_nopaste = p_et_nopaste;
11145 	    buf->b_p_ml = p_ml;
11146 	    buf->b_p_ml_nobin = p_ml_nobin;
11147 	    buf->b_p_inf = p_inf;
11148 	    buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
11149 #ifdef FEAT_INS_EXPAND
11150 	    buf->b_p_cpt = vim_strsave(p_cpt);
11151 #endif
11152 #ifdef FEAT_COMPL_FUNC
11153 	    buf->b_p_cfu = vim_strsave(p_cfu);
11154 	    buf->b_p_ofu = vim_strsave(p_ofu);
11155 #endif
11156 	    buf->b_p_sts = p_sts;
11157 	    buf->b_p_sts_nopaste = p_sts_nopaste;
11158 	    buf->b_p_sn = p_sn;
11159 #ifdef FEAT_COMMENTS
11160 	    buf->b_p_com = vim_strsave(p_com);
11161 #endif
11162 #ifdef FEAT_FOLDING
11163 	    buf->b_p_cms = vim_strsave(p_cms);
11164 #endif
11165 	    buf->b_p_fo = vim_strsave(p_fo);
11166 	    buf->b_p_flp = vim_strsave(p_flp);
11167 	    buf->b_p_nf = vim_strsave(p_nf);
11168 	    buf->b_p_mps = vim_strsave(p_mps);
11169 #ifdef FEAT_SMARTINDENT
11170 	    buf->b_p_si = p_si;
11171 #endif
11172 	    buf->b_p_ci = p_ci;
11173 #ifdef FEAT_CINDENT
11174 	    buf->b_p_cin = p_cin;
11175 	    buf->b_p_cink = vim_strsave(p_cink);
11176 	    buf->b_p_cino = vim_strsave(p_cino);
11177 #endif
11178 #ifdef FEAT_AUTOCMD
11179 	    /* Don't copy 'filetype', it must be detected */
11180 	    buf->b_p_ft = empty_option;
11181 #endif
11182 	    buf->b_p_pi = p_pi;
11183 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11184 	    buf->b_p_cinw = vim_strsave(p_cinw);
11185 #endif
11186 #ifdef FEAT_LISP
11187 	    buf->b_p_lisp = p_lisp;
11188 #endif
11189 #ifdef FEAT_SYN_HL
11190 	    /* Don't copy 'syntax', it must be set */
11191 	    buf->b_p_syn = empty_option;
11192 	    buf->b_p_smc = p_smc;
11193 	    buf->b_s.b_syn_isk = empty_option;
11194 #endif
11195 #ifdef FEAT_SPELL
11196 	    buf->b_s.b_p_spc = vim_strsave(p_spc);
11197 	    (void)compile_cap_prog(&buf->b_s);
11198 	    buf->b_s.b_p_spf = vim_strsave(p_spf);
11199 	    buf->b_s.b_p_spl = vim_strsave(p_spl);
11200 #endif
11201 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11202 	    buf->b_p_inde = vim_strsave(p_inde);
11203 	    buf->b_p_indk = vim_strsave(p_indk);
11204 #endif
11205 	    buf->b_p_fp = empty_option;
11206 #if defined(FEAT_EVAL)
11207 	    buf->b_p_fex = vim_strsave(p_fex);
11208 #endif
11209 #ifdef FEAT_CRYPT
11210 	    buf->b_p_key = vim_strsave(p_key);
11211 #endif
11212 #ifdef FEAT_SEARCHPATH
11213 	    buf->b_p_sua = vim_strsave(p_sua);
11214 #endif
11215 #ifdef FEAT_KEYMAP
11216 	    buf->b_p_keymap = vim_strsave(p_keymap);
11217 	    buf->b_kmap_state |= KEYMAP_INIT;
11218 #endif
11219 	    /* This isn't really an option, but copying the langmap and IME
11220 	     * state from the current buffer is better than resetting it. */
11221 	    buf->b_p_iminsert = p_iminsert;
11222 	    buf->b_p_imsearch = p_imsearch;
11223 
11224 	    /* options that are normally global but also have a local value
11225 	     * are not copied, start using the global value */
11226 	    buf->b_p_ar = -1;
11227 	    buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11228 	    buf->b_p_bkc = empty_option;
11229 	    buf->b_bkc_flags = 0;
11230 #ifdef FEAT_QUICKFIX
11231 	    buf->b_p_gp = empty_option;
11232 	    buf->b_p_mp = empty_option;
11233 	    buf->b_p_efm = empty_option;
11234 #endif
11235 	    buf->b_p_ep = empty_option;
11236 	    buf->b_p_kp = empty_option;
11237 	    buf->b_p_path = empty_option;
11238 	    buf->b_p_tags = empty_option;
11239 	    buf->b_p_tc = empty_option;
11240 	    buf->b_tc_flags = 0;
11241 #ifdef FEAT_FIND_ID
11242 	    buf->b_p_def = empty_option;
11243 	    buf->b_p_inc = empty_option;
11244 # ifdef FEAT_EVAL
11245 	    buf->b_p_inex = vim_strsave(p_inex);
11246 # endif
11247 #endif
11248 #ifdef FEAT_INS_EXPAND
11249 	    buf->b_p_dict = empty_option;
11250 	    buf->b_p_tsr = empty_option;
11251 #endif
11252 #ifdef FEAT_TEXTOBJ
11253 	    buf->b_p_qe = vim_strsave(p_qe);
11254 #endif
11255 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11256 	    buf->b_p_bexpr = empty_option;
11257 #endif
11258 #if defined(FEAT_CRYPT)
11259 	    buf->b_p_cm = empty_option;
11260 #endif
11261 #ifdef FEAT_PERSISTENT_UNDO
11262 	    buf->b_p_udf = p_udf;
11263 #endif
11264 #ifdef FEAT_LISP
11265 	    buf->b_p_lw = empty_option;
11266 #endif
11267 #ifdef FEAT_MBYTE
11268 	    buf->b_p_menc = empty_option;
11269 #endif
11270 
11271 	    /*
11272 	     * Don't copy the options set by ex_help(), use the saved values,
11273 	     * when going from a help buffer to a non-help buffer.
11274 	     * Don't touch these at all when BCO_NOHELP is used and going from
11275 	     * or to a help buffer.
11276 	     */
11277 	    if (dont_do_help)
11278 		buf->b_p_isk = save_p_isk;
11279 	    else
11280 	    {
11281 		buf->b_p_isk = vim_strsave(p_isk);
11282 		did_isk = TRUE;
11283 		buf->b_p_ts = p_ts;
11284 		buf->b_help = FALSE;
11285 		if (buf->b_p_bt[0] == 'h')
11286 		    clear_string_option(&buf->b_p_bt);
11287 		buf->b_p_ma = p_ma;
11288 	    }
11289 	}
11290 
11291 	/*
11292 	 * When the options should be copied (ignoring BCO_ALWAYS), set the
11293 	 * flag that indicates that the options have been initialized.
11294 	 */
11295 	if (should_copy)
11296 	    buf->b_p_initialized = TRUE;
11297     }
11298 
11299     check_buf_options(buf);	    /* make sure we don't have NULLs */
11300     if (did_isk)
11301 	(void)buf_init_chartab(buf, FALSE);
11302 }
11303 
11304 /*
11305  * Reset the 'modifiable' option and its default value.
11306  */
11307     void
11308 reset_modifiable(void)
11309 {
11310     int		opt_idx;
11311 
11312     curbuf->b_p_ma = FALSE;
11313     p_ma = FALSE;
11314     opt_idx = findoption((char_u *)"ma");
11315     if (opt_idx >= 0)
11316 	options[opt_idx].def_val[VI_DEFAULT] = FALSE;
11317 }
11318 
11319 /*
11320  * Set the global value for 'iminsert' to the local value.
11321  */
11322     void
11323 set_iminsert_global(void)
11324 {
11325     p_iminsert = curbuf->b_p_iminsert;
11326 }
11327 
11328 /*
11329  * Set the global value for 'imsearch' to the local value.
11330  */
11331     void
11332 set_imsearch_global(void)
11333 {
11334     p_imsearch = curbuf->b_p_imsearch;
11335 }
11336 
11337 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11338 static int expand_option_idx = -1;
11339 static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11340 static int expand_option_flags = 0;
11341 
11342     void
11343 set_context_in_set_cmd(
11344     expand_T	*xp,
11345     char_u	*arg,
11346     int		opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11347 {
11348     int		nextchar;
11349     long_u	flags = 0;	/* init for GCC */
11350     int		opt_idx = 0;	/* init for GCC */
11351     char_u	*p;
11352     char_u	*s;
11353     int		is_term_option = FALSE;
11354     int		key;
11355 
11356     expand_option_flags = opt_flags;
11357 
11358     xp->xp_context = EXPAND_SETTINGS;
11359     if (*arg == NUL)
11360     {
11361 	xp->xp_pattern = arg;
11362 	return;
11363     }
11364     p = arg + STRLEN(arg) - 1;
11365     if (*p == ' ' && *(p - 1) != '\\')
11366     {
11367 	xp->xp_pattern = p + 1;
11368 	return;
11369     }
11370     while (p > arg)
11371     {
11372 	s = p;
11373 	/* count number of backslashes before ' ' or ',' */
11374 	if (*p == ' ' || *p == ',')
11375 	{
11376 	    while (s > arg && *(s - 1) == '\\')
11377 		--s;
11378 	}
11379 	/* break at a space with an even number of backslashes */
11380 	if (*p == ' ' && ((p - s) & 1) == 0)
11381 	{
11382 	    ++p;
11383 	    break;
11384 	}
11385 	--p;
11386     }
11387     if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
11388     {
11389 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11390 	p += 2;
11391     }
11392     if (STRNCMP(p, "inv", 3) == 0)
11393     {
11394 	xp->xp_context = EXPAND_BOOL_SETTINGS;
11395 	p += 3;
11396     }
11397     xp->xp_pattern = arg = p;
11398     if (*arg == '<')
11399     {
11400 	while (*p != '>')
11401 	    if (*p++ == NUL)	    /* expand terminal option name */
11402 		return;
11403 	key = get_special_key_code(arg + 1);
11404 	if (key == 0)		    /* unknown name */
11405 	{
11406 	    xp->xp_context = EXPAND_NOTHING;
11407 	    return;
11408 	}
11409 	nextchar = *++p;
11410 	is_term_option = TRUE;
11411 	expand_option_name[2] = KEY2TERMCAP0(key);
11412 	expand_option_name[3] = KEY2TERMCAP1(key);
11413     }
11414     else
11415     {
11416 	if (p[0] == 't' && p[1] == '_')
11417 	{
11418 	    p += 2;
11419 	    if (*p != NUL)
11420 		++p;
11421 	    if (*p == NUL)
11422 		return;		/* expand option name */
11423 	    nextchar = *++p;
11424 	    is_term_option = TRUE;
11425 	    expand_option_name[2] = p[-2];
11426 	    expand_option_name[3] = p[-1];
11427 	}
11428 	else
11429 	{
11430 		/* Allow * wildcard */
11431 	    while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11432 		p++;
11433 	    if (*p == NUL)
11434 		return;
11435 	    nextchar = *p;
11436 	    *p = NUL;
11437 	    opt_idx = findoption(arg);
11438 	    *p = nextchar;
11439 	    if (opt_idx == -1 || options[opt_idx].var == NULL)
11440 	    {
11441 		xp->xp_context = EXPAND_NOTHING;
11442 		return;
11443 	    }
11444 	    flags = options[opt_idx].flags;
11445 	    if (flags & P_BOOL)
11446 	    {
11447 		xp->xp_context = EXPAND_NOTHING;
11448 		return;
11449 	    }
11450 	}
11451     }
11452     /* handle "-=" and "+=" */
11453     if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11454     {
11455 	++p;
11456 	nextchar = '=';
11457     }
11458     if ((nextchar != '=' && nextchar != ':')
11459 				    || xp->xp_context == EXPAND_BOOL_SETTINGS)
11460     {
11461 	xp->xp_context = EXPAND_UNSUCCESSFUL;
11462 	return;
11463     }
11464     if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11465     {
11466 	xp->xp_context = EXPAND_OLD_SETTING;
11467 	if (is_term_option)
11468 	    expand_option_idx = -1;
11469 	else
11470 	    expand_option_idx = opt_idx;
11471 	xp->xp_pattern = p + 1;
11472 	return;
11473     }
11474     xp->xp_context = EXPAND_NOTHING;
11475     if (is_term_option || (flags & P_NUM))
11476 	return;
11477 
11478     xp->xp_pattern = p + 1;
11479 
11480     if (flags & P_EXPAND)
11481     {
11482 	p = options[opt_idx].var;
11483 	if (p == (char_u *)&p_bdir
11484 		|| p == (char_u *)&p_dir
11485 		|| p == (char_u *)&p_path
11486 		|| p == (char_u *)&p_pp
11487 		|| p == (char_u *)&p_rtp
11488 #ifdef FEAT_SEARCHPATH
11489 		|| p == (char_u *)&p_cdpath
11490 #endif
11491 #ifdef FEAT_SESSION
11492 		|| p == (char_u *)&p_vdir
11493 #endif
11494 		)
11495 	{
11496 	    xp->xp_context = EXPAND_DIRECTORIES;
11497 	    if (p == (char_u *)&p_path
11498 #ifdef FEAT_SEARCHPATH
11499 		    || p == (char_u *)&p_cdpath
11500 #endif
11501 		   )
11502 		xp->xp_backslash = XP_BS_THREE;
11503 	    else
11504 		xp->xp_backslash = XP_BS_ONE;
11505 	}
11506 	else
11507 	{
11508 	    xp->xp_context = EXPAND_FILES;
11509 	    /* for 'tags' need three backslashes for a space */
11510 	    if (p == (char_u *)&p_tags)
11511 		xp->xp_backslash = XP_BS_THREE;
11512 	    else
11513 		xp->xp_backslash = XP_BS_ONE;
11514 	}
11515     }
11516 
11517     /* For an option that is a list of file names, find the start of the
11518      * last file name. */
11519     for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11520     {
11521 	/* count number of backslashes before ' ' or ',' */
11522 	if (*p == ' ' || *p == ',')
11523 	{
11524 	    s = p;
11525 	    while (s > xp->xp_pattern && *(s - 1) == '\\')
11526 		--s;
11527 	    if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11528 		    || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11529 	    {
11530 		xp->xp_pattern = p + 1;
11531 		break;
11532 	    }
11533 	}
11534 
11535 #ifdef FEAT_SPELL
11536 	/* for 'spellsuggest' start at "file:" */
11537 	if (options[opt_idx].var == (char_u *)&p_sps
11538 					       && STRNCMP(p, "file:", 5) == 0)
11539 	{
11540 	    xp->xp_pattern = p + 5;
11541 	    break;
11542 	}
11543 #endif
11544     }
11545 
11546     return;
11547 }
11548 
11549     int
11550 ExpandSettings(
11551     expand_T	*xp,
11552     regmatch_T	*regmatch,
11553     int		*num_file,
11554     char_u	***file)
11555 {
11556     int		num_normal = 0;	    /* Nr of matching non-term-code settings */
11557     int		num_term = 0;	    /* Nr of matching terminal code settings */
11558     int		opt_idx;
11559     int		match;
11560     int		count = 0;
11561     char_u	*str;
11562     int		loop;
11563     int		is_term_opt;
11564     char_u	name_buf[MAX_KEY_NAME_LEN];
11565     static char *(names[]) = {"all", "termcap"};
11566     int		ic = regmatch->rm_ic;	/* remember the ignore-case flag */
11567 
11568     /* do this loop twice:
11569      * loop == 0: count the number of matching options
11570      * loop == 1: copy the matching options into allocated memory
11571      */
11572     for (loop = 0; loop <= 1; ++loop)
11573     {
11574 	regmatch->rm_ic = ic;
11575 	if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11576 	{
11577 	    for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11578 								      ++match)
11579 		if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11580 		{
11581 		    if (loop == 0)
11582 			num_normal++;
11583 		    else
11584 			(*file)[count++] = vim_strsave((char_u *)names[match]);
11585 		}
11586 	}
11587 	for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11588 								    opt_idx++)
11589 	{
11590 	    if (options[opt_idx].var == NULL)
11591 		continue;
11592 	    if (xp->xp_context == EXPAND_BOOL_SETTINGS
11593 	      && !(options[opt_idx].flags & P_BOOL))
11594 		continue;
11595 	    is_term_opt = istermoption(&options[opt_idx]);
11596 	    if (is_term_opt && num_normal > 0)
11597 		continue;
11598 	    match = FALSE;
11599 	    if (vim_regexec(regmatch, str, (colnr_T)0)
11600 		    || (options[opt_idx].shortname != NULL
11601 			&& vim_regexec(regmatch,
11602 			   (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11603 		match = TRUE;
11604 	    else if (is_term_opt)
11605 	    {
11606 		name_buf[0] = '<';
11607 		name_buf[1] = 't';
11608 		name_buf[2] = '_';
11609 		name_buf[3] = str[2];
11610 		name_buf[4] = str[3];
11611 		name_buf[5] = '>';
11612 		name_buf[6] = NUL;
11613 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11614 		{
11615 		    match = TRUE;
11616 		    str = name_buf;
11617 		}
11618 	    }
11619 	    if (match)
11620 	    {
11621 		if (loop == 0)
11622 		{
11623 		    if (is_term_opt)
11624 			num_term++;
11625 		    else
11626 			num_normal++;
11627 		}
11628 		else
11629 		    (*file)[count++] = vim_strsave(str);
11630 	    }
11631 	}
11632 	/*
11633 	 * Check terminal key codes, these are not in the option table
11634 	 */
11635 	if (xp->xp_context != EXPAND_BOOL_SETTINGS  && num_normal == 0)
11636 	{
11637 	    for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11638 	    {
11639 		if (!isprint(str[0]) || !isprint(str[1]))
11640 		    continue;
11641 
11642 		name_buf[0] = 't';
11643 		name_buf[1] = '_';
11644 		name_buf[2] = str[0];
11645 		name_buf[3] = str[1];
11646 		name_buf[4] = NUL;
11647 
11648 		match = FALSE;
11649 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11650 		    match = TRUE;
11651 		else
11652 		{
11653 		    name_buf[0] = '<';
11654 		    name_buf[1] = 't';
11655 		    name_buf[2] = '_';
11656 		    name_buf[3] = str[0];
11657 		    name_buf[4] = str[1];
11658 		    name_buf[5] = '>';
11659 		    name_buf[6] = NUL;
11660 
11661 		    if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11662 			match = TRUE;
11663 		}
11664 		if (match)
11665 		{
11666 		    if (loop == 0)
11667 			num_term++;
11668 		    else
11669 			(*file)[count++] = vim_strsave(name_buf);
11670 		}
11671 	    }
11672 
11673 	    /*
11674 	     * Check special key names.
11675 	     */
11676 	    regmatch->rm_ic = TRUE;		/* ignore case here */
11677 	    for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11678 	    {
11679 		name_buf[0] = '<';
11680 		STRCPY(name_buf + 1, str);
11681 		STRCAT(name_buf, ">");
11682 
11683 		if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11684 		{
11685 		    if (loop == 0)
11686 			num_term++;
11687 		    else
11688 			(*file)[count++] = vim_strsave(name_buf);
11689 		}
11690 	    }
11691 	}
11692 	if (loop == 0)
11693 	{
11694 	    if (num_normal > 0)
11695 		*num_file = num_normal;
11696 	    else if (num_term > 0)
11697 		*num_file = num_term;
11698 	    else
11699 		return OK;
11700 	    *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11701 	    if (*file == NULL)
11702 	    {
11703 		*file = (char_u **)"";
11704 		return FAIL;
11705 	    }
11706 	}
11707     }
11708     return OK;
11709 }
11710 
11711     int
11712 ExpandOldSetting(int *num_file, char_u ***file)
11713 {
11714     char_u  *var = NULL;	/* init for GCC */
11715     char_u  *buf;
11716 
11717     *num_file = 0;
11718     *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11719     if (*file == NULL)
11720 	return FAIL;
11721 
11722     /*
11723      * For a terminal key code expand_option_idx is < 0.
11724      */
11725     if (expand_option_idx < 0)
11726     {
11727 	var = find_termcode(expand_option_name + 2);
11728 	if (var == NULL)
11729 	    expand_option_idx = findoption(expand_option_name);
11730     }
11731 
11732     if (expand_option_idx >= 0)
11733     {
11734 	/* put string of option value in NameBuff */
11735 	option_value2string(&options[expand_option_idx], expand_option_flags);
11736 	var = NameBuff;
11737     }
11738     else if (var == NULL)
11739 	var = (char_u *)"";
11740 
11741     /* A backslash is required before some characters.  This is the reverse of
11742      * what happens in do_set(). */
11743     buf = vim_strsave_escaped(var, escape_chars);
11744 
11745     if (buf == NULL)
11746     {
11747 	vim_free(*file);
11748 	*file = NULL;
11749 	return FAIL;
11750     }
11751 
11752 #ifdef BACKSLASH_IN_FILENAME
11753     /* For MS-Windows et al. we don't double backslashes at the start and
11754      * before a file name character. */
11755     for (var = buf; *var != NUL; MB_PTR_ADV(var))
11756 	if (var[0] == '\\' && var[1] == '\\'
11757 		&& expand_option_idx >= 0
11758 		&& (options[expand_option_idx].flags & P_EXPAND)
11759 		&& vim_isfilec(var[2])
11760 		&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
11761 	    STRMOVE(var, var + 1);
11762 #endif
11763 
11764     *file[0] = buf;
11765     *num_file = 1;
11766     return OK;
11767 }
11768 #endif
11769 
11770 /*
11771  * Get the value for the numeric or string option *opp in a nice format into
11772  * NameBuff[].  Must not be called with a hidden option!
11773  */
11774     static void
11775 option_value2string(
11776     struct vimoption	*opp,
11777     int			opt_flags)	/* OPT_GLOBAL and/or OPT_LOCAL */
11778 {
11779     char_u	*varp;
11780 
11781     varp = get_varp_scope(opp, opt_flags);
11782 
11783     if (opp->flags & P_NUM)
11784     {
11785 	long wc = 0;
11786 
11787 	if (wc_use_keyname(varp, &wc))
11788 	    STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11789 	else if (wc != 0)
11790 	    STRCPY(NameBuff, transchar((int)wc));
11791 	else
11792 	    sprintf((char *)NameBuff, "%ld", *(long *)varp);
11793     }
11794     else    /* P_STRING */
11795     {
11796 	varp = *(char_u **)(varp);
11797 	if (varp == NULL)		    /* just in case */
11798 	    NameBuff[0] = NUL;
11799 #ifdef FEAT_CRYPT
11800 	/* don't show the actual value of 'key', only that it's set */
11801 	else if (opp->var == (char_u *)&p_key && *varp)
11802 	    STRCPY(NameBuff, "*****");
11803 #endif
11804 	else if (opp->flags & P_EXPAND)
11805 	    home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11806 	/* Translate 'pastetoggle' into special key names */
11807 	else if ((char_u **)opp->var == &p_pt)
11808 	    str2specialbuf(p_pt, NameBuff, MAXPATHL);
11809 	else
11810 	    vim_strncpy(NameBuff, varp, MAXPATHL - 1);
11811     }
11812 }
11813 
11814 /*
11815  * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11816  * printed as a keyname.
11817  * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11818  */
11819     static int
11820 wc_use_keyname(char_u *varp, long *wcp)
11821 {
11822     if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11823     {
11824 	*wcp = *(long *)varp;
11825 	if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11826 	    return TRUE;
11827     }
11828     return FALSE;
11829 }
11830 
11831 #if defined(FEAT_LANGMAP) || defined(PROTO)
11832 /*
11833  * Any character has an equivalent 'langmap' character.  This is used for
11834  * keyboards that have a special language mode that sends characters above
11835  * 128 (although other characters can be translated too).  The "to" field is a
11836  * Vim command character.  This avoids having to switch the keyboard back to
11837  * ASCII mode when leaving Insert mode.
11838  *
11839  * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11840  * commands.
11841  * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11842  * langmap_entry_T.  This does the same as langmap_mapchar[] for characters >=
11843  * 256.
11844  */
11845 # if defined(FEAT_MBYTE) || defined(PROTO)
11846 /*
11847  * With multi-byte support use growarray for 'langmap' chars >= 256
11848  */
11849 typedef struct
11850 {
11851     int	    from;
11852     int     to;
11853 } langmap_entry_T;
11854 
11855 static garray_T langmap_mapga;
11856 static void langmap_set_entry(int from, int to);
11857 
11858 /*
11859  * Search for an entry in "langmap_mapga" for "from".  If found set the "to"
11860  * field.  If not found insert a new entry at the appropriate location.
11861  */
11862     static void
11863 langmap_set_entry(int from, int to)
11864 {
11865     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11866     int		    a = 0;
11867     int		    b = langmap_mapga.ga_len;
11868 
11869     /* Do a binary search for an existing entry. */
11870     while (a != b)
11871     {
11872 	int i = (a + b) / 2;
11873 	int d = entries[i].from - from;
11874 
11875 	if (d == 0)
11876 	{
11877 	    entries[i].to = to;
11878 	    return;
11879 	}
11880 	if (d < 0)
11881 	    a = i + 1;
11882 	else
11883 	    b = i;
11884     }
11885 
11886     if (ga_grow(&langmap_mapga, 1) != OK)
11887 	return;  /* out of memory */
11888 
11889     /* insert new entry at position "a" */
11890     entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11891     mch_memmove(entries + 1, entries,
11892 			(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11893     ++langmap_mapga.ga_len;
11894     entries[0].from = from;
11895     entries[0].to = to;
11896 }
11897 
11898 /*
11899  * Apply 'langmap' to multi-byte character "c" and return the result.
11900  */
11901     int
11902 langmap_adjust_mb(int c)
11903 {
11904     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11905     int a = 0;
11906     int b = langmap_mapga.ga_len;
11907 
11908     while (a != b)
11909     {
11910 	int i = (a + b) / 2;
11911 	int d = entries[i].from - c;
11912 
11913 	if (d == 0)
11914 	    return entries[i].to;  /* found matching entry */
11915 	if (d < 0)
11916 	    a = i + 1;
11917 	else
11918 	    b = i;
11919     }
11920     return c;  /* no entry found, return "c" unmodified */
11921 }
11922 # endif
11923 
11924     static void
11925 langmap_init(void)
11926 {
11927     int i;
11928 
11929     for (i = 0; i < 256; i++)
11930 	langmap_mapchar[i] = i;	 /* we init with a one-to-one map */
11931 # ifdef FEAT_MBYTE
11932     ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11933 # endif
11934 }
11935 
11936 /*
11937  * Called when langmap option is set; the language map can be
11938  * changed at any time!
11939  */
11940     static void
11941 langmap_set(void)
11942 {
11943     char_u  *p;
11944     char_u  *p2;
11945     int	    from, to;
11946 
11947 #ifdef FEAT_MBYTE
11948     ga_clear(&langmap_mapga);		    /* clear the previous map first */
11949 #endif
11950     langmap_init();			    /* back to one-to-one map */
11951 
11952     for (p = p_langmap; p[0] != NUL; )
11953     {
11954 	for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11955 							       MB_PTR_ADV(p2))
11956 	{
11957 	    if (p2[0] == '\\' && p2[1] != NUL)
11958 		++p2;
11959 	}
11960 	if (p2[0] == ';')
11961 	    ++p2;	    /* abcd;ABCD form, p2 points to A */
11962 	else
11963 	    p2 = NULL;	    /* aAbBcCdD form, p2 is NULL */
11964 	while (p[0])
11965 	{
11966 	    if (p[0] == ',')
11967 	    {
11968 		++p;
11969 		break;
11970 	    }
11971 	    if (p[0] == '\\' && p[1] != NUL)
11972 		++p;
11973 #ifdef FEAT_MBYTE
11974 	    from = (*mb_ptr2char)(p);
11975 #else
11976 	    from = p[0];
11977 #endif
11978 	    to = NUL;
11979 	    if (p2 == NULL)
11980 	    {
11981 		MB_PTR_ADV(p);
11982 		if (p[0] != ',')
11983 		{
11984 		    if (p[0] == '\\')
11985 			++p;
11986 #ifdef FEAT_MBYTE
11987 		    to = (*mb_ptr2char)(p);
11988 #else
11989 		    to = p[0];
11990 #endif
11991 		}
11992 	    }
11993 	    else
11994 	    {
11995 		if (p2[0] != ',')
11996 		{
11997 		    if (p2[0] == '\\')
11998 			++p2;
11999 #ifdef FEAT_MBYTE
12000 		    to = (*mb_ptr2char)(p2);
12001 #else
12002 		    to = p2[0];
12003 #endif
12004 		}
12005 	    }
12006 	    if (to == NUL)
12007 	    {
12008 		EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12009 							     transchar(from));
12010 		return;
12011 	    }
12012 
12013 #ifdef FEAT_MBYTE
12014 	    if (from >= 256)
12015 		langmap_set_entry(from, to);
12016 	    else
12017 #endif
12018 		langmap_mapchar[from & 255] = to;
12019 
12020 	    /* Advance to next pair */
12021 	    MB_PTR_ADV(p);
12022 	    if (p2 != NULL)
12023 	    {
12024 		MB_PTR_ADV(p2);
12025 		if (*p == ';')
12026 		{
12027 		    p = p2;
12028 		    if (p[0] != NUL)
12029 		    {
12030 			if (p[0] != ',')
12031 			{
12032 			    EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12033 			    return;
12034 			}
12035 			++p;
12036 		    }
12037 		    break;
12038 		}
12039 	    }
12040 	}
12041     }
12042 }
12043 #endif
12044 
12045 /*
12046  * Return TRUE if format option 'x' is in effect.
12047  * Take care of no formatting when 'paste' is set.
12048  */
12049     int
12050 has_format_option(int x)
12051 {
12052     if (p_paste)
12053 	return FALSE;
12054     return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12055 }
12056 
12057 /*
12058  * Return TRUE if "x" is present in 'shortmess' option, or
12059  * 'shortmess' contains 'a' and "x" is present in SHM_A.
12060  */
12061     int
12062 shortmess(int x)
12063 {
12064     return p_shm != NULL &&
12065 	    (   vim_strchr(p_shm, x) != NULL
12066 	    || (vim_strchr(p_shm, 'a') != NULL
12067 		&& vim_strchr((char_u *)SHM_A, x) != NULL));
12068 }
12069 
12070 /*
12071  * paste_option_changed() - Called after p_paste was set or reset.
12072  */
12073     static void
12074 paste_option_changed(void)
12075 {
12076     static int	old_p_paste = FALSE;
12077     static int	save_sm = 0;
12078     static int	save_sta = 0;
12079 #ifdef FEAT_CMDL_INFO
12080     static int	save_ru = 0;
12081 #endif
12082 #ifdef FEAT_RIGHTLEFT
12083     static int	save_ri = 0;
12084     static int	save_hkmap = 0;
12085 #endif
12086     buf_T	*buf;
12087 
12088     if (p_paste)
12089     {
12090 	/*
12091 	 * Paste switched from off to on.
12092 	 * Save the current values, so they can be restored later.
12093 	 */
12094 	if (!old_p_paste)
12095 	{
12096 	    /* save options for each buffer */
12097 	    FOR_ALL_BUFFERS(buf)
12098 	    {
12099 		buf->b_p_tw_nopaste = buf->b_p_tw;
12100 		buf->b_p_wm_nopaste = buf->b_p_wm;
12101 		buf->b_p_sts_nopaste = buf->b_p_sts;
12102 		buf->b_p_ai_nopaste = buf->b_p_ai;
12103 		buf->b_p_et_nopaste = buf->b_p_et;
12104 	    }
12105 
12106 	    /* save global options */
12107 	    save_sm = p_sm;
12108 	    save_sta = p_sta;
12109 #ifdef FEAT_CMDL_INFO
12110 	    save_ru = p_ru;
12111 #endif
12112 #ifdef FEAT_RIGHTLEFT
12113 	    save_ri = p_ri;
12114 	    save_hkmap = p_hkmap;
12115 #endif
12116 	    /* save global values for local buffer options */
12117 	    p_ai_nopaste = p_ai;
12118 	    p_et_nopaste = p_et;
12119 	    p_sts_nopaste = p_sts;
12120 	    p_tw_nopaste = p_tw;
12121 	    p_wm_nopaste = p_wm;
12122 	}
12123 
12124 	/*
12125 	 * Always set the option values, also when 'paste' is set when it is
12126 	 * already on.
12127 	 */
12128 	/* set options for each buffer */
12129 	FOR_ALL_BUFFERS(buf)
12130 	{
12131 	    buf->b_p_tw = 0;	    /* textwidth is 0 */
12132 	    buf->b_p_wm = 0;	    /* wrapmargin is 0 */
12133 	    buf->b_p_sts = 0;	    /* softtabstop is 0 */
12134 	    buf->b_p_ai = 0;	    /* no auto-indent */
12135 	    buf->b_p_et = 0;	    /* no expandtab */
12136 	}
12137 
12138 	/* set global options */
12139 	p_sm = 0;		    /* no showmatch */
12140 	p_sta = 0;		    /* no smarttab */
12141 #ifdef FEAT_CMDL_INFO
12142 # ifdef FEAT_WINDOWS
12143 	if (p_ru)
12144 	    status_redraw_all();    /* redraw to remove the ruler */
12145 # endif
12146 	p_ru = 0;		    /* no ruler */
12147 #endif
12148 #ifdef FEAT_RIGHTLEFT
12149 	p_ri = 0;		    /* no reverse insert */
12150 	p_hkmap = 0;		    /* no Hebrew keyboard */
12151 #endif
12152 	/* set global values for local buffer options */
12153 	p_tw = 0;
12154 	p_wm = 0;
12155 	p_sts = 0;
12156 	p_ai = 0;
12157     }
12158 
12159     /*
12160      * Paste switched from on to off: Restore saved values.
12161      */
12162     else if (old_p_paste)
12163     {
12164 	/* restore options for each buffer */
12165 	FOR_ALL_BUFFERS(buf)
12166 	{
12167 	    buf->b_p_tw = buf->b_p_tw_nopaste;
12168 	    buf->b_p_wm = buf->b_p_wm_nopaste;
12169 	    buf->b_p_sts = buf->b_p_sts_nopaste;
12170 	    buf->b_p_ai = buf->b_p_ai_nopaste;
12171 	    buf->b_p_et = buf->b_p_et_nopaste;
12172 	}
12173 
12174 	/* restore global options */
12175 	p_sm = save_sm;
12176 	p_sta = save_sta;
12177 #ifdef FEAT_CMDL_INFO
12178 # ifdef FEAT_WINDOWS
12179 	if (p_ru != save_ru)
12180 	    status_redraw_all();    /* redraw to draw the ruler */
12181 # endif
12182 	p_ru = save_ru;
12183 #endif
12184 #ifdef FEAT_RIGHTLEFT
12185 	p_ri = save_ri;
12186 	p_hkmap = save_hkmap;
12187 #endif
12188 	/* set global values for local buffer options */
12189 	p_ai = p_ai_nopaste;
12190 	p_et = p_et_nopaste;
12191 	p_sts = p_sts_nopaste;
12192 	p_tw = p_tw_nopaste;
12193 	p_wm = p_wm_nopaste;
12194     }
12195 
12196     old_p_paste = p_paste;
12197 }
12198 
12199 /*
12200  * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12201  *
12202  * Reset 'compatible' and set the values for options that didn't get set yet
12203  * to the Vim defaults.
12204  * Don't do this if the 'compatible' option has been set or reset before.
12205  * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
12206  */
12207     void
12208 vimrc_found(char_u *fname, char_u *envname)
12209 {
12210     int		opt_idx;
12211     int		dofree = FALSE;
12212     char_u	*p;
12213 
12214     if (!option_was_set((char_u *)"cp"))
12215     {
12216 	p_cp = FALSE;
12217 	for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12218 	    if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12219 		set_option_default(opt_idx, OPT_FREE, FALSE);
12220 	didset_options();
12221 	didset_options2();
12222     }
12223 
12224     if (fname != NULL)
12225     {
12226 	p = vim_getenv(envname, &dofree);
12227 	if (p == NULL)
12228 	{
12229 	    /* Set $MYVIMRC to the first vimrc file found. */
12230 	    p = FullName_save(fname, FALSE);
12231 	    if (p != NULL)
12232 	    {
12233 		vim_setenv(envname, p);
12234 		vim_free(p);
12235 	    }
12236 	}
12237 	else if (dofree)
12238 	    vim_free(p);
12239     }
12240 }
12241 
12242 /*
12243  * Set 'compatible' on or off.  Called for "-C" and "-N" command line arg.
12244  */
12245     void
12246 change_compatible(int on)
12247 {
12248     int	    opt_idx;
12249 
12250     if (p_cp != on)
12251     {
12252 	p_cp = on;
12253 	compatible_set();
12254     }
12255     opt_idx = findoption((char_u *)"cp");
12256     if (opt_idx >= 0)
12257 	options[opt_idx].flags |= P_WAS_SET;
12258 }
12259 
12260 /*
12261  * Return TRUE when option "name" has been set.
12262  * Only works correctly for global options.
12263  */
12264     int
12265 option_was_set(char_u *name)
12266 {
12267     int idx;
12268 
12269     idx = findoption(name);
12270     if (idx < 0)	/* unknown option */
12271 	return FALSE;
12272     if (options[idx].flags & P_WAS_SET)
12273 	return TRUE;
12274     return FALSE;
12275 }
12276 
12277 /*
12278  * Reset the flag indicating option "name" was set.
12279  */
12280     void
12281 reset_option_was_set(char_u *name)
12282 {
12283     int idx = findoption(name);
12284 
12285     if (idx >= 0)
12286 	options[idx].flags &= ~P_WAS_SET;
12287 }
12288 
12289 /*
12290  * compatible_set() - Called when 'compatible' has been set or unset.
12291  *
12292  * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12293  * flag) to a Vi compatible value.
12294  * When 'compatible' is unset: Set all options that have a different default
12295  * for Vim (without the P_VI_DEF flag) to that default.
12296  */
12297     static void
12298 compatible_set(void)
12299 {
12300     int	    opt_idx;
12301 
12302     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12303 	if (	   ((options[opt_idx].flags & P_VIM) && p_cp)
12304 		|| (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12305 	    set_option_default(opt_idx, OPT_FREE, p_cp);
12306     didset_options();
12307     didset_options2();
12308 }
12309 
12310 #ifdef FEAT_LINEBREAK
12311 
12312 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12313    /* Borland C++ screws up loop optimisation here (negri) */
12314   #pragma option -O-l
12315 # endif
12316 
12317 /*
12318  * fill_breakat_flags() -- called when 'breakat' changes value.
12319  */
12320     static void
12321 fill_breakat_flags(void)
12322 {
12323     char_u	*p;
12324     int		i;
12325 
12326     for (i = 0; i < 256; i++)
12327 	breakat_flags[i] = FALSE;
12328 
12329     if (p_breakat != NULL)
12330 	for (p = p_breakat; *p; p++)
12331 	    breakat_flags[*p] = TRUE;
12332 }
12333 
12334 # if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12335   #pragma option -O.l
12336 # endif
12337 
12338 #endif
12339 
12340 /*
12341  * Check an option that can be a range of string values.
12342  *
12343  * Return OK for correct value, FAIL otherwise.
12344  * Empty is always OK.
12345  */
12346     static int
12347 check_opt_strings(
12348     char_u	*val,
12349     char	**values,
12350     int		list)	    /* when TRUE: accept a list of values */
12351 {
12352     return opt_strings_flags(val, values, NULL, list);
12353 }
12354 
12355 /*
12356  * Handle an option that can be a range of string values.
12357  * Set a flag in "*flagp" for each string present.
12358  *
12359  * Return OK for correct value, FAIL otherwise.
12360  * Empty is always OK.
12361  */
12362     static int
12363 opt_strings_flags(
12364     char_u	*val,		/* new value */
12365     char	**values,	/* array of valid string values */
12366     unsigned	*flagp,
12367     int		list)		/* when TRUE: accept a list of values */
12368 {
12369     int		i;
12370     int		len;
12371     unsigned	new_flags = 0;
12372 
12373     while (*val)
12374     {
12375 	for (i = 0; ; ++i)
12376 	{
12377 	    if (values[i] == NULL)	/* val not found in values[] */
12378 		return FAIL;
12379 
12380 	    len = (int)STRLEN(values[i]);
12381 	    if (STRNCMP(values[i], val, len) == 0
12382 		    && ((list && val[len] == ',') || val[len] == NUL))
12383 	    {
12384 		val += len + (val[len] == ',');
12385 		new_flags |= (1 << i);
12386 		break;		/* check next item in val list */
12387 	    }
12388 	}
12389     }
12390     if (flagp != NULL)
12391 	*flagp = new_flags;
12392 
12393     return OK;
12394 }
12395 
12396 /*
12397  * Read the 'wildmode' option, fill wim_flags[].
12398  */
12399     static int
12400 check_opt_wim(void)
12401 {
12402     char_u	new_wim_flags[4];
12403     char_u	*p;
12404     int		i;
12405     int		idx = 0;
12406 
12407     for (i = 0; i < 4; ++i)
12408 	new_wim_flags[i] = 0;
12409 
12410     for (p = p_wim; *p; ++p)
12411     {
12412 	for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12413 	    ;
12414 	if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12415 	    return FAIL;
12416 	if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12417 	    new_wim_flags[idx] |= WIM_LONGEST;
12418 	else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12419 	    new_wim_flags[idx] |= WIM_FULL;
12420 	else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12421 	    new_wim_flags[idx] |= WIM_LIST;
12422 	else
12423 	    return FAIL;
12424 	p += i;
12425 	if (*p == NUL)
12426 	    break;
12427 	if (*p == ',')
12428 	{
12429 	    if (idx == 3)
12430 		return FAIL;
12431 	    ++idx;
12432 	}
12433     }
12434 
12435     /* fill remaining entries with last flag */
12436     while (idx < 3)
12437     {
12438 	new_wim_flags[idx + 1] = new_wim_flags[idx];
12439 	++idx;
12440     }
12441 
12442     /* only when there are no errors, wim_flags[] is changed */
12443     for (i = 0; i < 4; ++i)
12444 	wim_flags[i] = new_wim_flags[i];
12445     return OK;
12446 }
12447 
12448 /*
12449  * Check if backspacing over something is allowed.
12450  */
12451     int
12452 can_bs(
12453     int		what)	    /* BS_INDENT, BS_EOL or BS_START */
12454 {
12455     switch (*p_bs)
12456     {
12457 	case '2':	return TRUE;
12458 	case '1':	return (what != BS_START);
12459 	case '0':	return FALSE;
12460     }
12461     return vim_strchr(p_bs, what) != NULL;
12462 }
12463 
12464 /*
12465  * Save the current values of 'fileformat' and 'fileencoding', so that we know
12466  * the file must be considered changed when the value is different.
12467  */
12468     void
12469 save_file_ff(buf_T *buf)
12470 {
12471     buf->b_start_ffc = *buf->b_p_ff;
12472     buf->b_start_eol = buf->b_p_eol;
12473 #ifdef FEAT_MBYTE
12474     buf->b_start_bomb = buf->b_p_bomb;
12475 
12476     /* Only use free/alloc when necessary, they take time. */
12477     if (buf->b_start_fenc == NULL
12478 			     || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12479     {
12480 	vim_free(buf->b_start_fenc);
12481 	buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12482     }
12483 #endif
12484 }
12485 
12486 /*
12487  * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12488  * from when editing started (save_file_ff() called).
12489  * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12490  * changed and 'binary' is not set.
12491  * Also when 'endofline' was changed and 'fixeol' is not set.
12492  * When "ignore_empty" is true don't consider a new, empty buffer to be
12493  * changed.
12494  */
12495     int
12496 file_ff_differs(buf_T *buf, int ignore_empty)
12497 {
12498     /* In a buffer that was never loaded the options are not valid. */
12499     if (buf->b_flags & BF_NEVERLOADED)
12500 	return FALSE;
12501     if (ignore_empty
12502 	    && (buf->b_flags & BF_NEW)
12503 	    && buf->b_ml.ml_line_count == 1
12504 	    && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12505 	return FALSE;
12506     if (buf->b_start_ffc != *buf->b_p_ff)
12507 	return TRUE;
12508     if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
12509 	return TRUE;
12510 #ifdef FEAT_MBYTE
12511     if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12512 	return TRUE;
12513     if (buf->b_start_fenc == NULL)
12514 	return (*buf->b_p_fenc != NUL);
12515     return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12516 #else
12517     return FALSE;
12518 #endif
12519 }
12520 
12521 /*
12522  * return OK if "p" is a valid fileformat name, FAIL otherwise.
12523  */
12524     int
12525 check_ff_value(char_u *p)
12526 {
12527     return check_opt_strings(p, p_ff_values, FALSE);
12528 }
12529 
12530 /*
12531  * Return the effective shiftwidth value for current buffer, using the
12532  * 'tabstop' value when 'shiftwidth' is zero.
12533  */
12534     long
12535 get_sw_value(buf_T *buf)
12536 {
12537     return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
12538 }
12539 
12540 /*
12541  * Return the effective softtabstop value for the current buffer, using the
12542  * 'tabstop' value when 'softtabstop' is negative.
12543  */
12544     long
12545 get_sts_value(void)
12546 {
12547     return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
12548 }
12549 
12550 /*
12551  * Check matchpairs option for "*initc".
12552  * If there is a match set "*initc" to the matching character and "*findc" to
12553  * the opposite character.  Set "*backwards" to the direction.
12554  * When "switchit" is TRUE swap the direction.
12555  */
12556     void
12557 find_mps_values(
12558     int	    *initc,
12559     int	    *findc,
12560     int	    *backwards,
12561     int	    switchit)
12562 {
12563     char_u	*ptr;
12564 
12565     ptr = curbuf->b_p_mps;
12566     while (*ptr != NUL)
12567     {
12568 #ifdef FEAT_MBYTE
12569 	if (has_mbyte)
12570 	{
12571 	    char_u *prev;
12572 
12573 	    if (mb_ptr2char(ptr) == *initc)
12574 	    {
12575 		if (switchit)
12576 		{
12577 		    *findc = *initc;
12578 		    *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12579 		    *backwards = TRUE;
12580 		}
12581 		else
12582 		{
12583 		    *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12584 		    *backwards = FALSE;
12585 		}
12586 		return;
12587 	    }
12588 	    prev = ptr;
12589 	    ptr += mb_ptr2len(ptr) + 1;
12590 	    if (mb_ptr2char(ptr) == *initc)
12591 	    {
12592 		if (switchit)
12593 		{
12594 		    *findc = *initc;
12595 		    *initc = mb_ptr2char(prev);
12596 		    *backwards = FALSE;
12597 		}
12598 		else
12599 		{
12600 		    *findc = mb_ptr2char(prev);
12601 		    *backwards = TRUE;
12602 		}
12603 		return;
12604 	    }
12605 	    ptr += mb_ptr2len(ptr);
12606 	}
12607 	else
12608 #endif
12609 	{
12610 	    if (*ptr == *initc)
12611 	    {
12612 		if (switchit)
12613 		{
12614 		    *backwards = TRUE;
12615 		    *findc = *initc;
12616 		    *initc = ptr[2];
12617 		}
12618 		else
12619 		{
12620 		    *backwards = FALSE;
12621 		    *findc = ptr[2];
12622 		}
12623 		return;
12624 	    }
12625 	    ptr += 2;
12626 	    if (*ptr == *initc)
12627 	    {
12628 		if (switchit)
12629 		{
12630 		    *backwards = FALSE;
12631 		    *findc = *initc;
12632 		    *initc = ptr[-2];
12633 		}
12634 		else
12635 		{
12636 		    *backwards = TRUE;
12637 		    *findc =  ptr[-2];
12638 		}
12639 		return;
12640 	    }
12641 	    ++ptr;
12642 	}
12643 	if (*ptr == ',')
12644 	    ++ptr;
12645     }
12646 }
12647 
12648 #if defined(FEAT_LINEBREAK) || defined(PROTO)
12649 /*
12650  * This is called when 'breakindentopt' is changed and when a window is
12651  * initialized.
12652  */
12653     static int
12654 briopt_check(win_T *wp)
12655 {
12656     char_u	*p;
12657     int		bri_shift = 0;
12658     long	bri_min = 20;
12659     int		bri_sbr = FALSE;
12660 
12661     p = wp->w_p_briopt;
12662     while (*p != NUL)
12663     {
12664 	if (STRNCMP(p, "shift:", 6) == 0
12665 		 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12666 	{
12667 	    p += 6;
12668 	    bri_shift = getdigits(&p);
12669 	}
12670 	else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12671 	{
12672 	    p += 4;
12673 	    bri_min = getdigits(&p);
12674 	}
12675 	else if (STRNCMP(p, "sbr", 3) == 0)
12676 	{
12677 	    p += 3;
12678 	    bri_sbr = TRUE;
12679 	}
12680 	if (*p != ',' && *p != NUL)
12681 	    return FAIL;
12682 	if (*p == ',')
12683 	    ++p;
12684     }
12685 
12686     wp->w_p_brishift = bri_shift;
12687     wp->w_p_brimin   = bri_min;
12688     wp->w_p_brisbr   = bri_sbr;
12689 
12690     return OK;
12691 }
12692 #endif
12693 
12694 /*
12695  * Get the local or global value of 'backupcopy'.
12696  */
12697     unsigned int
12698 get_bkc_value(buf_T *buf)
12699 {
12700     return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12701 }
12702 
12703 #if defined(FEAT_SIGNS) || defined(PROTO)
12704 /*
12705  * Return TRUE when window "wp" has a column to draw signs in.
12706  */
12707      int
12708 signcolumn_on(win_T *wp)
12709 {
12710     if (*wp->w_p_scl == 'n')
12711 	return FALSE;
12712     if (*wp->w_p_scl == 'y')
12713 	return TRUE;
12714     return (wp->w_buffer->b_signlist != NULL
12715 # ifdef FEAT_NETBEANS_INTG
12716 			|| wp->w_buffer->b_has_sign_column
12717 # endif
12718 		    );
12719 }
12720 #endif
12721 
12722 #if defined(FEAT_EVAL) || defined(PROTO)
12723 /*
12724  * Get window or buffer local options.
12725  */
12726     dict_T *
12727 get_winbuf_options(int bufopt)
12728 {
12729     dict_T	*d;
12730     int		opt_idx;
12731 
12732     d = dict_alloc();
12733     if (d == NULL)
12734 	return NULL;
12735 
12736     for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12737     {
12738 	struct vimoption *opt = &options[opt_idx];
12739 
12740 	if ((bufopt && (opt->indir & PV_BUF))
12741 					 || (!bufopt && (opt->indir & PV_WIN)))
12742 	{
12743 	    char_u *varp = get_varp(opt);
12744 
12745 	    if (varp != NULL)
12746 	    {
12747 		if (opt->flags & P_STRING)
12748 		    dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
12749 		else if (opt->flags & P_NUM)
12750 		    dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
12751 		else
12752 		    dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
12753 	    }
12754 	}
12755     }
12756 
12757     return d;
12758 }
12759 #endif
12760