Download raw body.
vi(1), inconsistency in sentence limit
In sentence movement, the commands ')' and '(', move sentence forward
and backward respectively, present a inconsistency. Only the latter
considers also single spaces as sentence delimiter.
Below I paste two diffs. The first unifies the behavior in favor of
including also single space as delimiter for sentences. The second one
makes both to honor the traditional behavior.
Even when I format my paragraphs using two spaces as a sentence
delimiter (anything that helps to distinguish field separators in any
language helps reading,) I see some practical use in having the cursor
movement recognize both cases. I also see the drawbacks of this, so I
don't have a favorite.
FIRST OPTION
Teach ')' movement command to recognize single spaces as sentence
separator.
Index: vi/v_sentence.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/vi/v_sentence.c,v
diff -u -p -u -p -r1.8 v_sentence.c
--- vi/v_sentence.c 26 Dec 2022 19:16:04 -0000 1.8
+++ vi/v_sentence.c 24 Apr 2026 17:02:43 -0000
@@ -127,13 +127,15 @@ v_sentencef(SCR *sp, VICMD *vp)
/* FALLTHROUGH */
case ' ':
if (state == PERIOD) {
- state = BLANK;
- break;
- }
- if (state == BLANK && --cnt == 0) {
+ if (--cnt == 0) {
+ if (cs_fblank(sp, &cs))
+ return (1);
+ goto okret;
+ }
if (cs_fblank(sp, &cs))
return (1);
- goto okret;
+ state = NONE;
+ break;
}
/* FALLTHROUGH */
default:
SECOND OPTION
Restrict '(' command to only consider double space as sentence
separator.
Index: vi/v_sentence.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/vi/v_sentence.c,v
diff -u -p -u -p -r1.11 v_sentence.c
--- vi/v_sentence.c 25 Apr 2026 19:30:59 -0000 1.11
+++ vi/v_sentence.c 26 Apr 2026 11:36:51 -0000
@@ -205,7 +205,7 @@ v_sentenceb(SCR *sp, VICMD *vp)
recno_t slno;
size_t len, scno;
u_long cnt;
- int last;
+ int last, DOUBLE_SPACE;
/*
* !!!
@@ -332,7 +332,14 @@ ret: slno = cs.cs_lno;
cs.cs_flags == CS_EOL || isblank(cs.cs_ch) ||
cs.cs_ch == ')' || cs.cs_ch == ']' ||
cs.cs_ch == '"' || cs.cs_ch == '\'' ? 1 : 0;
+
+ if (cs.cs_ch == ' ' && DOUBLE_SPACE == 0)
+ last = 0;
}
+ if (cs.cs_ch == ' ')
+ DOUBLE_SPACE = 1;
+ else
+ DOUBLE_SPACE = 0;
}
okret: vp->m_stop.lno = cs.cs_lno;
--
Walter
vi(1), inconsistency in sentence limit