From e577afca7c94a7827bc216f4d8c95823d0f86489 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 6 Apr 2021 13:41:01 +0100 Subject: vi: more fixes to range selection by word An example in my vi book presents different ways to fix the spelling of the last word in a line: ... anyweigh. With the cursor on the 'e' the command 'cway' should do the job. Since commit 776b56d77, though, 'cw' incorrectly includes the full stop in the range if we're on the last line of the file. (Prior to commit 776b56d77 BusyBox vi got 'cw' right in this case but 'cW' wrong: it *didn't* delete the full stop.) Reinstate some of the bloat removed by the earlier commit to fix this. Also, commit 7b4c2276a (vi: fix word operations across line boundaries) incorrectly ignores whitespace after a single character word. Adjust the condition to avoid this. function old new delta find_range 707 737 +30 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 30/0) Total: 30 bytes Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- editors/vi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 9a17f65..7e89f58 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -3117,8 +3117,10 @@ static int find_range(char **start, char **stop, int cmd) } else if (strchr("wW", c)) { buftype = MULTI; do_cmd(c); // execute movement cmd - // step back one char, but not if we're at end of file - if (dot > p && !at_eof(dot)) + // step back one char, but not if we're at end of file, + // or if we are at EOF and search was for 'w' and we're at + // the start of a 'W' word. + if (dot > p && (!at_eof(dot) || (c == 'w' && ispunct(*dot)))) dot--; t = dot; // don't include trailing WS as part of word @@ -3127,7 +3129,7 @@ static int find_range(char **start, char **stop, int cmd) t = dot; } // for non-change operations WS after NL is not part of word - if (cmd != 'c' && dot != p && *dot != '\n') + if (cmd != 'c' && dot != t && *dot != '\n') dot = t; } else if (strchr("GHL+-jk'\r\n", c)) { // these operate on whole lines -- cgit v1.1