1 /* $NetBSD: v_right.c,v 1.2 2013/11/22 15:52:06 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.
14 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 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
21 #include <bitstring.h>
25 #include "../common/common.h"
29 * v_right -- [count]' ', [count]l
30 * Move right by columns.
32 * PUBLIC: int v_right __P((SCR *, VICMD *));
35 v_right(SCR
*sp
, VICMD
*vp
)
40 if (db_eget(sp
, vp
->m_start
.lno
, NULL
, &len
, &isempty
)) {
46 /* It's always illegal to move right on empty lines. */
53 * Non-motion commands move to the end of the range. Delete and
54 * yank stay at the start. Ignore others. Adjust the end of the
55 * range for motion commands.
58 * Historically, "[cdsy]l" worked at the end of a line. Also,
59 * EOL is a count sink.
61 vp
->m_stop
.cno
= vp
->m_start
.cno
+
62 (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1);
63 if (vp
->m_start
.cno
== len
- 1 && !ISMOTION(vp
)) {
67 if (vp
->m_stop
.cno
>= len
) {
68 vp
->m_stop
.cno
= len
- 1;
69 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
70 } else if (ISMOTION(vp
)) {
72 vp
->m_final
= vp
->m_start
;
74 vp
->m_final
= vp
->m_stop
;
79 * v_dollar -- [count]$
80 * Move to the last column.
82 * PUBLIC: int v_dollar __P((SCR *, VICMD *));
85 v_dollar(SCR
*sp
, VICMD
*vp
)
92 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
94 if ((F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1) != 1) {
97 * Historically, if the $ is a motion, and deleting from
98 * at or before the first non-blank of the line, it's a
99 * line motion, and the line motion flag is set.
102 if (nonblank(sp
, vp
->m_start
.lno
, &vp
->m_stop
.cno
))
104 if (ISMOTION(vp
) && vp
->m_start
.cno
<= vp
->m_stop
.cno
)
114 * Historically, it was illegal to use $ as a motion command on
115 * an empty line. Unfortunately, even though C was historically
116 * aliased to c$, it (and not c$) was special cased to work on
117 * empty lines. Since we alias C to c$ too, we have a problem.
118 * To fix it, we let c$ go through, on the assumption that it's
119 * not a problem for it to work.
121 if (db_eget(sp
, vp
->m_stop
.lno
, NULL
, &len
, &isempty
)) {
128 if (ISMOTION(vp
) && !ISCMD(vp
->rkp
, 'c')) {
136 * Non-motion commands move to the end of the range. Delete
137 * and yank stay at the start. Ignore others.
139 vp
->m_stop
.cno
= len
? len
- 1 : 0;
140 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;