From d143657a79e250bdb91dff9a90d882c95f4b94a2 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 5 Dec 2014 14:58:44 +0000 Subject: vi: fix reading of file after last line If the :r command is used to read a file after the last line of the buffer the last line of the buffer and the first line of the file are joined. An extra blank line appears at the end of the buffer. file 1 file 1 file 1file 2 file 2 file 2 ~ ~ The insertion point is normally at the start of the line following the specified line. When the specified line is the last one the next_line function baulks at moving to the non-existent following line. --- editors/vi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/editors/vi.c b/editors/vi.c index 84da6db74..1fa97b568 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1318,8 +1318,12 @@ static void colon(char *buf) q = begin_line(dot); // assume "dot" } // read after current line- unless user said ":0r foo" - if (b != 0) + if (b != 0) { q = next_line(q); + // read after last line + if (q == end-1) + ++q; + } { // dance around potentially-reallocated text[] uintptr_t ofs = q - text; size = file_insert(fn, q, 0); -- cgit v1.2.3-55-g6feb