vis

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

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

commit 7e0eb3ea1aa14f6a29f911a06882c8c4fee3c94b
parent c910de605a6e771f4f396d5b094e1e1c1cc86baa
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu,  9 Jul 2015 10:12:25 +0200

vis: improve handling of linewise deletion at end of file

dd on the last line now moves the cursor to the start of the
preceding line.

Diffstat:
Mvis.c | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vis.c b/vis.c @@ -447,13 +447,16 @@ static size_t op_delete(OperatorContext *c) { c->reg->linewise = c->linewise; register_put(c->reg, txt, &c->range); text_delete(txt, c->range.start, len); - return c->range.start; + size_t pos = c->range.start; + if (c->linewise && pos == text_size(txt)) + pos = text_line_begin(txt, text_line_prev(txt, pos)); + return pos; } static size_t op_change(OperatorContext *c) { - size_t pos = op_delete(c); + op_delete(c); switchmode(&(const Arg){ .i = VIS_MODE_INSERT }); - return pos; + return c->range.start; } static size_t op_yank(OperatorContext *c) {