diff options
author | Ron Yorston | 2021-03-28 13:22:43 +0100 |
---|---|---|
committer | Denys Vlasenko | 2021-03-29 12:16:21 +0200 |
commit | 8b571bd7b507c5dbdf8bb2bd804047ed66ea9809 (patch) | |
tree | a536b701cb2cf07ab42b6f71982291b2e2673cb4 /editors/vi.c | |
parent | d3b74826c5a0843e9c0ef324944d6e084ae15b46 (diff) | |
download | busybox-8b571bd7b507c5dbdf8bb2bd804047ed66ea9809.zip busybox-8b571bd7b507c5dbdf8bb2bd804047ed66ea9809.tar.gz |
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.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c index e3e0f4b..5d4b0f2 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 */ |