vis

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

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

commit 71f350fadd7ab01e321e7fe5b7f238e7e37e697c
parent 485ed210eb91b74e8a8d568a6aefe9f204304b84
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 19 Nov 2016 11:16:00 +0100

vis: make gg and G move to first non-blank character of line

Diffstat:
Mvis-motions.c | 20+++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/vis-motions.c b/vis-motions.c @@ -97,8 +97,18 @@ static size_t till_left(Vis *vis, Text *txt, size_t pos) { return pos; } +static size_t firstline(Text *txt, size_t pos) { + return text_line_start(txt, 0); +} + static size_t line(Vis *vis, Text *txt, size_t pos) { - return text_pos_by_lineno(txt, vis_count_get_default(vis, 1)); + int count = vis_count_get_default(vis, 1); + return text_line_start(txt, text_pos_by_lineno(txt, count)); +} + +static size_t lastline(Text *txt, size_t pos) { + pos = text_size(txt); + return text_line_start(txt, pos > 0 ? pos-1 : pos); } static size_t column(Vis *vis, Text *txt, size_t pos) { @@ -486,12 +496,12 @@ const Movement vis_motions[] = { .type = INCLUSIVE|JUMP, }, [VIS_MOVE_FILE_BEGIN] = { - .txt = text_begin, - .type = LINEWISE|JUMP, + .txt = firstline, + .type = LINEWISE|LINEWISE_INCLUSIVE|JUMP|IDEMPOTENT, }, [VIS_MOVE_FILE_END] = { - .txt = text_end, - .type = LINEWISE|JUMP, + .txt = lastline, + .type = LINEWISE|LINEWISE_INCLUSIVE|JUMP|IDEMPOTENT, }, [VIS_MOVE_LEFT_TO] = { .vis = to_left,