aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-03-28 13:22:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-03-29 12:16:21 +0200
commit8b571bd7b507c5dbdf8bb2bd804047ed66ea9809 (patch)
treea536b701cb2cf07ab42b6f71982291b2e2673cb4 /editors/vi.c
parentd3b74826c5a0843e9c0ef324944d6e084ae15b46 (diff)
downloadbusybox-w32-8b571bd7b507c5dbdf8bb2bd804047ed66ea9809.tar.gz
busybox-w32-8b571bd7b507c5dbdf8bb2bd804047ed66ea9809.tar.bz2
busybox-w32-8b571bd7b507c5dbdf8bb2bd804047ed66ea9809.zip
vi: improve motion by paragraph
When moving by paragraph ('{' and '}'): - Treat multiple empty lines as a single paragraph separator. - When no paragraph separator is found move to the start or end of the file depending on the direction of motion. function old new delta do_cmd 4821 4900 +79 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 79/0) Total: 79 bytes 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.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c
index e3e0f4b44..5d4b0f20e 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3515,12 +3515,20 @@ static void do_cmd(int c)
3515 case '{': // {- move backward paragraph 3515 case '{': // {- move backward paragraph
3516 case '}': // }- move forward paragraph 3516 case '}': // }- move forward paragraph
3517 do { 3517 do {
3518 q = char_search(dot, "\n\n", c == '{' ? 3518 dir = c == '}' ? FORWARD : BACK;
3519 ((unsigned)BACK << 1) | FULL : 3519 // skip over consecutive empty lines
3520 (FORWARD << 1) | FULL); 3520 while ((dir == FORWARD ? dot < end - 1 : dot > text) &&
3521 *dot == '\n' && dot[dir] == '\n') {
3522 dot += dir;
3523 }
3524 q = char_search(dot, "\n\n", ((unsigned)dir << 1) | FULL);
3521 if (q != NULL) { // found blank line 3525 if (q != NULL) { // found blank line
3522 dot = next_line(q); // move to next blank line 3526 dot = next_line(q); // move to next blank line
3523 } 3527 }
3528 else { // blank line not found, move to end of file
3529 dot = dir == FORWARD ? end - 1 : text;
3530 break;
3531 }
3524 } while (--cmdcnt > 0); 3532 } while (--cmdcnt > 0);
3525 break; 3533 break;
3526#endif /* FEATURE_VI_SEARCH */ 3534#endif /* FEATURE_VI_SEARCH */