vis

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

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

commit ab900feddd081a5da0e830bdf255b95868bce191
parent c17be0ec353fc9f7cb7c8939474e833a934224db
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat,  9 Apr 2016 11:41:02 +0200

vis: make sure linewise put operations insert necessary new lines

Given the following text with no trailing new line at the end of line2,
where # denotes the cursor position:

 line1 of text
 line2 #f text

the command yykp should produce

 line1 of text
 #ine2 of text
 line2 of text

where previously it would wrongly result in

 line1 of text
 #ine1 of textline2 of text

Diffstat:
Mvis-operators.c | 2++
1 file changed, 2 insertions(+), 0 deletions(-)

diff --git a/vis-operators.c b/vis-operators.c @@ -62,6 +62,8 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) { pos += text_insert_newline(txt, pos); text_insert(txt, pos, data, len); pos += len; + if (c->reg->linewise && pos > 0 && text_byte_get(txt, pos-1, &nl) && nl != '\n') + pos += text_insert_newline(txt, pos); } if (c->reg->linewise) {