1 /* $NetBSD: v_right.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 static const char sccsid
[] = "Id: v_right.c,v 10.8 2001/06/25 15:19:34 skimo Exp (Berkeley) Date: 2001/06/25 15:19:34 ";
19 __RCSID("$NetBSD: v_right.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
30 #include "../common/common.h"
34 * v_right -- [count]' ', [count]l
35 * Move right by columns.
37 * PUBLIC: int v_right __P((SCR *, VICMD *));
40 v_right(SCR
*sp
, VICMD
*vp
)
45 if (db_eget(sp
, vp
->m_start
.lno
, NULL
, &len
, &isempty
)) {
51 /* It's always illegal to move right on empty lines. */
58 * Non-motion commands move to the end of the range. Delete and
59 * yank stay at the start. Ignore others. Adjust the end of the
60 * range for motion commands.
63 * Historically, "[cdsy]l" worked at the end of a line. Also,
64 * EOL is a count sink.
66 vp
->m_stop
.cno
= vp
->m_start
.cno
+
67 (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1);
68 if (vp
->m_start
.cno
== len
- 1 && !ISMOTION(vp
)) {
72 if (vp
->m_stop
.cno
>= len
) {
73 vp
->m_stop
.cno
= len
- 1;
74 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
75 } else if (ISMOTION(vp
)) {
77 vp
->m_final
= vp
->m_start
;
79 vp
->m_final
= vp
->m_stop
;
84 * v_dollar -- [count]$
85 * Move to the last column.
87 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
90 v_dollar(SCR
*sp
, VICMD
*vp
)
97 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
99 if ((F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1) != 1) {
102 * Historically, if the $ is a motion, and deleting from
103 * at or before the first non-blank of the line, it's a
104 * line motion, and the line motion flag is set.
107 if (nonblank(sp
, vp
->m_start
.lno
, &vp
->m_stop
.cno
))
109 if (ISMOTION(vp
) && vp
->m_start
.cno
<= vp
->m_stop
.cno
)
119 * Historically, it was illegal to use $ as a motion command on
120 * an empty line. Unfortunately, even though C was historically
121 * aliased to c$, it (and not c$) was special cased to work on
122 * empty lines. Since we alias C to c$ too, we have a problem.
123 * To fix it, we let c$ go through, on the assumption that it's
124 * not a problem for it to work.
126 if (db_eget(sp
, vp
->m_stop
.lno
, NULL
, &len
, &isempty
)) {
133 if (ISMOTION(vp
) && !ISCMD(vp
->rkp
, 'c')) {
141 * Non-motion commands move to the end of the range. Delete
142 * and yank stay at the start. Ignore others.
144 vp
->m_stop
.cno
= len
? len
- 1 : 0;
145 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;