vis

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

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

commit bc8d4ba7551c6d95d9e5d20a86ea6c24d1d2ba70
parent 6ec3d1a60619a0446057d5d2413fa1656f9bfbaf
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Mon, 27 Jul 2015 22:00:53 +0200

vis: CTRL+J and CTRL+K creates a new cursor on the line below/above

Diffstat:
Mconfig.def.h | 2++
Mvis.c | 15+++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -360,6 +360,8 @@ static KeyBinding vis_marks_set[] = { static KeyBinding vis_mode_normal[] = { { { NONE(ESC) }, cursors_clear, { } }, + { { CONTROL('K') }, cursors_new, { .i = -1 } }, + { { CONTROL('J') }, cursors_new, { .i = +1 } }, { { CONTROL('w'), NONE('n') }, cmd, { .s = "open" } }, { { CONTROL('w'), NONE('c') }, cmd, { .s = "q" } }, { { CONTROL('w'), NONE('s') }, cmd, { .s = "split" } }, diff --git a/vis.c b/vis.c @@ -320,6 +320,8 @@ static void totill_repeat(const Arg *arg); static void totill_reverse(const Arg *arg); /* replace character at cursor with one read form keyboard */ static void replace(const Arg *arg); +/* create a new cursor on the previous (arg->i < 0) or next (arg->i > 0) line */ +static void cursors_new(const Arg *arg); /* remove all but the primary cursor and their selections */ static void cursors_clear(const Arg *arg); /* adjust action.count by arg->i */ @@ -827,6 +829,19 @@ static void totill_reverse(const Arg *arg) { movement(&(const Arg){ .i = type }); } +static void cursors_new(const Arg *arg) { + View *view = vis->win->view; + Text *txt = vis->win->file->text; + size_t pos = view_cursor_get(view); + if (arg->i > 0) + pos = text_line_down(txt, pos); + else if (arg->i < 0) + pos = text_line_up(txt, pos); + Cursor *cursor = view_cursors_new(view); + if (cursor) + view_cursors_to(cursor, pos); +} + static void cursors_clear(const Arg *arg) { View *view = vis->win->view; if (view_cursors_count(view) > 1)