From 268d15e32fc36c363e573658a0588cfcd2f5d897 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 16 Jun 2026 02:15:14 +0000 Subject: [PATCH] Fix behavior of ')' used in a range when setence reaches EOF. For a sentence spanning more than one line at the end of the file, when the cursor is placed at the first character of any line except for the last one, running '!)' won't affect the last line. From Walter Alejandro Iglesias --- usr.bin/vi/vi/v_sentence.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/usr.bin/vi/vi/v_sentence.c b/usr.bin/vi/vi/v_sentence.c index a3306adde84..86136bf3721 100644 --- a/usr.bin/vi/vi/v_sentence.c +++ b/usr.bin/vi/vi/v_sentence.c @@ -1,4 +1,4 @@ -/* $OpenBSD: v_sentence.c,v 1.11 2026/04/25 19:30:59 millert Exp $ */ +/* $OpenBSD: v_sentence.c,v 1.12 2026/06/16 02:15:14 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -175,8 +175,20 @@ okret: vp->m_stop.lno = cs.cs_lno; * range for motion commands. */ if (ISMOTION(vp)) { - if (vp->m_start.cno == 0 && + if (cs.cs_flags == CS_EOF) { + /* + * If EOF is reached, maintain the stop position + * at the very end of the file (cs_len - 1) instead + * of decrementing it. + */ + vp->m_stop.lno = cs.cs_lno; + vp->m_stop.cno = cs.cs_len > 0 ? cs.cs_len - 1 : 0; + } else if (vp->m_start.cno == 0 && (cs.cs_flags != 0 || vp->m_stop.cno == 0)) { + /* + * If in line mode, adjust stop to the end of + * the previous line. + */ if (vp->m_start.lno < vp->m_stop.lno) { if (db_get(sp, --vp->m_stop.lno, DBG_FATAL, NULL, &len)) @@ -184,11 +196,13 @@ okret: vp->m_stop.lno = cs.cs_lno; vp->m_stop.cno = len ? len - 1 : 0; } F_SET(vp, VM_LMODE); - } else + } else if (vp->m_stop.cno > 0) { --vp->m_stop.cno; + } vp->m_final = vp->m_start; - } else + } else { vp->m_final = vp->m_stop; + } return (0); }