⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 option.c

📁 VIM文本编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
/* vi:set ts=8 sts=4 sw=4:
 *
 * VIM - Vi IMproved	by Bram Moolenaar
 *
 * Do ":help uganda"  in Vim to read copying and usage conditions.
 * Do ":help credits" in Vim to see a list of people who contributed.
 */

/*
 * Code to handle user-settable options. This is all pretty much table-
 * driven. Checklist for adding a new option:
 * - Put it in the options array below (copy an existing entry).
 * - For a global option: Add a variable for it in option.h.
 * - For a buffer or window local option:
 *   - Add a PV_XX entry to the enum below.
 *   - Add a variable to the window or buffer struct in structs.h.
 *   - For a window option, add some code to win_copy_options().
 *   - For a buffer option, add some code to buf_copy_options().
 *   - For a buffer string option, add code to check_buf_options().
 * - If it's a numeric option, add any necessary bounds checks to do_set().
 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
 * - When adding an option with expansion (P_EXPAND), but with a different
 *   default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
 * - Add documentation!  One line in doc/help.txt, full description in
 *   options.txt, and any other related places.
 */

#include "vim.h"

struct vimoption
{
    char	*fullname;	/* full option name */
    char	*shortname;	/* permissible abbreviation */
    short_u	flags;		/* see below */
    char_u	*var;		/* pointer to variable */
    char_u	*def_val[2];	/* default values for variable (vi and vim) */
};

#define VI_DEFAULT  0	    /* def_val[VI_DEFAULT] is Vi default value */
#define VIM_DEFAULT 1	    /* def_val[VIM_DEFAULT] is Vim default value */

/*
 * Flags
 *
 * Note: P_EXPAND and P_IND can never be used at the same time.
 * Note: P_IND cannot be used for a terminal option.
 */
#define P_BOOL		0x01	/* the option is boolean */
#define P_NUM		0x02	/* the option is numeric */
#define P_STRING	0x04	/* the option is a string */
#define P_ALLOCED	0x08	/* the string option is in allocated memory,
				    must use vim_free() when assigning new
				    value. Not set if default is the same. */
#define P_EXPAND	0x10	/* environment expansion */
#define P_IND		0x20	/* indirect, is in curwin or curbuf */
#define P_NODEFAULT	0x40	/* has no default value */
#define P_DEF_ALLOCED	0x80	/* default value is in allocated memory, must
				    use vim_free() when assigning new value */
#define P_WAS_SET	0x100	/* option has been set/reset */
#define P_NO_MKRC	0x200	/* don't include in :mkvimrc output */
#define P_VI_DEF	0x400	/* Use Vi default for Vim */
#define P_VIM		0x800	/* Vim option, reset when 'cp' set */

#define P_RSTAT		0x1000	/* when changed, redraw status lines */
#define P_RBUF		0x2000	/* when changed, redraw current buffer */
#define P_RALL		0x4000	/* when changed, redraw all */
#define P_COMMA		0x8000	/* comma separated list */

/*
 * The options that are in curwin or curbuf have P_IND set and a var field
 * that contains one of the enum values below.
 */
enum indirect_options
{
    PV_AI = 1,
    PV_BIN,
    PV_CIN,
    PV_CINK,
    PV_CINO,
    PV_CINW,
    PV_COM,
    PV_CPT,
    PV_EOL,
    PV_ET,
    PV_FE,
    PV_FF,
    PV_FO,
    PV_FT,
    PV_INF,
    PV_ISK,
    PV_LBR,
    PV_LISP,
    PV_LIST,
    PV_ML,
    PV_MPS,
    PV_MOD,
    PV_NF,
    PV_NU,
    PV_RL,
    PV_RO,
    PV_SCROLL,
    PV_SI,
    PV_SN,
    PV_STS,
    PV_SWF,
    PV_SYN,
    PV_SW,
    PV_TS,
    PV_TW,
    PV_TX,
    PV_WM,
    PV_WRAP
};

/*
 * options[] is initialized here.
 * The order of the options MUST be alphabetic for ":set all" and findoption().
 * All option names MUST start with a lowercase letter (for findoption()).
 * Exception: "t_" options are at the end.
 * The options with a NULL variable are 'hidden': a set command for them is
 * ignored and they are not printed.
 */
static struct vimoption options[] =
{
    {"aleph",	    "al",   P_NUM|P_VI_DEF,
#ifdef RIGHTLEFT
			    (char_u *)&p_aleph,
#else
			    (char_u *)NULL,
#endif
			    {
#if (defined(MSDOS) || defined(WIN32) || defined(OS2)) && !defined(USE_GUI_WIN32)
			    (char_u *)128L,
#else
			    (char_u *)224L,
#endif
					    (char_u *)0L}},
    {"allowrevins", "ari",  P_BOOL|P_VI_DEF|P_VIM,
#ifdef RIGHTLEFT
			    (char_u *)&p_ari,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"altkeymap",   "akm",  P_BOOL|P_VI_DEF,
#ifdef FKMAP
			    (char_u *)&p_altkeymap,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"autoindent",  "ai",   P_BOOL|P_IND|P_VI_DEF,
			    (char_u *)PV_AI,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
			    (char_u *)NULL,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"autowrite",   "aw",   P_BOOL|P_VI_DEF,
			    (char_u *)&p_aw,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"background",  "bg",   P_STRING|P_VI_DEF|P_RALL,
			    (char_u *)&p_bg,
			    {
#if (defined(MSDOS) || defined(OS2) || defined(WIN32)) && !defined(USE_GUI)
			    (char_u *)"dark",
#else
			    (char_u *)"light",
#endif
					    (char_u *)0L}},
    {"backspace",   "bs",   P_NUM|P_VI_DEF|P_VIM,
			    (char_u *)&p_bs,
			    {(char_u *)0L, (char_u *)0L}},
    {"backup",	    "bk",   P_BOOL|P_VI_DEF|P_VIM,
			    (char_u *)&p_bk,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"backupdir",   "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA,
			    (char_u *)&p_bdir,
			    {(char_u *)DEF_BDIR, (char_u *)0L}},
    {"backupext",   "bex",  P_STRING|P_VI_DEF,
			    (char_u *)&p_bex,
			    {
#ifdef VMS
			    (char_u *)"_",
#else
			    (char_u *)"~",
#endif
					    (char_u *)0L}},
    {"beautify",    "bf",   P_BOOL|P_VI_DEF,
			    (char_u *)NULL,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"binary",	    "bin",  P_BOOL|P_IND|P_VI_DEF|P_RSTAT,
			    (char_u *)PV_BIN,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"bioskey",	    "biosk",P_BOOL|P_VI_DEF,
#ifdef MSDOS
			    (char_u *)&p_biosk,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)TRUE, (char_u *)0L}},
    {"breakat",	    "brk",  P_STRING|P_VI_DEF|P_RALL,
			    (char_u *)&p_breakat,
			    {(char_u *)" \t!@*-+_;:,./?", (char_u *)0L}},
    {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
#ifdef USE_BROWSE
			    (char_u *)&p_bsdir,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)"last", (char_u *)0L}},
    {"cindent",	    "cin",  P_BOOL|P_IND|P_VI_DEF|P_VIM,
#ifdef CINDENT
			    (char_u *)PV_CIN,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"cinkeys",	    "cink", P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_COMMA,
#ifdef CINDENT
			    (char_u *)PV_CINK,
			    {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"cinoptions",  "cino", P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_COMMA,
#ifdef CINDENT
			    (char_u *)PV_CINO,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)"", (char_u *)0L}},
    {"cinwords",    "cinw", P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_COMMA,
#if defined(SMARTINDENT) || defined(CINDENT)
			    (char_u *)PV_CINW,
			    {(char_u *)"if,else,while,do,for,switch",
				(char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
			    (char_u *)&p_ch,
			    {(char_u *)1L, (char_u *)0L}},
    {"columns",	    "co",   P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
			    (char_u *)&Columns,
			    {(char_u *)80L, (char_u *)0L}},
    {"comments",    "com",  P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_COMMA,
			    (char_u *)PV_COM,
			    {(char_u *)"sr:/*,mb:*,el:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
				(char_u *)0L}},
    {"compatible",  "cp",   P_BOOL|P_RALL,
			    (char_u *)&p_cp,
			    {(char_u *)TRUE, (char_u *)FALSE}},
    {"complete",    "cpt",  P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_COMMA,
#ifdef INSERT_EXPAND
			    (char_u *)PV_CPT,
			    {(char_u *)".,b", (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"confirm",     "cf",   P_BOOL|P_VI_DEF,
#if defined(GUI_DIALOG) || defined(CON_DIALOG)
			    (char_u *)&p_confirm,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"cpoptions",   "cpo",  P_STRING|P_VIM|P_RALL,
			    (char_u *)&p_cpo,
			    {(char_u *)CPO_ALL, (char_u *)CPO_DEFAULT}},
    {"cscopeprg",   "csprg", P_STRING|P_EXPAND|P_VI_DEF,
#ifdef USE_CSCOPE
			    (char_u *)&p_csprg,
			    {(char_u *)"cscope", (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"cscopetag",   "cst",  P_BOOL|P_VI_DEF|P_VIM,
#ifdef USE_CSCOPE
			    (char_u *)&p_cst,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)0L, (char_u *)0L}},
    {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
#ifdef USE_CSCOPE
			    (char_u *)&p_csto,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)0L, (char_u *)0L}},
    {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
#ifdef USE_CSCOPE
			    (char_u *)&p_csverbose,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)0L, (char_u *)0L}},
    {"define",	    "def",  P_STRING|P_VI_DEF,
			    (char_u *)&p_def,
			    {(char_u *)"^#\\s*define", (char_u *)0L}},
    {"dictionary",  "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA,
			    (char_u *)&p_dict,
			    {(char_u *)"", (char_u *)0L}},
    {"digraph",	    "dg",   P_BOOL|P_VI_DEF|P_VIM,
#ifdef DIGRAPHS
			    (char_u *)&p_dg,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"directory",   "dir",  P_STRING|P_EXPAND|P_VI_DEF|P_COMMA,
			    (char_u *)&p_dir,
			    {(char_u *)DEF_DIR, (char_u *)0L}},
    {"edcompatible","ed",   P_BOOL|P_VI_DEF,
			    (char_u *)&p_ed,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"endofline",   "eol",  P_BOOL|P_IND|P_NO_MKRC|P_VI_DEF|P_RSTAT,
			    (char_u *)PV_EOL,
			    {(char_u *)TRUE, (char_u *)0L}},
    {"equalalways", "ea",   P_BOOL|P_VI_DEF|P_RALL,
			    (char_u *)&p_ea,
			    {(char_u *)TRUE, (char_u *)0L}},
    {"equalprg",    "ep",   P_STRING|P_EXPAND|P_VI_DEF,
			    (char_u *)&p_ep,
			    {(char_u *)"", (char_u *)0L}},
    {"errorbells",  "eb",   P_BOOL|P_VI_DEF,
			    (char_u *)&p_eb,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"errorfile",   "ef",   P_STRING|P_EXPAND|P_VI_DEF,
#ifdef QUICKFIX
			    (char_u *)&p_ef,
			    {(char_u *)ERRORFILE, (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)NULL, (char_u *)0L}
#endif
			    },
    {"errorformat", "efm",  P_STRING|P_VI_DEF|P_COMMA,
#ifdef QUICKFIX
			    (char_u *)&p_efm,
			    {(char_u *)EFM_DFLT, (char_u *)0L},
#else
			    (char_u *)NULL,
			    {(char_u *)NULL, (char_u *)0L}
#endif
			    },
    {"esckeys",	    "ek",   P_BOOL|P_VIM,
			    (char_u *)&p_ek,
			    {(char_u *)FALSE, (char_u *)TRUE}},
    {"eventignore", "ei",   P_STRING|P_VI_DEF|P_COMMA,
#ifdef AUTOCMD
			    (char_u *)&p_ei,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)"", (char_u *)0L}},
    {"expandtab",   "et",   P_BOOL|P_IND|P_VI_DEF|P_VIM,
			    (char_u *)PV_ET,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"exrc",	    "ex",   P_BOOL|P_VI_DEF,
			    (char_u *)&p_exrc,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"fileencoding", "fe",   P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_RSTAT,
#ifdef MULTI_BYTE
			    (char_u *)PV_FE,
			    {(char_u *)FE_DFLT, (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"fileformat",  "ff",   P_STRING|P_IND|P_ALLOCED|P_VI_DEF|P_RSTAT,
			    (char_u *)PV_FF,
			    {(char_u *)FF_DFLT, (char_u *)0L}},
    {"fileformats", "ffs",  P_STRING|P_VIM|P_COMMA,
			    (char_u *)&p_ffs,
			    {(char_u *)FFS_VI, (char_u *)FFS_DFLT}},
    {"filetype", "ft",	    P_STRING|P_IND|P_ALLOCED|P_VI_DEF,
#ifdef WANT_FILETYPE
			    (char_u *)PV_FT,
			    {(char_u *)FT_DFLT, (char_u *)0L}
#else
			    (char_u *)NULL,
			    {(char_u *)0L, (char_u *)0L}
#endif
			    },
    {"fkmap",	    "fk",   P_BOOL|P_VI_DEF,
#ifdef FKMAP
			    (char_u *)&p_fkmap,
#else
			    (char_u *)NULL,
#endif
			    {(char_u *)FALSE, (char_u *)0L}},
    {"flash",	    "fl",   P_BOOL|P_VI_DEF,
			    (char_u *)NULL,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"formatoptions","fo",  P_STRING|P_IND|P_ALLOCED|P_VIM,
			    (char_u *)PV_FO,
			    {(char_u *)FO_DFLT_VI, (char_u *)FO_DFLT}},
    {"formatprg",   "fp",   P_STRING|P_EXPAND|P_VI_DEF,
			    (char_u *)&p_fp,
			    {(char_u *)"", (char_u *)0L}},
    {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
			    (char_u *)&p_gd,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"graphic",	    "gr",   P_BOOL|P_VI_DEF,
			    (char_u *)NULL,
			    {(char_u *)FALSE, (char_u *)0L}},
    {"grepformat",  "gfm",  P_STRING|P_VI_DEF|P_COMMA,
#ifdef QUICKFIX
			    (char_u *)&p_gefm,
			    {(char_u *)GEFM_DFLT, (char_u *)0L},
#else
			    (char_u *)NULL,
			    {(char_u *)NULL, (char_u *)0L}
#endif
			    },
    {"grepprg",	    "gp",   P_STRING|P_EXPAND|P_VI_DEF,
#ifdef QUICKFIX
			    (char_u *)&p_gp,
			    {
# ifdef WIN32
			    (char_u *)"findstr /n",
# else
			    (char_u *)"grep -n",
# endif
			    (char_u *)0L},
#else
			    (char_u *)NULL,
			    {(char_u *)NULL, (char_u *)0L}
#endif
			    },
    {"guicursor",    "gcr",  P_STRING|P_VI_DEF|P_COMMA,
#ifdef CURSOR_SHAPE
			    (char_u *)&p_guicursor,
			    {
# ifdef USE_GUI
				(char_u *)"n-v-c:block-Cursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor,r-cr:hor20-Cursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
# else	/* MSDOS or Win32 console */
				(char_u *)"n-v-c:block,o:hor50,i-ci:hor10,r-cr:hor30,sm:block",
# endif
				    (char_u *)0L}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -