4 * Copyright (C) 2015 Ali Gholami Rudi <ali at rudi dot ir>
6 * This program is released under the Modified BSD license.
15 char vi_msg
[512]; /* current message */
16 static char vi_findlast
[256]; /* the last searched keyword */
17 static int vi_finddir
; /* the last search direction */
18 static char vi_charlast
[8]; /* the last character searched via f, t, F, or T */
19 static int vi_charcmd
; /* the character finding command */
20 static int vi_arg1
, vi_arg2
; /* the first and second arguments */
21 static int vi_ybuf
; /* current yank buffer */
22 static char *vi_kmap
; /* current insertion keymap */
23 static int vi_pcol
; /* the column requested by | command */
25 static void vi_drawmsg(void)
27 led_print(vi_msg
, xrows
);
31 static void vi_draw(int xcol
)
35 for (i
= xtop
; i
< xtop
+ xrows
; i
++) {
36 char *s
= lbuf_get(xb
, i
);
37 led_print(s
? s
: (i
? "~" : ""), i
- xtop
);
40 term_pos(xrow
, led_pos(lbuf_get(xb
, i
), xcol
));
44 static int vi_buf
[128];
47 static int vi_read(void)
49 return vi_buflen
? vi_buf
[--vi_buflen
] : term_read(1000);
52 static void vi_back(int c
)
54 if (vi_buflen
< sizeof(vi_buf
))
55 vi_buf
[vi_buflen
++] = c
;
58 static char *vi_char(void)
60 return led_read(&vi_kmap
);
63 static char *vi_prompt(char *msg
, char **kmap
)
65 term_pos(xrows
, led_pos(msg
, 0));
67 return led_prompt(msg
, "", kmap
);
70 char *ex_read(char *msg
)
75 char *s
= led_prompt(msg
, "", &vi_kmap
);
81 while ((c
= getchar()) != EOF
&& c
!= '\n')
90 void ex_show(char *msg
)
93 snprintf(vi_msg
, sizeof(vi_msg
), "%s", msg
);
102 static int vi_yankbuf(void)
111 static int vi_prefix(void)
115 if ((c
>= '1' && c
<= '9')) {
117 n
= n
* 10 + c
- '0';
125 static int vi_col2off(struct lbuf
*lb
, int row
, int col
)
127 char *ln
= lbuf_get(lb
, row
);
128 return ln
? ren_off(ln
, col
) : 0;
131 static int vi_off2col(struct lbuf
*lb
, int row
, int off
)
133 char *ln
= lbuf_get(lb
, row
);
134 return ln
? ren_pos(ln
, off
) : 0;
137 static int vi_nextoff(struct lbuf
*lb
, int dir
, int *row
, int *off
)
140 if (o
< 0 || !lbuf_get(lb
, *row
) || o
>= uc_slen(lbuf_get(lb
, *row
)))
146 static int vi_nextcol(struct lbuf
*lb
, int dir
, int *row
, int *off
)
148 char *ln
= lbuf_get(lb
, *row
);
149 int col
= ln
? ren_pos(ln
, *off
) : 0;
150 int o
= ln
? ren_next(ln
, col
, dir
) : -1;
153 *off
= ren_off(ln
, o
);
157 static int vi_findchar(struct lbuf
*lb
, char *cs
, int cmd
, int n
, int *row
, int *off
)
159 strcpy(vi_charlast
, cs
);
161 return lbuf_findchar(lb
, cs
, cmd
, n
, row
, off
);
164 static int vi_search(int cmd
, int cnt
, int *row
, int *off
)
172 if (cmd
== '/' || cmd
== '?') {
173 char sign
[4] = {cmd
};
174 char *kw
= vi_prompt(sign
, &vi_kmap
);
177 vi_finddir
= cmd
== '/' ? +1 : -1;
179 snprintf(vi_findlast
, sizeof(vi_findlast
), "%s", kw
);
180 if (strchr(vi_findlast
, cmd
)) {
181 soff
= strchr(vi_findlast
, cmd
) + 1;
182 *strchr(vi_findlast
, cmd
) = '\0';
186 dir
= cmd
== 'N' ? -vi_finddir
: vi_finddir
;
187 if (!vi_findlast
[0] || !lbuf_len(xb
))
190 for (i
= 0; i
< cnt
; i
++) {
191 if (lbuf_search(xb
, vi_findlast
, dir
, &r
, &o
, &len
)) {
195 if (i
+ 1 < cnt
&& cmd
== '/')
201 while (soff
[0] && isspace((unsigned char) soff
[0]))
205 if (*row
+ atoi(soff
) < 0 || *row
+ atoi(soff
) >= lbuf_len(xb
))
212 snprintf(vi_msg
, sizeof(vi_msg
), "\"%s\" not found\n", vi_findlast
);
216 /* read a line motion */
217 static int vi_motionln(int *row
, int cmd
)
219 int cnt
= (vi_arg1
? vi_arg1
: 1) * (vi_arg2
? vi_arg2
: 1);
221 int mark
, mark_row
, mark_off
;
225 *row
= MIN(*row
+ cnt
, lbuf_len(xb
) - 1);
228 *row
= MAX(*row
- cnt
, 0);
231 *row
= MIN(*row
+ cnt
- 1, lbuf_len(xb
) - 1);
234 if ((mark
= vi_read()) <= 0)
236 if (lbuf_jump(xb
, mark
, &mark_row
, &mark_off
))
241 *row
= MIN(*row
+ cnt
, lbuf_len(xb
) - 1);
244 *row
= MAX(*row
- cnt
, 0);
247 *row
= (vi_arg1
|| vi_arg2
) ? cnt
- 1 : lbuf_len(xb
) - 1;
251 *row
= MIN(xtop
+ cnt
- 1, lbuf_len(xb
) - 1);
257 *row
= MIN(xtop
+ xrows
- 1 - cnt
+ 1, lbuf_len(xb
) - 1);
263 *row
= MIN(xtop
+ xrows
/ 2, lbuf_len(xb
) - 1);
269 *row
= MAX(0, MIN(*row
+ cnt
- 1, lbuf_len(xb
) - 1));
278 static char *vi_curword(struct lbuf
*lb
, int row
, int off
)
281 char *ln
= lbuf_get(lb
, row
);
285 beg
= uc_chr(ln
, ren_noeol(ln
, off
));
287 while (*end
&& uc_kind(end
) == 1)
289 while (beg
> ln
&& uc_kind(uc_beg(ln
, beg
- 1)) == 1)
290 beg
= uc_beg(ln
, beg
- 1);
295 sbuf_mem(sb
, beg
, end
- beg
);
297 return sbuf_done(sb
);
301 static int vi_motion(int *row
, int *off
)
303 int cnt
= (vi_arg1
? vi_arg1
: 1) * (vi_arg2
? vi_arg2
: 1);
304 char *ln
= lbuf_get(xb
, *row
);
305 int dir
= dir_context(ln
? ln
: "");
306 int mark
, mark_row
, mark_off
;
310 if ((mv
= vi_motionln(row
, 0))) {
317 if (!(cs
= vi_char()))
319 if (vi_findchar(xb
, cs
, mv
, cnt
, row
, off
))
323 if (!(cs
= vi_char()))
325 if (vi_findchar(xb
, cs
, mv
, cnt
, row
, off
))
331 if (vi_findchar(xb
, vi_charlast
, vi_charcmd
, cnt
, row
, off
))
337 if (vi_findchar(xb
, vi_charlast
, vi_charcmd
, -cnt
, row
, off
))
341 for (i
= 0; i
< cnt
; i
++)
342 if (vi_nextcol(xb
, -1 * dir
, row
, off
))
346 for (i
= 0; i
< cnt
; i
++)
347 if (vi_nextcol(xb
, +1 * dir
, row
, off
))
351 if (!(cs
= vi_char()))
353 if (vi_findchar(xb
, cs
, mv
, cnt
, row
, off
))
357 if (!(cs
= vi_char()))
359 if (vi_findchar(xb
, cs
, mv
, cnt
, row
, off
))
363 for (i
= 0; i
< cnt
; i
++)
364 if (lbuf_wordend(xb
, 1, -1, row
, off
))
368 for (i
= 0; i
< cnt
; i
++)
369 if (lbuf_wordend(xb
, 1, +1, row
, off
))
373 for (i
= 0; i
< cnt
; i
++)
374 if (lbuf_wordbeg(xb
, 1, +1, row
, off
))
378 for (i
= 0; i
< cnt
; i
++)
379 if (lbuf_wordend(xb
, 0, -1, row
, off
))
383 for (i
= 0; i
< cnt
; i
++)
384 if (lbuf_wordend(xb
, 0, +1, row
, off
))
388 for (i
= 0; i
< cnt
; i
++)
389 if (lbuf_wordbeg(xb
, 0, +1, row
, off
))
393 for (i
= 0; i
< cnt
; i
++)
394 if (lbuf_paragraphbeg(xb
, -1, row
, off
))
398 for (i
= 0; i
< cnt
; i
++)
399 if (lbuf_paragraphbeg(xb
, +1, row
, off
))
403 if (vi_read() != '[')
405 for (i
= 0; i
< cnt
; i
++)
406 if (lbuf_sectionbeg(xb
, -1, row
, off
))
410 if (vi_read() != ']')
412 for (i
= 0; i
< cnt
; i
++)
413 if (lbuf_sectionbeg(xb
, +1, row
, off
))
420 *off
= lbuf_indents(xb
, *row
);
423 *off
= lbuf_eol(xb
, *row
);
426 *off
= vi_col2off(xb
, *row
, cnt
- 1);
430 if (vi_search(mv
, cnt
, row
, off
))
434 if (vi_search(mv
, cnt
, row
, off
))
438 if (vi_search(mv
, cnt
, row
, off
))
442 if (vi_search(mv
, cnt
, row
, off
))
446 if (!(cs
= vi_curword(xb
, *row
, *off
)))
448 strcpy(vi_findlast
, cs
);
451 if (vi_search('n', cnt
, row
, off
))
455 for (i
= 0; i
< cnt
; i
++)
456 if (vi_nextoff(xb
, +1, row
, off
))
461 for (i
= 0; i
< cnt
; i
++)
462 if (vi_nextoff(xb
, -1, row
, off
))
466 if ((mark
= vi_read()) <= 0)
468 if (lbuf_jump(xb
, mark
, &mark_row
, &mark_off
))
480 static void swap(int *a
, int *b
)
487 static char *lbuf_region(struct lbuf
*lb
, int r1
, int o1
, int r2
, int o2
)
492 return uc_sub(lbuf_get(lb
, r1
), o1
, o2
);
494 s1
= uc_sub(lbuf_get(lb
, r1
), o1
, -1);
495 s3
= uc_sub(lbuf_get(lb
, r2
), 0, o2
);
496 s2
= lbuf_cp(lb
, r1
+ 1, r2
);
503 return sbuf_done(sb
);
506 static void vi_yank(int r1
, int o1
, int r2
, int o2
, int lnmode
)
509 region
= lbuf_region(xb
, r1
, lnmode
? 0 : o1
, r2
, lnmode
? -1 : o2
);
510 reg_put(vi_ybuf
, region
, lnmode
);
513 xoff
= lnmode
? xoff
: o1
;
516 static void vi_delete(int r1
, int o1
, int r2
, int o2
, int lnmode
)
520 region
= lbuf_region(xb
, r1
, lnmode
? 0 : o1
, r2
, lnmode
? -1 : o2
);
521 reg_put(vi_ybuf
, region
, lnmode
);
523 pref
= lnmode
? uc_dup("") : uc_sub(lbuf_get(xb
, r1
), 0, o1
);
524 post
= lnmode
? uc_dup("\n") : uc_sub(lbuf_get(xb
, r2
), o2
, -1);
525 lbuf_rm(xb
, r1
, r2
+ 1);
527 struct sbuf
*sb
= sbuf_make();
530 lbuf_put(xb
, r1
, sbuf_buf(sb
));
534 xoff
= lnmode
? lbuf_indents(xb
, xrow
) : o1
;
539 static int linecount(char *s
)
543 if ((s
= strchr(s
, '\n')))
548 static int indentscopy(char *d
, char *s
, int len
)
551 for (i
= 0; i
< len
- 1 && (s
[i
] == ' ' || s
[i
] == '\t'); i
++)
557 static char *vi_input(char *pref
, char *post
, int *row
, int *off
)
564 pref
+= indentscopy(ai
, pref
, sizeof(ai
));
565 rep
= led_input(pref
, post
, ai
, xai
? sizeof(ai
) - 1 : 0, &vi_kmap
);
573 last
= uc_lastline(s
) - s
;
574 *off
= MAX(0, uc_slen(sbuf_buf(sb
) + last
) - 1);
576 while (xai
&& (post
[0] == ' ' || post
[0] == '\t'))
579 *row
= linecount(sbuf_buf(sb
)) - 1;
581 return sbuf_done(sb
);
584 static char *vi_indents(char *ln
)
586 struct sbuf
*sb
= sbuf_make();
587 while (xai
&& ln
&& (*ln
== ' ' || *ln
== '\t'))
589 return sbuf_done(sb
);
592 static void vi_change(int r1
, int o1
, int r2
, int o2
, int lnmode
)
598 region
= lbuf_region(xb
, r1
, lnmode
? 0 : o1
, r2
, lnmode
? -1 : o2
);
599 reg_put(vi_ybuf
, region
, lnmode
);
601 pref
= lnmode
? vi_indents(lbuf_get(xb
, r1
)) : uc_sub(lbuf_get(xb
, r1
), 0, o1
);
602 post
= lnmode
? uc_dup("\n") : uc_sub(lbuf_get(xb
, r2
), o2
, -1);
603 rep
= vi_input(pref
, post
, &row
, &off
);
605 lbuf_rm(xb
, r1
, r2
+ 1);
606 lbuf_put(xb
, r1
, rep
);
615 static void vi_case(int r1
, int o1
, int r2
, int o2
, int lnmode
, int cmd
)
619 region
= lbuf_region(xb
, r1
, lnmode
? 0 : o1
, r2
, lnmode
? -1 : o2
);
622 int c
= (unsigned char) s
[0];
629 s
[0] = islower(c
) ? toupper(c
) : tolower(c
);
633 pref
= lnmode
? uc_dup("") : uc_sub(lbuf_get(xb
, r1
), 0, o1
);
634 post
= lnmode
? uc_dup("\n") : uc_sub(lbuf_get(xb
, r2
), o2
, -1);
635 lbuf_rm(xb
, r1
, r2
+ 1);
637 struct sbuf
*sb
= sbuf_make();
639 sbuf_str(sb
, region
);
641 lbuf_put(xb
, r1
, sbuf_buf(sb
));
644 lbuf_put(xb
, r1
, region
);
647 xoff
= lnmode
? lbuf_indents(xb
, r2
) : o2
;
653 static void vi_pipe(int r1
, int r2
)
658 char *cmd
= vi_prompt("!", &kmap
);
661 text
= lbuf_cp(xb
, r1
, r2
+ 1);
662 rep
= cmd_pipe(cmd
, text
);
664 lbuf_rm(xb
, r1
, r2
+ 1);
665 lbuf_put(xb
, r1
, rep
);
672 static void vi_shift(int r1
, int r2
, int dir
)
677 for (i
= r1
; i
<= r2
; i
++) {
678 if (!(ln
= lbuf_get(xb
, i
)))
684 ln
= ln
[0] == ' ' || ln
[0] == '\t' ? ln
+ 1 : ln
;
686 lbuf_rm(xb
, i
, i
+ 1);
687 lbuf_put(xb
, i
, sbuf_buf(sb
));
691 xoff
= lbuf_indents(xb
, xrow
);
694 static int vc_motion(int cmd
)
696 int r1
= xrow
, r2
= xrow
; /* region rows */
697 int o1
= xoff
, o2
= xoff
; /* visual region columns */
698 int lnmode
= 0; /* line-based region */
700 vi_arg2
= vi_prefix();
703 o1
= ren_noeol(lbuf_get(xb
, r1
), o1
);
705 if ((mv
= vi_motionln(&r2
, cmd
))) {
707 } else if (!(mv
= vi_motion(&r2
, &o2
))) {
716 o2
= lbuf_eol(xb
, r2
);
722 if (r1
== r2
&& o1
> o2
)
724 o1
= ren_noeol(lbuf_get(xb
, r1
), o1
);
725 if (!lnmode
&& strchr("fFtTeE", mv
))
726 if (o2
< lbuf_eol(xb
, r2
))
727 o2
= ren_noeol(lbuf_get(xb
, r2
), o2
) + 1;
729 vi_yank(r1
, o1
, r2
, o2
, lnmode
);
731 vi_delete(r1
, o1
, r2
, o2
, lnmode
);
733 vi_change(r1
, o1
, r2
, o2
, lnmode
);
734 if (cmd
== '~' || cmd
== 'u' || cmd
== 'U')
735 vi_case(r1
, o1
, r2
, o2
, lnmode
, cmd
);
738 if (cmd
== '>' || cmd
== '<')
739 vi_shift(r1
, r2
, cmd
== '>' ? +1 : -1);
743 static int vc_insert(int cmd
)
746 char *ln
= lbuf_get(xb
, xrow
);
750 xoff
= lbuf_indents(xb
, xrow
);
752 xoff
= lbuf_eol(xb
, xrow
);
753 xoff
= ren_noeol(ln
, xoff
);
756 if (cmd
== 'i' || cmd
== 'I')
758 if (cmd
== 'a' || cmd
== 'A')
760 pref
= ln
&& cmd
!= 'o' && cmd
!= 'O' ? uc_sub(ln
, 0, off
) : vi_indents(ln
);
761 post
= ln
&& cmd
!= 'o' && cmd
!= 'O' ? uc_sub(ln
, off
, -1) : uc_dup("\n");
762 rep
= vi_input(pref
, post
, &row
, &off
);
763 if ((cmd
== 'o' || cmd
== 'O') && !lbuf_len(xb
))
764 lbuf_put(xb
, 0, "\n");
766 if (cmd
!= 'o' && cmd
!= 'O')
767 lbuf_rm(xb
, xrow
, xrow
+ 1);
768 lbuf_put(xb
, xrow
, rep
);
778 static int vc_put(int cmd
)
780 int cnt
= MAX(1, vi_arg1
);
782 char *buf
= reg_get(vi_ybuf
, &lnmode
);
787 struct sbuf
*sb
= sbuf_make();
788 for (i
= 0; i
< cnt
; i
++)
791 lbuf_put(xb
, 0, "\n");
794 lbuf_put(xb
, xrow
, sbuf_buf(sb
));
795 xoff
= lbuf_indents(xb
, xrow
);
798 struct sbuf
*sb
= sbuf_make();
799 char *ln
= xrow
< lbuf_len(xb
) ? lbuf_get(xb
, xrow
) : "\n";
800 int off
= ren_noeol(ln
, xoff
) + (ln
[0] != '\n' && cmd
== 'p');
801 char *s
= uc_sub(ln
, 0, off
);
804 for (i
= 0; i
< cnt
; i
++)
806 s
= uc_sub(ln
, off
, -1);
809 lbuf_rm(xb
, xrow
, xrow
+ 1);
810 lbuf_put(xb
, xrow
, sbuf_buf(sb
));
811 xoff
= off
+ uc_slen(buf
) * cnt
- 1;
817 static int join_spaces(char *prev
, char *next
)
819 int prevlen
= strlen(prev
);
822 if (prev
[prevlen
- 1] == ' ' || next
[0] == ')')
824 return prev
[prevlen
- 1] == '.' ? 2 : 1;
827 static int vc_join(void)
830 int cnt
= vi_arg1
<= 1 ? 2 : vi_arg1
;
832 int end
= xrow
+ cnt
;
835 if (!lbuf_get(xb
, beg
) || !lbuf_get(xb
, end
- 1))
838 for (i
= beg
; i
< end
; i
++) {
839 char *ln
= lbuf_get(xb
, i
);
840 char *lnend
= strchr(ln
, '\n');
843 while (ln
[0] == ' ' || ln
[0] == '\t')
845 spaces
= i
> beg
? join_spaces(sbuf_buf(sb
), ln
) : 0;
846 off
= uc_slen(sbuf_buf(sb
));
849 sbuf_mem(sb
, ln
, lnend
- ln
);
852 lbuf_rm(xb
, beg
, end
);
853 lbuf_put(xb
, beg
, sbuf_buf(sb
));
859 static int vi_scrollforeward(int cnt
)
861 if (xtop
>= lbuf_len(xb
) - 1)
863 xtop
= MIN(lbuf_len(xb
) - 1, xtop
+ cnt
);
864 xrow
= MAX(xrow
, xtop
);
868 static int vi_scrollbackward(int cnt
)
872 xtop
= MAX(0, xtop
- cnt
);
873 xrow
= MIN(xrow
, xtop
+ xrows
- 1);
877 static void vc_status(void)
879 int col
= vi_off2col(xb
, xrow
, xoff
);
880 snprintf(vi_msg
, sizeof(vi_msg
),
881 "\"%s\"%c %d lines L%d C%d\n",
882 xpath
[0] ? xpath
: "unnamed",
883 lbuf_modified(xb
) ? '*' : ' ',
884 lbuf_len(xb
), xrow
+ 1,
885 ren_cursor(lbuf_get(xb
, xrow
), col
) + 1);
888 static int vc_replace(void)
890 int cnt
= MAX(1, vi_arg1
);
891 char *cs
= vi_char();
892 char *ln
= lbuf_get(xb
, xrow
);
899 off
= ren_noeol(ln
, xoff
);
901 for (i
= 0; s
[0] != '\n' && i
< cnt
; i
++)
905 pref
= uc_sub(ln
, 0, off
);
906 post
= uc_sub(ln
, off
+ cnt
, -1);
909 for (i
= 0; i
< cnt
; i
++)
912 lbuf_rm(xb
, xrow
, xrow
+ 1);
913 lbuf_put(xb
, xrow
, sbuf_buf(sb
));
922 static char rep_cmd
[4096]; /* the last command */
925 static void vc_repeat(void)
927 term_push(rep_cmd
, rep_len
);
930 static void vc_execute(void)
941 buf
= reg_get(exec_buf
, &lnmode
);
943 term_push(buf
, strlen(buf
));
956 xcol
= vi_off2col(xb
, xrow
, xoff
);
958 term_pos(xrow
, led_pos(lbuf_get(xb
, xrow
), xcol
));
962 int noff
= ren_noeol(lbuf_get(xb
, xrow
), xoff
);
967 vi_ybuf
= vi_yankbuf();
968 vi_arg1
= vi_prefix();
970 vi_ybuf
= vi_yankbuf();
971 mv
= vi_motion(&nrow
, &noff
);
973 if (strchr("\'`GHML/?{}[]nN", mv
)) {
974 lbuf_mark(xb
, '\'', xrow
, xoff
);
975 lbuf_mark(xb
, '`', xrow
, xoff
);
978 if (noff
< 0 && !strchr("jk", mv
))
979 noff
= lbuf_indents(xb
, xrow
);
980 if (strchr("jk", mv
))
981 noff
= vi_col2off(xb
, xrow
, xcol
);
982 xoff
= ren_noeol(lbuf_get(xb
, xrow
), noff
);
983 if (!strchr("|jk", mv
))
984 xcol
= vi_off2col(xb
, xrow
, xoff
);
987 } else if (mv
== 0) {
993 lbuf_mark(xb
, '*', xrow
, xoff
);
996 if (vi_scrollbackward(MAX(1, vi_arg1
) * (xrows
- 1)))
998 xoff
= lbuf_indents(xb
, xrow
);
1002 if (vi_scrollforeward(MAX(1, vi_arg1
) * (xrows
- 1)))
1004 xoff
= lbuf_indents(xb
, xrow
);
1008 if (vi_scrollforeward(MAX(1, vi_arg1
)))
1013 if (vi_scrollbackward(MAX(1, vi_arg1
)))
1023 if (!lbuf_undo(xb
)) {
1024 lbuf_jump(xb
, '*', &xrow
, &xoff
);
1027 snprintf(vi_msg
, sizeof(vi_msg
), "undo failed\n");
1031 if (!lbuf_redo(xb
)) {
1032 lbuf_jump(xb
, '*', &xrow
, &xoff
);
1035 snprintf(vi_msg
, sizeof(vi_msg
), "redo failed\n");
1046 ln
= vi_prompt(":", &kmap
);
1078 if ((mark
= vi_read()) > 0 && islower(mark
))
1079 lbuf_mark(xb
, mark
, xrow
, xoff
);
1090 xtop
= vi_arg1
? vi_arg1
: xrow
;
1093 n
= vi_arg1
? vi_arg1
: xrow
;
1094 xtop
= MAX(0, n
- xrows
/ 2);
1097 n
= vi_arg1
? vi_arg1
: xrow
;
1098 xtop
= MAX(0, n
- xrows
+ 1);
1102 xdir
= z
== 'r' ? -1 : +1;
1106 xdir
= z
== 'R' ? -2 : +2;
1113 if (g
== '~' || g
== 'u' || g
== 'U')
1119 if (!vc_motion('d'))
1123 vi_back(TK_CTL('h'));
1124 if (!vc_motion('d'))
1129 if (!vc_motion('c'))
1134 if (!vc_motion('d'))
1143 if (!vc_motion('c'))
1148 if (!vc_motion('c'))
1153 if (!vc_motion('y'))
1158 if (!vc_motion('~'))
1171 if (strchr("!<>ACDIJOPRSXYacdioprsxy~", c
)) {
1172 if (n
< sizeof(rep_cmd
)) {
1173 memcpy(rep_cmd
, cmd
, n
);
1178 if (xrow
< 0 || xrow
>= lbuf_len(xb
))
1179 xrow
= lbuf_len(xb
) ? lbuf_len(xb
) - 1 : 0;
1181 xtop
= xtop
- xrows
/ 2 > xrow
?
1182 MAX(0, xrow
- xrows
/ 2) : xrow
;
1183 if (xtop
+ xrows
<= xrow
)
1184 xtop
= xtop
+ xrows
+ xrows
/ 2 <= xrow
?
1185 xrow
- xrows
/ 2 : xrow
- xrows
+ 1;
1186 xoff
= ren_noeol(lbuf_get(xb
, xrow
), xoff
);
1188 xcol
= vi_off2col(xb
, xrow
, xoff
);
1189 if (redraw
|| xtop
!= otop
)
1193 term_pos(xrow
- xtop
, led_pos(lbuf_get(xb
, xrow
),
1194 ren_cursor(lbuf_get(xb
, xrow
), xcol
)));
1202 int main(int argc
, char *argv
[])
1208 for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
1209 if (argv
[i
][1] == 's')
1211 if (argv
[i
][1] == 'e')
1213 if (argv
[i
][1] == 'v')
1219 snprintf(ecmd
, PATHLEN
, "e %s", argv
[i
]);