tvi: basic section and paragraph boundaries - neatvi - [fork] simple vi-type ed… | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit d1f4855224db5c5e09d987e742cd43bace5139ba | |
parent 58191346a45866137a12738b1b82b31f40a673aa | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Fri, 15 May 2015 18:32:57 +0430 | |
vi: basic section and paragraph boundaries | |
Diffstat: | |
M vi.c | 45 +++++++++++++++++++++++++++++… | |
1 file changed, 45 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/vi.c b/vi.c | |
t@@ -286,6 +286,27 @@ static int lbuf_wordend(struct lbuf *lb, int *row, int *c… | |
return 0; | |
} | |
+static int lbuf_paragraphbeg(struct lbuf *lb, int *row, int *col, int dir) | |
+{ | |
+ while (*row >= 0 && *row < lbuf_len(lb) && !strcmp("\n", lbuf_get(lb, … | |
+ *row += dir; | |
+ while (*row >= 0 && *row < lbuf_len(lb) && strcmp("\n", lbuf_get(lb, *… | |
+ *row += dir; | |
+ *row = MAX(0, MIN(*row, lbuf_len(lb) - 1)); | |
+ lbuf_eol(lb, row, col, -1); | |
+ return 0; | |
+} | |
+ | |
+static int lbuf_sectionbeg(struct lbuf *lb, int *row, int *col, int dir) | |
+{ | |
+ *row += dir; | |
+ while (*row >= 0 && *row < lbuf_len(lb) && lbuf_get(lb, *row)[0] != '{… | |
+ *row += dir; | |
+ *row = MAX(0, MIN(*row, lbuf_len(lb) - 1)); | |
+ lbuf_eol(lb, row, col, -1); | |
+ return 0; | |
+} | |
+ | |
/* read a line motion */ | |
static int vi_motionln(int *row, int cmd) | |
{ | |
t@@ -436,6 +457,30 @@ static int vi_motion(int *row, int *col) | |
if (lbuf_wordbeg(xb, row, col, 0, +1)) | |
break; | |
break; | |
+ case '{': | |
+ for (i = 0; i < cnt; i++) | |
+ if (lbuf_paragraphbeg(xb, row, col, -1)) | |
+ break; | |
+ break; | |
+ case '}': | |
+ for (i = 0; i < cnt; i++) | |
+ if (lbuf_paragraphbeg(xb, row, col, +1)) | |
+ break; | |
+ break; | |
+ case '[': | |
+ if (vi_read() != '[') | |
+ return -1; | |
+ for (i = 0; i < cnt; i++) | |
+ if (lbuf_sectionbeg(xb, row, col, -1)) | |
+ break; | |
+ break; | |
+ case ']': | |
+ if (vi_read() != ']') | |
+ return -1; | |
+ for (i = 0; i < cnt; i++) | |
+ if (lbuf_sectionbeg(xb, row, col, +1)) | |
+ break; | |
+ break; | |
case '0': | |
lbuf_eol(xb, row, col, -1); | |
break; |