vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 7f6945dcab21ab9891a4c64a337284773dc14961
parent 25af59126592d0a5afc46aa0ffbc6ed6ace8b857
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 27 Mar 2016 23:59:54 +0200

vis: support count for {Meta-Ctrl,Ctrl}-{j,k}

Create count new cursors on the lines above/below.

Diffstat:
Mmain.c | 49++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/main.c b/main.c @@ -1202,30 +1202,33 @@ static const char *repeat(Vis *vis, const char *keys, const Arg *arg) { static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - Cursor *cursor; - switch (arg->i) { - case -1: - case +1: - cursor = view_cursors_primary_get(view); - break; - case INT_MIN: - cursor = view_cursors(view); - break; - case INT_MAX: - for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) - cursor = c; - break; - default: - return keys; + for (int count = vis_count_get_default(vis, 1); count > 0; count--) { + Cursor *cursor; + switch (arg->i) { + case -1: + case +1: + cursor = view_cursors_primary_get(view); + break; + case INT_MIN: + cursor = view_cursors(view); + break; + case INT_MAX: + for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) + cursor = c; + break; + default: + return keys; + } + size_t oldpos = view_cursors_pos(cursor); + if (arg->i > 0) + view_line_down(cursor); + else if (arg->i < 0) + view_line_up(cursor); + size_t newpos = view_cursors_pos(cursor); + view_cursors_to(cursor, oldpos); + view_cursors_new(view, newpos); } - size_t oldpos = view_cursors_pos(cursor); - if (arg->i > 0) - view_line_down(cursor); - else if (arg->i < 0) - view_line_up(cursor); - size_t newpos = view_cursors_pos(cursor); - view_cursors_to(cursor, oldpos); - view_cursors_new(view, newpos); + vis_count_set(vis, VIS_COUNT_UNKNOWN); return keys; }