2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: v_right.c,v 10.8 2001/06/25 15:19:34 skimo Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
24 #include "../common/common.h"
28 * v_right -- [count]' ', [count]l
29 * Move right by columns.
31 * PUBLIC: int v_right(SCR *, VICMD *);
34 v_right(SCR
*sp
, VICMD
*vp
)
39 if (db_eget(sp
, vp
->m_start
.lno
, NULL
, &len
, &isempty
)) {
45 /* It's always illegal to move right on empty lines. */
52 * Non-motion commands move to the end of the range. Delete and
53 * yank stay at the start. Ignore others. Adjust the end of the
54 * range for motion commands.
57 * Historically, "[cdsy]l" worked at the end of a line. Also,
58 * EOL is a count sink.
60 vp
->m_stop
.cno
= vp
->m_start
.cno
+
61 (F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1);
62 if (vp
->m_start
.cno
== len
- 1 && !ISMOTION(vp
)) {
66 if (vp
->m_stop
.cno
>= len
) {
67 vp
->m_stop
.cno
= len
- 1;
68 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;
69 } else if (ISMOTION(vp
)) {
71 vp
->m_final
= vp
->m_start
;
73 vp
->m_final
= vp
->m_stop
;
78 * v_dollar -- [count]$
79 * Move to the last column.
81 * PUBLIC: int v_dollar(SCR *, VICMD *);
84 v_dollar(SCR
*sp
, VICMD
*vp
)
91 * A count moves down count - 1 rows, so, "3$" is the same as "2j$".
93 if ((F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1) != 1) {
96 * Historically, if the $ is a motion, and deleting from
97 * at or before the first non-blank of the line, it's a
98 * line motion, and the line motion flag is set.
101 if (nonblank(sp
, vp
->m_start
.lno
, &vp
->m_stop
.cno
))
103 if (ISMOTION(vp
) && vp
->m_start
.cno
<= vp
->m_stop
.cno
)
113 * Historically, it was illegal to use $ as a motion command on
114 * an empty line. Unfortunately, even though C was historically
115 * aliased to c$, it (and not c$) was special cased to work on
116 * empty lines. Since we alias C to c$ too, we have a problem.
117 * To fix it, we let c$ go through, on the assumption that it's
118 * not a problem for it to work.
120 if (db_eget(sp
, vp
->m_stop
.lno
, NULL
, &len
, &isempty
)) {
127 if (ISMOTION(vp
) && !ISCMD(vp
->rkp
, 'c')) {
135 * Non-motion commands move to the end of the range. Delete
136 * and yank stay at the start. Ignore others.
138 vp
->m_stop
.cno
= len
? len
- 1 : 0;
139 vp
->m_final
= ISMOTION(vp
) ? vp
->m_start
: vp
->m_stop
;