vis

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

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

commit a2ad160716aa28fcca23063ea893f0a96e3ab254
parent 2266bcb8841c9f61feec280c7545799b9b20328c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 22 Feb 2017 11:22:13 +0100

vis: simplify `r` implementation and fix cursor positioning

Diffstat:
Mmain.c | 12++----------
Mvis-operators.c | 2+-
2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/main.c b/main.c @@ -1618,17 +1618,9 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) { if (replacement[0] == 0x1b) /* <Escape> */ return next; - if (vis_mode_get(vis) == VIS_MODE_NORMAL) { - int count = vis_count_get_default(vis, 1); - vis_operator(vis, VIS_OP_CHANGE); + vis_operator(vis, VIS_OP_REPLACE, replacement); + if (vis_mode_get(vis) == VIS_MODE_OPERATOR_PENDING) vis_motion(vis, VIS_MOVE_CHAR_NEXT); - for (; count > 0; count--) - vis_keys_feed(vis, replacement[0] == '\n' ? "<Enter>" : replacement); - } else { - vis_operator(vis, VIS_OP_REPLACE, replacement); - } - - vis_keys_feed(vis, "<Escape>"); return next; } diff --git a/vis-operators.c b/vis-operators.c @@ -232,7 +232,7 @@ static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) { size_t pos = c->range.start; for (size_t len = strlen(c->arg->s); count > 0; pos += len, count--) text_insert(txt, pos, c->arg->s, len); - return pos; + return c->range.start; } static size_t op_filter(Vis *vis, Text *txt, OperatorContext *c) {