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[] = "@(#)v_left.c 10.7 (Berkeley) 3/6/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
24 #include "../common/common.h"
28 * v_left -- [count]^H, [count]h
29 * Move left by columns.
31 * PUBLIC: int v_left __P((SCR *, VICMD *));
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 *));
82 * If the _ is a motion component, it makes the command a line motion
83 * e.g. "d_" deletes the line. It also means that the cursor doesn't
86 * The _ command never failed in the first column.
92 * Historically a specified count makes _ move down count - 1
93 * rows, so, "3_" is the same as "2j_".
95 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
98 return (v_down(sp, vp));
102 * Move to the first non-blank.
104 * Can't just use RCM_SET_FNB, in case _ is used as the motion
105 * component of another command.
108 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
113 * The _ command has to fail if the file is empty and we're doing
114 * a delete. If deleting line 1, and 0 is the first nonblank,
117 if (vp->m_stop.lno == 1 &&
118 vp->m_stop.cno == 0 && ISCMD(vp->rkp, 'd')) {
119 if (db_last(sp, &lno))
128 * Delete and non-motion commands move to the end of the range,
129 * yank stays at the start. Ignore others.
132 ISMOTION(vp) && ISCMD(vp->rkp, 'y') ? vp->m_start : vp->m_stop;
138 * Move to the first non-blank character in this line.
140 * PUBLIC: int v_first __P((SCR *, VICMD *));
149 * Yielding to none in our quest for compatibility with every
150 * historical blemish of vi, no matter how strange it might be,
151 * we permit the user to enter a count and then ignore it.
155 * Move to the first non-blank.
157 * Can't just use RCM_SET_FNB, in case ^ is used as the motion
158 * component of another command.
161 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
166 * The ^ command succeeded if used as a command when the cursor was
167 * on the first non-blank in the line, but failed if used as a motion
168 * component in the same situation.
170 if (ISMOTION(vp) && vp->m_start.cno == vp->m_stop.cno) {
176 * If moving right, non-motion commands move to the end of the range.
177 * Delete and yank stay at the start. Motion commands adjust the
178 * ending point to the character before the current ending charcter.
180 * If moving left, all commands move to the end of the range. Motion
181 * commands adjust the starting point to the character before the
182 * current starting character.
184 if (vp->m_start.cno < vp->m_stop.cno)
187 vp->m_final = vp->m_start;
189 vp->m_final = vp->m_stop;
193 vp->m_final = vp->m_stop;
200 * Move to column count or the first column on this line. If the
201 * requested column is past EOL, move to EOL. The nasty part is
202 * that we have to know character column widths to make this work.
204 * PUBLIC: int v_ncol __P((SCR *, VICMD *));
211 if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
214 vs_colpos(sp, vp->m_start.lno, (size_t)vp->count);
217 * The | command succeeded if used as a command and the cursor
218 * didn't move, but failed if used as a motion component in the
221 if (ISMOTION(vp) && vp->m_stop.cno == vp->m_start.cno) {
228 * The | command succeeded if used as a command in column 0
229 * without a count, but failed if used as a motion component
230 * in the same situation.
232 if (ISMOTION(vp) && vp->m_start.cno == 0) {
240 * If moving right, non-motion commands move to the end of the range.
241 * Delete and yank stay at the start. Motion commands adjust the
242 * ending point to the character before the current ending charcter.
244 * If moving left, all commands move to the end of the range. Motion
245 * commands adjust the starting point to the character before the
246 * current starting character.
248 if (vp->m_start.cno < vp->m_stop.cno)
251 vp->m_final = vp->m_start;
253 vp->m_final = vp->m_stop;
257 vp->m_final = vp->m_stop;
264 * Move to the first column on this line.
266 * PUBLIC: int v_zero __P((SCR *, VICMD *));
275 * The 0 command succeeded if used as a command in the first column
276 * but failed if used as a motion component in the same situation.
278 if (ISMOTION(vp) && vp->m_start.cno == 0) {
284 * All commands move to the end of the range. Motion commands
285 * adjust the starting point to the character before the current
291 vp->m_final = vp->m_stop;