From dfc10a9bacfc71563b2573b54574fb4c9a69d2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 19 Nov 2016 11:16:00 +0100 Subject: vis: make gg and G move to first non-blank character of line --- vis-motions.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/vis-motions.c b/vis-motions.c index adf9b7f..a9c354c 100644 --- 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, -- cgit v1.2.3