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

📄 vi.c

📁 asterisk 是一个很有知名度开源软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* vi_delete_meta(): *	Vi delete prefix command *	[d] */protected el_action_t/*ARGSUSED*/vi_delete_meta(EditLine *el, int c){	return (cv_action(el, DELETE));}/* vi_end_word(): *	Vi move to the end of the current space delimited word *	[E] */protected el_action_t/*ARGSUSED*/vi_end_word(EditLine *el, int c){	if (el->el_line.cursor == el->el_line.lastchar)		return (CC_ERROR);	el->el_line.cursor = cv__endword(el->el_line.cursor,	    el->el_line.lastchar, el->el_state.argument);	if (el->el_chared.c_vcmd.action & DELETE) {		el->el_line.cursor++;		cv_delfini(el);		return (CC_REFRESH);	}	return (CC_CURSOR);}/* vi_to_end_word(): *	Vi move to the end of the current word *	[e] */protected el_action_t/*ARGSUSED*/vi_to_end_word(EditLine *el, int c){	if (el->el_line.cursor == el->el_line.lastchar)		return (CC_ERROR);	el->el_line.cursor = cv__endword(el->el_line.cursor,	    el->el_line.lastchar, el->el_state.argument);	if (el->el_chared.c_vcmd.action & DELETE) {		el->el_line.cursor++;		cv_delfini(el);		return (CC_REFRESH);	}	return (CC_CURSOR);}/* vi_undo(): *	Vi undo last change *	[u] */protected el_action_t/*ARGSUSED*/vi_undo(EditLine *el, int c){	char *cp, *kp;	char temp;	int i, size;	c_undo_t *un = &el->el_chared.c_undo;#ifdef DEBUG_UNDO	(void) fprintf(el->el_errfile, "Undo: %x \"%s\" +%d -%d\n",	    un->action, un->buf, un->isize, un->dsize);#endif	switch (un->action) {	case DELETE:		if (un->dsize == 0)			return (CC_NORM);		(void) memcpy(un->buf, un->ptr, un->dsize);		for (cp = un->ptr; cp <= el->el_line.lastchar; cp++)			*cp = cp[un->dsize];		el->el_line.lastchar -= un->dsize;		el->el_line.cursor = un->ptr;		un->action = INSERT;		un->isize = un->dsize;		un->dsize = 0;		break;	case DELETE | INSERT:		size = un->isize - un->dsize;		if (size > 0)			i = un->dsize;		else			i = un->isize;		cp = un->ptr;		kp = un->buf;		while (i-- > 0) {			temp = *kp;			*kp++ = *cp;			*cp++ = temp;		}		if (size > 0) {			el->el_line.cursor = cp;			c_insert(el, size);			while (size-- > 0 && cp < el->el_line.lastchar) {				temp = *kp;				*kp++ = *cp;				*cp++ = temp;			}		} else if (size < 0) {			size = -size;			for (; cp <= el->el_line.lastchar; cp++) {				*kp++ = *cp;				*cp = cp[size];			}			el->el_line.lastchar -= size;		}		el->el_line.cursor = un->ptr;		i = un->dsize;		un->dsize = un->isize;		un->isize = i;		break;	case INSERT:		if (un->isize == 0)			return (CC_NORM);		el->el_line.cursor = un->ptr;		c_insert(el, (int) un->isize);		(void) memcpy(un->ptr, un->buf, un->isize);		un->action = DELETE;		un->dsize = un->isize;		un->isize = 0;		break;	case CHANGE:		if (un->isize == 0)			return (CC_NORM);		el->el_line.cursor = un->ptr;		size = (int) (el->el_line.cursor - el->el_line.lastchar);		if (size < un->isize)			size = un->isize;		cp = un->ptr;		kp = un->buf;		for (i = 0; i < size; i++) {			temp = *kp;			*kp++ = *cp;			*cp++ = temp;		}		un->dsize = 0;		break;	default:		return (CC_ERROR);	}	return (CC_REFRESH);}/* vi_command_mode(): *	Vi enter command mode (use alternative key bindings) *	[<ESC>] */protected el_action_t/*ARGSUSED*/vi_command_mode(EditLine *el, int c){	int size;	/* [Esc] cancels pending action */	el->el_chared.c_vcmd.ins = 0;	el->el_chared.c_vcmd.action = NOP;	el->el_chared.c_vcmd.pos = 0;	el->el_state.doingarg = 0;	size = el->el_chared.c_undo.ptr - el->el_line.cursor;	if (size < 0)		size = -size;	if (el->el_chared.c_undo.action == (INSERT | DELETE) ||	    el->el_chared.c_undo.action == DELETE)		el->el_chared.c_undo.dsize = size;	else		el->el_chared.c_undo.isize = size;	el->el_state.inputmode = MODE_INSERT;	el->el_map.current = el->el_map.alt;#ifdef VI_MOVE	if (el->el_line.cursor > el->el_line.buffer)		el->el_line.cursor--;#endif	return (CC_CURSOR);}/* vi_zero(): *	Vi move to the beginning of line *	[0] */protected el_action_tvi_zero(EditLine *el, int c){	if (el->el_state.doingarg) {		if (el->el_state.argument > 1000000)			return (CC_ERROR);		el->el_state.argument =		    (el->el_state.argument * 10) + (c - '0');		return (CC_ARGHACK);	} else {		el->el_line.cursor = el->el_line.buffer;		if (el->el_chared.c_vcmd.action & DELETE) {			cv_delfini(el);			return (CC_REFRESH);		}		return (CC_CURSOR);	}}/* vi_delete_prev_char(): * 	Vi move to previous character (backspace) *	[^H] */protected el_action_t/*ARGSUSED*/vi_delete_prev_char(EditLine *el, int c){	if (el->el_chared.c_vcmd.ins == 0)		return (CC_ERROR);	if (el->el_chared.c_vcmd.ins >	    el->el_line.cursor - el->el_state.argument)		return (CC_ERROR);	c_delbefore(el, el->el_state.argument);	el->el_line.cursor -= el->el_state.argument;	return (CC_REFRESH);}/* vi_list_or_eof(): *	Vi list choices for completion or indicate end of file if empty line *	[^D] */protected el_action_t/*ARGSUSED*/vi_list_or_eof(EditLine *el, int c){#ifdef notyet	if (el->el_line.cursor == el->el_line.lastchar &&	    el->el_line.cursor == el->el_line.buffer) {#endif		term_overwrite(el, STReof, 4);	/* then do a EOF */		term__flush();		return (CC_EOF);#ifdef notyet	} else {		re_goto_bottom(el);		*el->el_line.lastchar = '\0';	/* just in case */		return (CC_LIST_CHOICES);	}#endif}/* vi_kill_line_prev(): *	Vi cut from beginning of line to cursor *	[^U] */protected el_action_t/*ARGSUSED*/vi_kill_line_prev(EditLine *el, int c){	char *kp, *cp;	cp = el->el_line.buffer;	kp = el->el_chared.c_kill.buf;	while (cp < el->el_line.cursor)		*kp++ = *cp++;	/* copy it */	el->el_chared.c_kill.last = kp;	c_delbefore(el, el->el_line.cursor - el->el_line.buffer);	el->el_line.cursor = el->el_line.buffer;	/* zap! */	return (CC_REFRESH);}/* vi_search_prev(): *	Vi search history previous *	[?] */protected el_action_t/*ARGSUSED*/vi_search_prev(EditLine *el, int c){	return (cv_search(el, ED_SEARCH_PREV_HISTORY));}/* vi_search_next(): *	Vi search history next *	[/] */protected el_action_t/*ARGSUSED*/vi_search_next(EditLine *el, int c){	return (cv_search(el, ED_SEARCH_NEXT_HISTORY));}/* vi_repeat_search_next(): *	Vi repeat current search in the same search direction *	[n] */protected el_action_t/*ARGSUSED*/vi_repeat_search_next(EditLine *el, int c){	if (el->el_search.patlen == 0)		return (CC_ERROR);	else		return (cv_repeat_srch(el, el->el_search.patdir));}/* vi_repeat_search_prev(): *	Vi repeat current search in the opposite search direction *	[N] *//*ARGSUSED*/protected el_action_tvi_repeat_search_prev(EditLine *el, int c){	if (el->el_search.patlen == 0)		return (CC_ERROR);	else		return (cv_repeat_srch(el,		    el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?		    ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));}/* vi_next_char(): *	Vi move to the character specified next *	[f] */protected el_action_t/*ARGSUSED*/vi_next_char(EditLine *el, int c){	char ch;	if (el_getc(el, &ch) != 1)		return (ed_end_of_file(el, 0));	el->el_search.chadir = CHAR_FWD;	el->el_search.chacha = ch;	return (cv_csearch_fwd(el, ch, el->el_state.argument, 0));}/* vi_prev_char(): *	Vi move to the character specified previous *	[F] */protected el_action_t/*ARGSUSED*/vi_prev_char(EditLine *el, int c){	char ch;	if (el_getc(el, &ch) != 1)		return (ed_end_of_file(el, 0));	el->el_search.chadir = CHAR_BACK;	el->el_search.chacha = ch;	return (cv_csearch_back(el, ch, el->el_state.argument, 0));}/* vi_to_next_char(): *	Vi move up to the character specified next *	[t] */protected el_action_t/*ARGSUSED*/vi_to_next_char(EditLine *el, int c){	char ch;	if (el_getc(el, &ch) != 1)		return (ed_end_of_file(el, 0));	return (cv_csearch_fwd(el, ch, el->el_state.argument, 1));}/* vi_to_prev_char(): *	Vi move up to the character specified previous *	[T] */protected el_action_t/*ARGSUSED*/vi_to_prev_char(EditLine *el, int c){	char ch;	if (el_getc(el, &ch) != 1)		return (ed_end_of_file(el, 0));	return (cv_csearch_back(el, ch, el->el_state.argument, 1));}/* vi_repeat_next_char(): *	Vi repeat current character search in the same search direction *	[;] */protected el_action_t/*ARGSUSED*/vi_repeat_next_char(EditLine *el, int c){	if (el->el_search.chacha == 0)		return (CC_ERROR);	return (el->el_search.chadir == CHAR_FWD	    ? cv_csearch_fwd(el, el->el_search.chacha,		el->el_state.argument, 0)	    : cv_csearch_back(el, el->el_search.chacha,		el->el_state.argument, 0));}/* vi_repeat_prev_char(): *	Vi repeat current character search in the opposite search direction *	[,] */protected el_action_t/*ARGSUSED*/vi_repeat_prev_char(EditLine *el, int c){	if (el->el_search.chacha == 0)		return (CC_ERROR);	return el->el_search.chadir == CHAR_BACK ?	    cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :	    cv_csearch_back(el, el->el_search.chacha, el->el_state.argument, 0);}

⌨️ 快捷键说明

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