tvi: ; and , commands - neatvi - [fork] simple vi-type editor with UTF-8 support | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 7344f210fcb3b51fa46f90f0ace3bbe126cb47b8 | |
parent 1211e16126a16bac24629d9810462a22a722e75c | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Tue, 12 May 2015 19:01:05 +0430 | |
vi: ; and , commands | |
Diffstat: | |
M vi.c | 48 ++++++++++++++++++-----------… | |
1 file changed, 28 insertions(+), 20 deletions(-) | |
--- | |
diff --git a/vi.c b/vi.c | |
t@@ -18,6 +18,8 @@ int xrow, xcol, xtop; /* current row, column, and top… | |
int xled = 1; /* use the line editor */ | |
int xdir = 'L'; /* current direction context */ | |
int xquit; | |
+static char vi_charlast[8]; /* the last character searched via f, t, F,… | |
+static int vi_charcmd; /* the character finding command */ | |
static void vi_draw(void) | |
{ | |
t@@ -120,30 +122,23 @@ static void lbuf_postindents(struct lbuf *lb, int *r, in… | |
break; | |
} | |
-static void lbuf_findchar(struct lbuf *lb, int *row, int *col, char *cs, int d… | |
+static void lbuf_findchar(struct lbuf *lb, int *row, int *col, char *cs, int c… | |
{ | |
+ int dir = (cmd == 'f' || cmd == 't') ? +1 : -1; | |
int c = *col; | |
- if (!cs) | |
- return; | |
+ if (n < 0) | |
+ dir = -dir; | |
+ if (n < 0) | |
+ n = -n; | |
+ strcpy(vi_charlast, cs); | |
+ vi_charcmd = cmd; | |
while (n > 0 && !lbuf_lnnext(lb, row, &c, dir)) | |
if (uc_code(lbuf_chr(lb, *row, c)) == uc_code(cs)) | |
n--; | |
if (!n) | |
*col = c; | |
-} | |
- | |
-static void lbuf_tochar(struct lbuf *lb, int *row, int *col, char *cs, int dir… | |
-{ | |
- int c = *col; | |
- if (!cs) | |
- return; | |
- while (n > 0 && !lbuf_lnnext(lb, row, &c, dir)) | |
- if (uc_code(lbuf_chr(lb, *row, c)) == uc_code(cs)) | |
- n--; | |
- if (!n) { | |
- *col = c; | |
+ if (!n && (cmd == 't' || cmd == 'T')) | |
lbuf_lnnext(lb, row, col, -dir); | |
- } | |
} | |
static int vi_motionln(int *row, int cmd, int pre1, int pre2) | |
t@@ -261,6 +256,7 @@ static int vi_motion(int *row, int *col, int pre1, int pre… | |
int pre = (pre1 ? pre1 : 1) * (pre2 ? pre2 : 1); | |
char *ln = lbuf_get(xb, *row); | |
int dir = dir_context(ln ? ln : ""); | |
+ char *cs; | |
int i; | |
switch (c) { | |
case ' ': | |
t@@ -269,10 +265,20 @@ static int vi_motion(int *row, int *col, int pre1, int p… | |
break; | |
break; | |
case 'f': | |
- lbuf_findchar(xb, row, col, vi_char(), +1, pre); | |
+ if ((cs = vi_char())) | |
+ lbuf_findchar(xb, row, col, cs, c, pre); | |
break; | |
case 'F': | |
- lbuf_findchar(xb, row, col, vi_char(), -1, pre); | |
+ if ((cs = vi_char())) | |
+ lbuf_findchar(xb, row, col, cs, c, pre); | |
+ break; | |
+ case ';': | |
+ if (vi_charlast[0]) | |
+ lbuf_findchar(xb, row, col, vi_charlast, vi_charcmd, p… | |
+ break; | |
+ case ',': | |
+ if (vi_charlast[0]) | |
+ lbuf_findchar(xb, row, col, vi_charlast, vi_charcmd, -… | |
break; | |
case 'h': | |
for (i = 0; i < pre; i++) | |
t@@ -285,10 +291,12 @@ static int vi_motion(int *row, int *col, int pre1, int p… | |
break; | |
break; | |
case 't': | |
- lbuf_tochar(xb, row, col, vi_char(), 1, pre); | |
+ if ((cs = vi_char())) | |
+ lbuf_findchar(xb, row, col, cs, c, pre); | |
break; | |
case 'T': | |
- lbuf_tochar(xb, row, col, vi_char(), 0, pre); | |
+ if ((cs = vi_char())) | |
+ lbuf_findchar(xb, row, col, cs, c, pre); | |
break; | |
case 'B': | |
for (i = 0; i < pre; i++) |