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 <[email protected]>
---
editors/vi.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/editors/vi.c b/editors/vi.c
index 5ea1b7eea..94a5506b3 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -3515,12 +3515,20 @@ static void do_cmd(int c)
case '{': // {- move backward paragraph
case '}': // }- move forward paragraph
do {
- q = char_search(dot, "\n\n", c == '{' ?
- ((unsigned)BACK << 1) | FULL :
- (FORWARD << 1) | FULL);
+ dir = c == '}' ? FORWARD : BACK;
+ // skip over consecutive empty lines
+ while ((dir == FORWARD ? dot < end - 1 : dot > text) &&
+ *dot == '\n' && dot[dir] ==
'\n') {
+ dot += dir;
+ }
+ q = char_search(dot, "\n\n", ((unsigned)dir << 1) |
FULL);
if (q != NULL) { // found blank line
dot = next_line(q); // move to next blank
line
}
+ else { // blank line not found, move to end of file
+ dot = dir == FORWARD ? end - 1 : text;
+ break;
+ }
} while (--cmdcnt > 0);
break;
#endif /* FEATURE_VI_SEARCH */
--
2.30.2
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox