diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-19 11:16:00 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-19 11:18:40 +0100 |
| commit | dfc10a9bacfc71563b2573b54574fb4c9a69d2a9 (patch) | |
| tree | e1fda4bfeba57de15f2701d6cb9d1eaebc81682b | |
| parent | 3622dd1a16a61161bd1f4f2c02b1e222ea7694ae (diff) | |
| download | vis-dfc10a9bacfc71563b2573b54574fb4c9a69d2a9.tar.gz vis-dfc10a9bacfc71563b2573b54574fb4c9a69d2a9.tar.xz | |
vis: make gg and G move to first non-blank character of line
| -rw-r--r-- | vis-motions.c | 20 |
1 files 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, |
