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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
20 #include "../common/common.h"
24 * v_left -- [count]^H, [count]h
25 * Move left by columns.
27 * PUBLIC: int v_left(SCR *, VICMD *);
30 v_left(SCR *sp, VICMD *vp)
36 * The ^H and h commands always failed in the first column.
38 if (vp->m_start.cno == 0) {
43 /* Find the end of the range. */
44 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
45 if (vp->m_start.cno > cnt)
46 vp->m_stop.cno = vp->m_start.cno - cnt;
51 * All commands move to the end of the range. Motion commands
52 * adjust the starting point to the character before the current
57 vp->m_final = vp->m_stop;
62 * v_cfirst -- [count]_
63 * Move to the first non-blank character in a line.
65 * PUBLIC: int v_cfirst(SCR *, VICMD *);
68 v_cfirst(SCR *sp, VICMD *vp)
74 * If the _ is a motion component, it makes the command a line motion
75 * e.g. "d_" deletes the line. It also means that the cursor doesn't
78 * The _ command never failed in the first column.
84 * Historically a specified count makes _ move down count - 1
85 * rows, so, "3_" is the same as "2j_".
87 cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
90 return (v_down(sp, vp));
94 * Move to the first non-blank.
96 * Can't just use RCM_SET_FNB, in case _ is used as the motion
97 * component of another command.
100 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
105 * The _ command has to fail if the file is empty and we're doing
106 * a delete. If deleting line 1, and 0 is the first nonblank,
109 if (vp->m_stop.lno == 1 &&
110 vp->m_stop.cno == 0 && ISCMD(vp->rkp, 'd')) {
111 if (db_last(sp, &lno))
120 * Delete and non-motion commands move to the end of the range,
121 * yank stays at the start. Ignore others.
124 ISMOTION(vp) && ISCMD(vp->rkp, 'y') ? vp->m_start : vp->m_stop;
130 * Move to the first non-blank character in this line.
132 * PUBLIC: int v_first(SCR *, VICMD *);
135 v_first(SCR *sp, VICMD *vp)
139 * Yielding to none in our quest for compatibility with every
140 * historical blemish of vi, no matter how strange it might be,
141 * we permit the user to enter a count and then ignore it.
145 * Move to the first non-blank.
147 * Can't just use RCM_SET_FNB, in case ^ is used as the motion
148 * component of another command.
151 if (nonblank(sp, vp->m_stop.lno, &vp->m_stop.cno))
156 * The ^ command succeeded if used as a command when the cursor was
157 * on the first non-blank in the line, but failed if used as a motion
158 * component in the same situation.
160 if (ISMOTION(vp) && vp->m_start.cno == vp->m_stop.cno) {
166 * If moving right, non-motion commands move to the end of the range.
167 * Delete and yank stay at the start. Motion commands adjust the
168 * ending point to the character before the current ending charcter.
170 * If moving left, all commands move to the end of the range. Motion
171 * commands adjust the starting point to the character before the
172 * current starting character.
174 if (vp->m_start.cno < vp->m_stop.cno)
177 vp->m_final = vp->m_start;
179 vp->m_final = vp->m_stop;
183 vp->m_final = vp->m_stop;
190 * Move to column count or the first column on this line. If the
191 * requested column is past EOL, move to EOL. The nasty part is
192 * that we have to know character column widths to make this work.
194 * PUBLIC: int v_ncol(SCR *, VICMD *);
197 v_ncol(SCR *sp, VICMD *vp)
199 if (F_ISSET(vp, VC_C1SET) && vp->count > 1) {
202 vs_colpos(sp, vp->m_start.lno, (size_t)vp->count);
205 * The | command succeeded if used as a command and the cursor
206 * didn't move, but failed if used as a motion component in the
209 if (ISMOTION(vp) && vp->m_stop.cno == vp->m_start.cno) {
216 * The | command succeeded if used as a command in column 0
217 * without a count, but failed if used as a motion component
218 * in the same situation.
220 if (ISMOTION(vp) && vp->m_start.cno == 0) {
228 * If moving right, non-motion commands move to the end of the range.
229 * Delete and yank stay at the start. Motion commands adjust the
230 * ending point to the character before the current ending charcter.
232 * If moving left, all commands move to the end of the range. Motion
233 * commands adjust the starting point to the character before the
234 * current starting character.
236 if (vp->m_start.cno < vp->m_stop.cno)
239 vp->m_final = vp->m_start;
241 vp->m_final = vp->m_stop;
245 vp->m_final = vp->m_stop;
252 * Move to the first column on this line.
254 * PUBLIC: int v_zero(SCR *, VICMD *);
257 v_zero(SCR *sp, VICMD *vp)
261 * The 0 command succeeded if used as a command in the first column
262 * but failed if used as a motion component in the same situation.
264 if (ISMOTION(vp) && vp->m_start.cno == 0) {
270 * All commands move to the end of the range. Motion commands
271 * adjust the starting point to the character before the current
277 vp->m_final = vp->m_stop;