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

📄 edit.c

📁 VIM文本编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
	}
#ifdef MULTI_BYTE
# if defined(USE_GUI) && !defined(USE_GUI_WIN32)
	if (!gui.in_use)
# endif
	if (is_dbcs && IsLeadByte(c))
	{
	    int c2;

	    c2 = get_literal();
	    insert_special(c, FALSE, FALSE);
	    insert_special(c2, FALSE, FALSE);
	    need_redraw = TRUE;
	    continue;
	}
#endif

#ifdef CINDENT
	if (curbuf->b_p_cin
# ifdef INSERT_EXPAND
			    && !ctrl_x_mode
# endif
					       )
	{
	    line_is_white = inindent(0);

	    /*
	     * A key name preceded by a bang means that this
	     * key wasn't destined to be inserted.  Skip ahead
	     * to the re-indenting if we find one.
	     */
	    if (in_cinkeys(c, '!', line_is_white))
		goto force_cindent;

	    /*
	     * A key name preceded by a star means that indenting
	     * has to be done before inserting the key.
	     */
	    if (can_cindent && in_cinkeys(c, '*', line_is_white))
	    {
		stop_arrow();

		/* re-indent the current line */
		fixthisline(get_c_indent);

		/* draw the changes on the screen later */
		need_redraw = TRUE;
	    }
	}
#endif /* CINDENT */

#ifdef RIGHTLEFT
	if (curwin->w_p_rl)
	    switch (c)
	    {
		case K_LEFT:	c = K_RIGHT; break;
		case K_S_LEFT:	c = K_S_RIGHT; break;
		case K_RIGHT:	c = K_LEFT; break;
		case K_S_RIGHT: c = K_S_LEFT; break;
	    }
#endif

	/* if 'keymodel' contains "startsel", may start selection */
	if (has_startsel)
	    switch (c)
	    {
		case K_KHOME:
		case K_KEND:
		case K_PAGEUP:
		case K_KPAGEUP:
		case K_PAGEDOWN:
		case K_KPAGEDOWN:
		    if (!(mod_mask & MOD_MASK_SHIFT))
			break;
		    /* FALLTHROUGH */
		case K_S_LEFT:
		case K_S_RIGHT:
		case K_S_UP:
		case K_S_DOWN:
		case K_S_END:
		case K_S_HOME:
		    /* Start selection right away, the cursor can move with
		     * CTRL-O when beyond the end of the line. */
		    start_selection();

		    /* Execute the key in (insert) Select mode, unless it's
		     * shift-left and beyond the end of the line (the CTRL-O
		     * will move the cursor left already). */
		    stuffcharReadbuff(Ctrl('O'));
		    if (c != K_S_LEFT || gchar_cursor() != NUL)
		    {
			if (mod_mask)
			{
			    char_u	    buf[4];

			    buf[0] = K_SPECIAL;
			    buf[1] = KS_MODIFIER;
			    buf[2] = mod_mask;
			    buf[3] = NUL;
			    stuffReadbuff(buf);
			}
			stuffcharReadbuff(c);
		    }
		    continue;
	    }

	/*
	 * The big switch to handle a character in insert mode.
	 */
	switch (c)
	{
	case K_INS:	    /* toggle insert/replace mode */
#ifdef FKMAP
	    if (p_fkmap && p_ri)
	    {
		beep_flush();
		EMSG(farsi_text_3);	/* encoded in Farsi */
		break;
	    }
#endif
	    if (State == REPLACE)
		State = INSERT;
	    else
		State = REPLACE;
	    AppendCharToRedobuff(K_INS);
	    showmode();
#ifdef CURSOR_SHAPE
	    ui_cursor_shape();		/* may show different cursor shape */
#endif
	    break;

#ifdef INSERT_EXPAND
	case Ctrl('X'):	    /* Enter ctrl-x mode */
	    /* if the next ^X<> won't ADD nothing, then reset continue_status */
	    continue_status = continue_status & CONT_N_ADDS ?
		continue_status | CONT_INTRPT : 0;
	    /* We're not sure which ctrl-x mode it will be yet */
	    ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
	    edit_submode = (char_u *)ctrl_x_msgs[ctrl_x_mode & 15];
	    showmode();
	    break;
#endif

	case K_SELECT:	    /* end of Select mode mapping - ignore */
	    break;

	case Ctrl('Z'):	    /* suspend when 'insertmode' set */
	    if (!p_im)
		goto normalchar;	/* insert CTRL-Z as normal char */
	    stuffReadbuff((char_u *)":st\r");
	    c = Ctrl('O');
	    /*FALLTHROUGH*/

	case Ctrl('O'):	    /* execute one command */
	    if (echeck_abbr(Ctrl('O') + ABBR_OFF))
		break;
	    count = 0;
	    if (State == INSERT)
		restart_edit = 'I';
	    else
		restart_edit = 'R';
	    o_lnum = curwin->w_cursor.lnum;
	    o_eol = (gchar_cursor() == NUL);
	    goto doESCkey;

#ifdef USE_SNIFF
	case K_SNIFF:
	    stuffcharReadbuff(K_SNIFF);
	    goto doESCkey;
#endif

	  /* Hitting the help key in insert mode is like <ESC> <Help> */
	case K_HELP:
	case K_F1:
	    stuffcharReadbuff(K_HELP);
	    if (p_im)
		stuffcharReadbuff('i');
	    goto doESCkey;

	case ESC:	    /* an escape ends input mode */
	    if (echeck_abbr(ESC + ABBR_OFF))
		break;
	    /*FALLTHROUGH*/

	case Ctrl('C'):
#ifdef UNIX
do_intr:
#endif
	    /* when 'insertmode' set, and not halfway a mapping, don't leave
	     * Insert mode */
	    if (goto_im())
	    {
		if (got_int)
		{
		    (void)vgetc();		/* flush all buffers */
		    got_int = FALSE;
		}
		else
		    vim_beep();
		break;
	    }
doESCkey:
	    /*
	     * This is the ONLY return from edit()!
	     */
	    if (ins_esc(&count, need_redraw, cmdchar))
		return (c == Ctrl('O'));
	    continue;

	    /*
	     * Insert the previously inserted text.
	     * For ^@ the trailing ESC will end the insert, unless there
	     * is an error.
	     */
	case K_ZERO:
	case NUL:
	case Ctrl('A'):
	    if (stuff_inserted(NUL, 1L, (c == Ctrl('A'))) == FAIL
						   && c != Ctrl('A') && !p_im)
		goto doESCkey;		/* quit insert mode */
	    break;

	/*
	 * insert the contents of a register
	 */
	case Ctrl('R'):
	    need_redraw |= ins_reg();
	    break;

#ifdef RIGHTLEFT
	case Ctrl('_'):
	    if (!p_ari)
		goto normalchar;
	    ins_ctrl_();
	    break;
#endif

	/* Make indent one shiftwidth smaller. */
	case Ctrl('D'):
#if defined(INSERT_EXPAND) && defined(FIND_IN_PATH)
	    if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
		goto docomplete;
#endif
	    /* FALLTHROUGH */

	/* Make indent one shiftwidth greater. */
	case Ctrl('T'):
	    ins_shift(c, lastc);
	    need_redraw = TRUE;
	    break;

	/* delete character under the cursor */
	case K_DEL:
	    ins_del();
	    need_redraw = TRUE;
	    break;

	/* delete character before the cursor */
	case K_BS:
	case Ctrl('H'):
	    did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
	    need_redraw = TRUE;
	    break;

	/* delete word before the cursor */
	case Ctrl('W'):
	    did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
	    need_redraw = TRUE;
	    break;

	/* delete all inserted text in current line */
	case Ctrl('U'):
	    did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
	    need_redraw = TRUE;
	    break;

#ifdef USE_MOUSE
	case K_LEFTMOUSE:
	case K_LEFTDRAG:
	case K_LEFTRELEASE:
	case K_MIDDLEMOUSE:
	case K_MIDDLEDRAG:
	case K_MIDDLERELEASE:
	case K_RIGHTMOUSE:
	case K_RIGHTDRAG:
	case K_RIGHTRELEASE:
	    ins_mouse(c);
	    break;

	case K_IGNORE:
	    break;
#endif

#ifdef USE_GUI
	case K_SCROLLBAR:
	    ins_scroll();
	    break;

	case K_HORIZ_SCROLLBAR:
	    ins_horscroll();
	    break;
#endif

	case K_HOME:
	case K_KHOME:
	case K_S_HOME:
	    ins_home();
	    break;

	case K_END:
	case K_KEND:
	case K_S_END:
	    ins_end();
	    break;

	case K_LEFT:
	    if (mod_mask & MOD_MASK_CTRL)
		ins_s_left();
	    else
		ins_left();
	    break;

	case K_S_LEFT:
	    ins_s_left();
	    break;

	case K_RIGHT:
	    if (mod_mask & MOD_MASK_CTRL)
		ins_s_right();
	    else
		ins_right();
	    break;

	case K_S_RIGHT:
	    ins_s_right();
	    break;

	case K_UP:
	    ins_up();
	    break;

	case K_S_UP:
	case K_PAGEUP:
	case K_KPAGEUP:
	    ins_pageup();
	    break;

	case K_DOWN:
	    ins_down();
	    break;

	case K_S_DOWN:
	case K_PAGEDOWN:
	case K_KPAGEDOWN:
	    ins_pagedown();
	    break;

	    /* keypad keys: When not mapped they produce a normal char */
	case K_KPLUS:		c = '+'; goto normalchar;
	case K_KMINUS:		c = '-'; goto normalchar;
	case K_KDIVIDE:		c = '/'; goto normalchar;
	case K_KMULTIPLY:	c = '*'; goto normalchar;

	    /* When <S-Tab> isn't mapped, use it like a normal TAB */
	case K_S_TAB:
	    c = TAB;
	    /* FALLTHROUGH */

	/* TAB or Complete patterns along path */
	case TAB:
#if defined(INSERT_EXPAND) && defined(FIND_IN_PATH)
	    if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
		goto docomplete;
#endif
	    inserted_space = FALSE;
	    if (ins_tab())
		goto normalchar;	/* insert TAB as a normal char */
	    need_redraw = TRUE;
	    break;

	case K_KENTER:
	    c = CR;
	    /* FALLTHROUGH */
	case CR:
	case NL:
	    if (ins_eol(c) && !p_im)
		goto doESCkey;	    /* out of memory */
	    break;

#if defined(DIGRAPHS) || defined (INSERT_EXPAND)
	case Ctrl('K'):
# ifdef INSERT_EXPAND
	    if (ctrl_x_mode == CTRL_X_DICTIONARY)
	    {
		if (*p_dict == NUL)
		{
		    ctrl_x_mode = 0;
		    msg_attr((char_u *)"'dictionary' option is empty",
			     hl_attr(HLF_E));
		    vim_beep();
		    setcursor();
		    out_flush();
		    ui_delay(2000L, FALSE);
		    break;
		}
		goto docomplete;
	    }
# endif
# ifdef DIGRAPHS
	    c = ins_digraph();
	    if (c == NUL)
	    {
		need_redraw = TRUE;
		break;
	    }
# endif
	    goto normalchar;
#endif /* DIGRAPHS || INSERT_EXPAND */

#ifdef INSERT_EXPAND
	case Ctrl(']'):		/* Tag name completion after ^X */
	    if (ctrl_x_mode != CTRL_X_TAGS)
		goto normalchar;
	    goto docomplete;

	case Ctrl('F'):		/* File name completion after ^X */
	    if (ctrl_x_mode != CTRL_X_FILES)
		goto normalchar;
	    goto docomplete;
#endif

	case Ctrl('L'):		/* Whole line completion after ^X */
#ifdef INSERT_EXPAND
	    if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
#endif
	    {
		/* CTRL-L with 'insertmode' set: Leave Insert mode */
		if (p_im)
		{
		    if (echeck_abbr(Ctrl('L') + ABBR_OFF))
			break;
		    goto doESCkey;
		}
		goto normalchar;
	    }
#ifdef INSERT_EXPAND
	    /* FALLTHROUGH */

	case Ctrl('P'):		/* Do previous pattern completion */
	case Ctrl('N'):		/* Do next pattern completion */
	    /* if 'complete' is empty then plain ^P is no longer special,
	     * but it is under other ^X modes */
	    if (    *curbuf->b_p_cpt == NUL && !ctrl_x_mode
		    && !(continue_status & CONT_LOCAL))
		goto normalchar;
docomplete:
	    i = ins_complete(c);
	    if (i)
		need_redraw |= i;
	    else
		continue_status = 0;
	    break;
#endif /* INSERT_EXPAND */

	case Ctrl('Y'):		/* copy from previous line or scroll down */
	case Ctrl('E'):		/* copy from next line	   or scroll up */
#ifdef INSERT_EXPAND
	    if (ctrl_x_mode == CTRL_X_SCROLL)
	    {
		if (c == Ctrl('Y'))
		    scrolldown_clamp();
		else
		    scrollup_clamp();
		update_screen(VALID);
	    }
	    else
#endif
	    {
		c = ins_copychar(curwin->w_cursor.lnum
						 + (c == Ctrl('Y') ? -1 : 1));
		if (c != NUL)
		{
		    long	tw_save;

		    /* The character must be taken literally, insert like it
		     * was typed after a CTRL-V, and pretend 'textwidth'
		     * wasn't set.  Digits, 'o' and 'x' are special after a
		     * CTRL-V, don't use it for these. */
		    if (!isalnum(c))
			AppendToRedobuff((char_u *)"\026");	/* CTRL-V */

⌨️ 快捷键说明

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