aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-04-10 11:17:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-04-11 00:18:55 +0200
commit951c6ded3aa7f0dc414306e27aed8b2785965857 (patch)
treedc854fc8049dd3e1cbba0ea46bafd230289bf518 /editors/vi.c
parenta54450248b063afd96530821020872bfc9ec9997 (diff)
downloadbusybox-w32-951c6ded3aa7f0dc414306e27aed8b2785965857.tar.gz
busybox-w32-951c6ded3aa7f0dc414306e27aed8b2785965857.tar.bz2
busybox-w32-951c6ded3aa7f0dc414306e27aed8b2785965857.zip
vi: make put commands more like vi
Make the put commands 'p' and 'P' behave more like vi: - allow a repetition count to be specified; - when the text being inserted doesn't include a newline the cursor should be positioned at the end of the inserted text. function old new delta do_cmd 4765 4842 +77 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 77/0) Total: 77 bytes v2: Don't break build when FEATURE_VI_UNDO is disabled. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/vi.c')
-rw-r--r--editors/vi.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 9a2d7b0d9..fd4526dda 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3429,11 +3429,12 @@ static void do_cmd(int c)
3429 break; 3429 break;
3430 } 3430 }
3431 // are we putting whole lines or strings 3431 // are we putting whole lines or strings
3432 cnt = 0;
3432 if (regtype[YDreg] == WHOLE) { 3433 if (regtype[YDreg] == WHOLE) {
3433 if (c == 'P') { 3434 if (c == 'P') {
3434 dot_begin(); // putting lines- Put above 3435 dot_begin(); // putting lines- Put above
3435 } 3436 }
3436 if (c == 'p') { 3437 else /* if ( c == 'p') */ {
3437 // are we putting after very last line? 3438 // are we putting after very last line?
3438 if (end_line(dot) == (end - 1)) { 3439 if (end_line(dot) == (end - 1)) {
3439 dot = end; // force dot to end of text[] 3440 dot = end; // force dot to end of text[]
@@ -3444,8 +3445,18 @@ static void do_cmd(int c)
3444 } else { 3445 } else {
3445 if (c == 'p') 3446 if (c == 'p')
3446 dot_right(); // move to right, can move to NL 3447 dot_right(); // move to right, can move to NL
3448 // how far to move cursor if register doesn't have a NL
3449 if (strchr(p, '\n') == NULL)
3450 cnt = (cmdcnt ?: 1) * strlen(p) - 1;
3447 } 3451 }
3448 string_insert(dot, p, ALLOW_UNDO); // insert the string 3452 do {
3453 // dot is adjusted if text[] is reallocated so we don't have to
3454 string_insert(dot, p, allow_undo); // insert the string
3455# if ENABLE_FEATURE_VI_UNDO
3456 allow_undo = ALLOW_UNDO_CHAIN;
3457# endif
3458 } while (--cmdcnt > 0);
3459 dot += cnt;
3449 end_cmd_q(); // stop adding to q 3460 end_cmd_q(); // stop adding to q
3450 break; 3461 break;
3451 case 'U': // U- Undo; replace current line with original version 3462 case 'U': // U- Undo; replace current line with original version