[patch] vi: add 3 commands: '_' ',' and gg for vi

Paul Fox pgf at brightstareng.com
Tue Feb 12 22:45:55 UTC 2008


 > 
 > hello,
 > 
 > i added 3 commands for vi:
 > _           cnt - 1 lines downward, on the first non-blank character

i think you may be the first person i've ever met who uses this
vi command.  i assume you only use it as an operator motion, e.g.
"d_", correct?  can i ask why you don't just stutter the action
part, i.e. "dd"?  when i wrote vile, i didn't even bind '_'
(initially out of ignorance), but never had a complaint.  (it
does something else entirely in vile, and i'd gotten used to that
behavior by the time i found out it was a real command, and refused
to change it.)

in any case, can't '_' be more easily implemented as a
fall-through into the carriage return ("case 13") and '+' cases,
with a pre-decrement of the argument?

 > ,           repeat latest 'f' in opposite direction
this is fine.

 > gg        goto a line number (default= first line in file)
this is a vim-ism.  what's wrong with 'G' (and "1G")?

 > 
 > i don't know if the vi is still open for additional commands.

i'd rather you implemented "undo".  ;-)

paul


 > 
 > -- 
 > Best Regards,
 > Leo Jay
 > 
 > Index: editors/vi.c
 > ===================================================================
 > --- editors/vi.c	(revision 20998)
 > +++ editors/vi.c	(working copy)
 > @@ -3024,7 +3024,6 @@
 >  		//case '(':	// (-
 >  		//case ')':	// )-
 >  		//case '*':	// *-
 > -		//case ',':	// ,-
 >  		//case '=':	// =-
 >  		//case '@':	// @-
 >  		//case 'F':	// F-
 > @@ -3036,9 +3035,7 @@
 >  		//case '[':	// [-
 >  		//case '\\':	// \-
 >  		//case ']':	// ]-
 > -		//case '_':	// _-
 >  		//case '`':	// `-
 > -		//case 'g':	// g-
 >  		//case 'u':	// u- FIXME- there is no undo
 >  		//case 'v':	// v-
 >  	default:			// unrecognised command
 > @@ -3259,6 +3256,19 @@
 >  		if (*q == last_forward_char)
 >  			dot = q;
 >  		break;
 > +	case ',':           // repeat latest 'f' in opposite direction
 > +		if (cmdcnt-- > 1) {
 > +			do_cmd(',');
 > +		}				// repeat cnt
 > +		if (last_forward_char == 0)
 > +			break;
 > +		q = dot - 1;
 > +		while (q >= text && *q != '\n' && *q != last_forward_char) {
 > +			q--;
 > +		}
 > +		if (q >= text && *q == last_forward_char)
 > +			dot = q;
 > +		break;
 >  	case '-':			// -- goto prev line
 >  		if (cmdcnt-- > 1) {
 >  			do_cmd(c);
 > @@ -3266,6 +3276,14 @@
 >  		dot_prev();
 >  		dot_skip_over_ws();
 >  		break;
 > +	case '_':			// cnt - 1 lines downward, on the first 
 > non-blank character
 > +		while (--cmdcnt > 0) {
 > +			dot_next();
 > +		}
 > +		dot_begin();
 > +		dot_skip_over_ws();
 > +		break;
 > +
 >  #if ENABLE_FEATURE_VI_DOT_CMD
 >  	case '.':			// .- repeat the last modifying command
 >  		// Stuff the last_modifying_cmd back into stdin
 > @@ -3491,7 +3509,21 @@
 >  			end_cmd_q();	// stop adding to q
 >  #endif
 >  		break;
 > +	case 'g':
 > +		c1 = get_one_char();
 > +		if (c1 == 'g') {	// 'gg' goto a line number (default= 
 > first line in file)
 > +			if (cmdcnt == 0)
 > +				cmdcnt = 1;
 > +			goto dc_G;
 > +		}
 > +
 > +		buf[0] = 'g';
 > +		buf[1] = c1;
 > +		buf[2] = '\0';
 > +		not_implemented(buf);
 > +		break;
 >  	case 'G':		// G- goto to a line number (default= E-O-F)
 > +  dc_G:
 >  		dot = end - 1;				// assume E-O-F
 >  		if (cmdcnt > 0) {
 >  			dot = find_line(cmdcnt);	// what line is #cmdcnt

=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list