4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: v_left.c,v 10.9 2001/06/25 15:19:32 skimo Exp (Berkeley) Date: 2001/06/25 15:19:32";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
26 #include "../common/common.h"
30 * v_left -- [count]^H, [count]h
31 * Move left by columns.
33 * PUBLIC: int v_left __P((SCR *, VICMD *));
36 v_left(SCR
*sp
, VICMD
*vp
)
42 * The ^H and h commands always failed in the first column.
44 if (vp
->m_start
.cno
== 0) {
49 /* Find the end of the range. */
50 cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1;
51 if (vp
->m_start
.cno
> cnt
)
52 vp
->m_stop
.cno
= vp
->m_start
.cno
- cnt
;
57 * All commands move to the end of the range. Motion commands
58 * adjust the starting point to the character before the current
63 vp
->m_final
= vp
->m_stop
;
68 * v_cfirst -- [count]_
69 * Move to the first non-blank character in a line.
71 * PUBLIC: int v_cfirst __P((SCR *, VICMD *));
74 v_cfirst(SCR
*sp
, VICMD
*vp
)
80 * If the _ is a motion component, it makes the command a line motion
81 * e.g. "d_" deletes the line. It also means that the cursor doesn't
84 * The _ command never failed in the first column.
90 * Historically a specified count makes _ move down count - 1
91 * rows, so, "3_" is the same as "2j_".
93 cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1;
96 return (v_down(sp
, vp
));
100 * Move to the first non-blank.
102 * Can't just use RCM_SET_FNB, in case _ is used as the motion
103 * component of another command.
106 if (nonblank(sp
, vp
->m_stop
.lno
, &vp
->m_stop
.cno
))
111 * The _ command has to fail if the file is empty and we're doing
112 * a delete. If deleting line 1, and 0 is the first nonblank,
115 if (vp
->m_stop
.lno
== 1 &&
116 vp
->m_stop
.cno
== 0 && ISCMD(vp
->rkp
, 'd')) {
117 if (db_last(sp
, &lno
))
126 * Delete and non-motion commands move to the end of the range,
127 * yank stays at the start. Ignore others.
130 ISMOTION(vp
) && ISCMD(vp
->rkp
, 'y') ? vp
->m_start
: vp
->m_stop
;
136 * Move to the first non-blank character in this line.
138 * PUBLIC: int v_first __P((SCR *, VICMD *));
141 v_first(SCR
*sp
, VICMD
*vp
)
145 * Yielding to none in our quest for compatibility with every
146 * historical blemish of vi, no matter how strange it might be,
147 * we permit the user to enter a count and then ignore it.
151 * Move to the first non-blank.
153 * Can't just use RCM_SET_FNB, in case ^ is used as the motion
154 * component of another command.
157 if (nonblank(sp
, vp
->m_stop
.lno
, &vp
->m_stop
.cno
))
162 * The ^ command succeeded if used as a command when the cursor was
163 * on the first non-blank in the line, but failed if used as a motion
164 * component in the same situation.
166 if (ISMOTION(vp
) && vp
->m_start
.cno
== vp
->m_stop
.cno
) {
172 * If moving right, non-motion commands move to the end of the range.
173 * Delete and yank stay at the start. Motion commands adjust the
174 * ending point to the character before the current ending charcter.
176 * If moving left, all commands move to the end of the range. Motion
177 * commands adjust the starting point to the character before the
178 * current starting character.
180 if (vp
->m_start
.cno
< vp
->m_stop
.cno
)
183 vp
->m_final
= vp
->m_start
;
185 vp
->m_final
= vp
->m_stop
;
189 vp
->m_final
= vp
->m_stop
;
196 * Move to column count or the first column on this line. If the
197 * requested column is past EOL, move to EOL. The nasty part is
198 * that we have to know character column widths to make this work.
200 * PUBLIC: int v_ncol __P((SCR *, VICMD *));
203 v_ncol(SCR
*sp
, VICMD
*vp
)
205 if (F_ISSET(vp
, VC_C1SET
) && vp
->count
> 1) {
208 vs_colpos(sp
, vp
->m_start
.lno
, (size_t)vp
->count
);
211 * The | command succeeded if used as a command and the cursor
212 * didn't move, but failed if used as a motion component in the
215 if (ISMOTION(vp
) && vp
->m_stop
.cno
== vp
->m_start
.cno
) {
222 * The | command succeeded if used as a command in column 0
223 * without a count, but failed if used as a motion component
224 * in the same situation.
226 if (ISMOTION(vp
) && vp
->m_start
.cno
== 0) {
234 * If moving right, non-motion commands move to the end of the range.
235 * Delete and yank stay at the start. Motion commands adjust the
236 * ending point to the character before the current ending charcter.
238 * If moving left, all commands move to the end of the range. Motion
239 * commands adjust the starting point to the character before the
240 * current starting character.
242 if (vp
->m_start
.cno
< vp
->m_stop
.cno
)
245 vp
->m_final
= vp
->m_start
;
247 vp
->m_final
= vp
->m_stop
;
251 vp
->m_final
= vp
->m_stop
;
258 * Move to the first column on this line.
260 * PUBLIC: int v_zero __P((SCR *, VICMD *));
263 v_zero(SCR
*sp
, VICMD
*vp
)
267 * The 0 command succeeded if used as a command in the first column
268 * but failed if used as a motion component in the same situation.
270 if (ISMOTION(vp
) && vp
->m_start
.cno
== 0) {
276 * All commands move to the end of the range. Motion commands
277 * adjust the starting point to the character before the current
283 vp
->m_final
= vp
->m_stop
;