📄 main.c
字号:
case 'e': /* "-e" Ex mode */
exmode_active = TRUE;
break;
case 'f': /* "-f" GUI: run in foreground. Amiga: open
window directly, not with newcli */
#ifdef USE_GUI
gui.dofork = FALSE; /* don't fork() when starting GUI */
#endif
break;
case 'g': /* "-g" start GUI */
#ifdef USE_GUI
gui.starting = TRUE; /* start GUI a bit later */
#else
mch_errmsg((char *)e_nogvim);
mch_windexit(2);
#endif
break;
case 'F': /* "-F" start in Farsi mode: rl + fkmap set */
#ifdef FKMAP
curwin->w_p_rl = p_fkmap = TRUE;
#else
mch_errmsg((char *)e_nofarsi);
mch_windexit(2);
#endif
break;
case 'h': /* "-h" give help message */
usage();
break;
case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */
#ifdef RIGHTLEFT
curwin->w_p_rl = p_hkmap = TRUE;
#else
mch_errmsg((char *)e_nohebrew);
mch_windexit(2);
#endif
break;
case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */
#ifdef LISPINDENT
curbuf->b_p_lisp = TRUE;
p_sm = TRUE;
#endif
break;
case 'N': /* "-N" Nocompatible */
change_compatible(FALSE);
break;
case 'n': /* "-n" no swap file */
no_swap_file = TRUE;
break;
case 'o': /* "-o[N]" open N windows */
/* default is 0: open window for each file */
window_count = get_number_arg((char_u *)argv[0], &argv_idx, 0);
break;
#ifdef QUICKFIX
case 'q': /* "-q" QuickFix mode */
if (edit_type != EDIT_NONE)
mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
edit_type = EDIT_QF;
if (argv[0][argv_idx]) /* "-q{errorfile}" */
{
use_ef = (char_u *)argv[0] + argv_idx;
argv_idx = -1;
}
else if (argc > 1) /* "-q {errorfile}" */
want_argument = TRUE;
break;
#endif
case 'R': /* "-R" readonly mode */
readonlymode = TRUE;
curbuf->b_p_ro = TRUE;
p_uc = 10000; /* don't update very often */
break;
case 'r': /* "-r" recovery mode */
case 'L': /* "-L" recovery mode */
recoverymode = 1;
break;
case 's':
if (exmode_active) /* "-s" silent (batch) mode */
silent_mode = TRUE;
else /* "-s {scriptin}" read from script file */
want_argument = TRUE;
break;
case 't': /* "-t {tag}" or "-t{tag}" jump to tag */
if (edit_type != EDIT_NONE)
mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
edit_type = EDIT_TAG;
if (argv[0][argv_idx]) /* "-t{tag}" */
{
tagname = (char_u *)argv[0] + argv_idx;
argv_idx = -1;
}
else /* "-t {tag}" */
want_argument = TRUE;
break;
case 'V': /* "-V{N}" Verbose level */
/* default is 10: a little bit verbose */
p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10);
break;
case 'v': /* "-v" Vi-mode (as if called "vi") */
exmode_active = FALSE;
break;
case 'w': /* "-w{number}" set window height */
/* "-w {scriptout}" write to script */
if (isdigit(((char_u *)argv[0])[argv_idx]))
{
argv_idx = -1;
break; /* not implemented, ignored */
}
want_argument = TRUE;
break;
case 'x': /* "-x" use "crypt" for reading/writing files. */
/* TODO */
break;
case 'Z': /* "-Z" restricted mode */
restricted = TRUE;
break;
case 'c': /* "-c {command}" execute command */
case 'd': /* "-d {device}" device (for Amiga) */
case 'i': /* "-i {viminfo}" use for viminfo */
case 'T': /* "-T {terminal}" terminal name */
case 'u': /* "-u {vimrc}" vim inits file */
case 'U': /* "-U {gvimrc}" gvim inits file */
case 'W': /* "-W {scriptout}" overwrite */
want_argument = TRUE;
break;
default:
mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]);
}
/*
* Handle options with argument.
*/
if (want_argument)
{
/*
* Check for garbage immediately after the option letter.
*/
if (argv[0][argv_idx] != NUL)
mainerr(ME_GARBAGE, (char_u *)argv[0]);
--argc;
if (argc < 1)
mainerr(ME_ARG_MISSING, (char_u *)argv[0]);
++argv;
argv_idx = -1;
switch (c)
{
case 'c': /* "-c {command}" execute command */
if (n_commands >= MAX_ARG_CMDS)
mainerr(ME_EXTRA_CMD, NULL);
commands[n_commands++] = (char_u *)argv[0];
break;
/* case 'd': This is handled in mch_check_win() */
#ifdef QUICKFIX
case 'q': /* "-q {errorfile}" QuickFix mode */
use_ef = (char_u *)argv[0];
break;
#endif
case 'i': /* "-i {viminfo}" use for viminfo */
use_viminfo = (char_u *)argv[0];
break;
case 's': /* "-s {scriptin}" read from script file */
if (scriptin[0] != NULL)
{
mch_errmsg("Attempt to open script file again: \"");
mch_errmsg(argv[-1]);
mch_errmsg(" ");
mch_errmsg(argv[0]);
mch_errmsg("\"\n");
mch_windexit(2);
}
if ((scriptin[0] = fopen(argv[0], READBIN)) == NULL)
{
mch_errmsg("Cannot open \"");
mch_errmsg(argv[0]);
mch_errmsg("\" for reading\n");
mch_windexit(2);
}
if (save_typebuf() == FAIL)
mch_windexit(2); /* out of memory */
break;
case 't': /* "-t {tag}" */
tagname = (char_u *)argv[0];
break;
case 'T': /* "-T {terminal}" terminal name */
/*
* The -T term option is always available and when
* HAVE_TERMLIB is supported it overrides the environment
* variable TERM.
*/
#ifdef USE_GUI
if (term_is_gui((char_u *)argv[0]))
gui.starting = TRUE; /* start GUI a bit later */
else
#endif
term = (char_u *)argv[0];
break;
case 'u': /* "-u {vimrc}" vim inits file */
use_vimrc = (char_u *)argv[0];
break;
case 'U': /* "-U {gvimrc}" gvim inits file */
use_gvimrc = (char_u *)argv[0];
break;
case 'w': /* "-w {scriptout}" append to script file */
case 'W': /* "-W {scriptout}" overwrite script file */
if (scriptout != NULL)
{
mch_errmsg("Attempt to open script file again: \"");
mch_errmsg(argv[-1]);
mch_errmsg(" ");
mch_errmsg(argv[0]);
mch_errmsg("\"\n");
mch_windexit(2);
}
if ((scriptout = fopen(argv[0],
c == 'w' ? APPENDBIN : WRITEBIN)) == NULL)
{
mch_errmsg("cannot open \"");
mch_errmsg(argv[0]);
mch_errmsg("\" for output\n");
mch_windexit(2);
}
break;
}
}
}
/*
* File name argument.
*/
else
{
argv_idx = -1; /* skip to next argument */
if (edit_type != EDIT_NONE && edit_type != EDIT_FILE)
mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]);
edit_type = EDIT_FILE;
arg_files[arg_file_count] = vim_strsave((char_u *)argv[0]);
if (arg_files[arg_file_count] != NULL)
++arg_file_count;
}
/*
* If there are no more letters after the current "-", go to next
* argument. argv_idx is set to -1 when the current argument is to be
* skipped.
*/
if (argv_idx <= 0 || argv[0][argv_idx] == NUL)
{
--argc;
++argv;
argv_idx = 1;
}
}
/*
* May expand wildcards in file names.
*/
if (arg_file_count > 0)
{
#if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE)
char_u **new_arg_files;
int new_arg_file_count;
if (expand_wildcards(arg_file_count, arg_files, &new_arg_file_count,
&new_arg_files, EW_FILE|EW_NOTFOUND) == OK
&& new_arg_file_count != 0)
{
FreeWild(arg_file_count, arg_files);
arg_file_count = new_arg_file_count;
arg_files = new_arg_files;
}
#endif
fname = arg_files[0];
}
if (arg_file_count > 1)
printf("%d files to edit\n", arg_file_count);
#ifdef WIN32
else if (arg_file_count == 1)
{
/*
* If there is one filename, fully qualified, we have very probably
* been invoked from explorer, so change to the file's directory.
*/
if (fname[0] != NUL && fname[1] == ':' && fname[2] == '\\')
{
/* If the cd fails, it doesn't matter.. */
(void)vim_chdirfile(fname);
}
}
#endif
RedrawingDisabled = TRUE;
/*
* When listing swap file names, don't do cursor positioning et. al.
*/
if (recoverymode && fname == NULL)
want_full_screen = FALSE;
/*
* When starting the GUI, don't need to check capabilities of terminal.
*/
#ifdef USE_GUI
if (gui.starting)
want_full_screen = FALSE;
#endif
/*
* mch_windinit() sets up the terminal (window) for use. This must be
* done after resetting full_screen, otherwise it may move the cursor
* (MSDOS).
* Note that we may use mch_windexit() before mch_windinit()!
*/
mch_windinit();
/*
* Print a warning if stdout is not a terminal.
* When starting in Ex mode and commands come from a file, set Silent mode.
*/
input_isatty = mch_input_isatty();
if (exmode_active)
{
if (!input_isatty)
silent_mode = TRUE;
}
else if (want_full_screen && (!stdout_isatty || !input_isatty))
{
if (!stdout_isatty)
mch_errmsg("Vim: Warning: Output is not to a terminal\n");
if (!input_isatty)
mch_errmsg("Vim: Warning: Input is not from a terminal\n");
ui_delay(2000L, TRUE);
}
if (want_full_screen)
{
termcapinit(term); /* set terminal name and get terminal
capabilities (will set full_screen) */
screen_start(); /* don't know where cursor is now */
}
screenclear(); /* clear screen (just inits screen structures,
because starting is TRUE) */
/*
* Set the default values for the options that use Rows and Columns.
*/
ui_get_winsize(); /* inits Rows and Columns */
set_init_2();
firstwin->w_height = Rows - 1;
cmdline_row = Rows - 1;
if (full_screen)
msg_start(); /* in case a mapping or error message is printed */
msg_scroll = TRUE;
no_wait_return = TRUE;
#if defined(MSDOS) || defined(WIN32) || defined(OS2) || defined(macintosh)
/*
* Default mappings for some often used keys.
* Need to put string in allocated memory, because do_map() will modify it.
*/
{
char_u *cpo_save = p_cpo;
p_cpo = (char_u *)""; /* Allow <> notation */
for (i = 0; i < sizeof(initmappings) / sizeof(struct initmap); ++i)
{
initstr = vim_strsave(initmappings[i].arg);
if (initstr != NULL)
{
do_map(0, initstr, initmappings[i].mode, FALSE);
vim_free(initstr);
}
}
p_cpo = cpo_save;
}
#endif
init_highlight(TRUE); /* set the default highlight groups */
#ifdef CURSOR_SHAPE
parse_guicursor(); /* set cursor shapes from 'guicursor' */
#endif
/*
* If -u option given, use only the initializations from that file and
* nothing else.
*/
if (use_vimrc != NULL)
{
if (STRCMP(use_vimrc, "NONE") == 0)
{
if (use_gvimrc == NULL) /* don't load gvimrc either */
use_gvimrc = use_vimrc;
}
else
{
if (do_source(use_vimrc, FALSE, FALSE) != OK)
EMSG2("Cannot read from \"%s\"", use_vimrc);
}
}
else if (!silent_mode)
{
/*
* Get system wide defaults, if the file name is defined.
*/
#ifdef SYS_VIMRC_FILE
(void)do_source((char_u *)SYS_VIMRC_FILE, TRUE, FALSE);
#endif
/*
* Try to read initialization commands from the following places:
* - environment variable VIMINIT
* - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise)
* - second user vimrc file ($VIM/.vimrc for Dos)
* - environment variable EXINIT
* - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise)
* - second user exrc file ($VIM/.exrc for Dos)
* The first that exists is used, the rest is ignored.
*/
if (process_env((char_u *)"VIMINIT") == OK)
vimrc_found();
else
{
if (do_source((char_u *)USR_VIMRC_FILE, TRUE, TRUE) == FAIL
#ifdef USR_VIMRC_FILE2
&& do_source((char_u *)USR_VIMRC_FILE2, TRUE, TRUE) == FAIL
#endif
&& process_env((char_u *)"EXINIT") == FAIL
&& do_source((char_u *)USR_EXRC_FILE, FALSE, FALSE) == FAIL)
{
#ifdef USR_EXRC_FILE2
(void)do_source((char_u *)USR_EXRC_FILE2, FALSE, FALSE);
#endif
}
}
/*
* Read initialization commands from ".vimrc" or ".exrc" in current
* directory. This is only done if the 'exrc' option is set.
* Because of security reasons we disallow shell and write commands
* now, except for unix if the file is owned by the user or 'secure'
* option has been reset in environmet of global ".exrc" or ".vimrc".
* Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or
* SYS_VIMRC_FILE.
*/
if (p_exrc)
{
#ifdef UNIX
{
struct stat s;
/* if ".vimrc" file is not owned by user, set 'secure' mode */
if (stat(VIMRC_FILE, &s) || s.st_uid != getuid())
secure = p_secure;
}
#else
secure = p_secure;
#endif
i = FAIL;
if (fullpathcmp((char_u *)USR_VIMRC_FILE,
(char_u *)VIMRC_FILE, FALSE) != FPC_SAME
#ifdef USR_VIMRC_FILE2
&& fullpathcmp((char_u *)USR_VIMRC_FILE2,
(char_u *)VIMRC_FILE, FALSE) != FPC_SAME
#endif
#ifdef SYS_VIMRC_FILE
&& fullpathcmp((char_u *)SYS_VIMRC_FILE,
(char_u *)VIMRC_FILE, FALSE) != FPC_SAME
#endif
)
i = do_source((char_u *)VIMRC_FILE, TRUE, TRUE);
if (i == FAIL)
{
#ifdef UNIX
struct stat s;
/* if ".exrc" is not owned by user set 'secure' mode */
if (stat(EXRC_FILE, &s) || s.st_uid != getuid())
secure = p_secure;
else
secure = 0;
#endif
if ( fullpathcmp((char_u *)USR_EXRC_FILE,
(char_u *)EXRC_FILE, FALSE) != FPC_SAME
#ifdef USR_EXRC_FILE2
&& fullpathcmp((char_u *)USR_EXRC_FILE2,
(char_u *)EXRC_FILE, FALSE) != FPC_SAME
#endif
)
(void)do_source((char_u *)EXRC_FILE, FALSE, FALSE);
}
}
if (secure == 2)
need_wait_return = TRUE;
secure = 0;
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -