diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-21 12:25:58 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-21 12:54:31 +0100 |
| commit | 559ab349a05d5201b666eddb22d921c40b131bd5 (patch) | |
| tree | 107c95f6ddc10bec2837ed452aa97410a572b9cc | |
| parent | 0109dfc0d4e65751571a86aa91ae3c9947182ba0 (diff) | |
| download | vis-559ab349a05d5201b666eddb22d921c40b131bd5.tar.gz vis-559ab349a05d5201b666eddb22d921c40b131bd5.tar.xz | |
vis: implement `go` to move to absolute byte position
| -rw-r--r-- | config.def.h | 1 | ||||
| -rw-r--r-- | main.c | 6 | ||||
| -rw-r--r-- | vis-motions.c | 10 | ||||
| -rw-r--r-- | vis.h | 1 |
4 files changed, 18 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index cc68a84..eb01ac9 100644 --- a/config.def.h +++ b/config.def.h @@ -65,6 +65,7 @@ static const KeyBinding bindings_motions[] = { { "<Enter>", ALIAS("j") }, { "F", ACTION(TO_LEFT) }, { "f", ACTION(TO_RIGHT) }, + { "go", ACTION(CURSOR_BYTE) }, { "g0", ACTION(CURSOR_SCREEN_LINE_BEGIN) }, { "g_", ACTION(CURSOR_LINE_FINISH) }, { "G", ACTION(CURSOR_LINE_LAST) }, @@ -160,6 +160,7 @@ enum { VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE, VIS_ACTION_CURSOR_SCREEN_LINE_END, VIS_ACTION_CURSOR_PERCENT, + VIS_ACTION_CURSOR_BYTE, VIS_ACTION_CURSOR_PARAGRAPH_PREV, VIS_ACTION_CURSOR_PARAGRAPH_NEXT, VIS_ACTION_CURSOR_SENTENCE_PREV, @@ -451,6 +452,11 @@ static const KeyAction vis_action[] = { "Move to count % of file or matching item", percent }, + [VIS_ACTION_CURSOR_BYTE] = { + "cursor-byte", + "Move to absolute byte position", + movement, { .i = VIS_MOVE_BYTE } + }, [VIS_ACTION_CURSOR_PARAGRAPH_PREV] = { "cursor-paragraph-prev", "Move cursor paragraph backward", diff --git a/vis-motions.c b/vis-motions.c index a9c354c..1e9d9c5 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -221,6 +221,12 @@ static size_t percent(Vis *vis, Text *txt, size_t pos) { return text_size(txt) * ratio / 100; } +static size_t byte(Vis *vis, Text *txt, size_t pos) { + pos = vis_count_get_default(vis, 0); + size_t max = text_size(txt); + return pos <= max ? pos : max; +} + void vis_motion_type(Vis *vis, enum VisMotionType type) { vis->action.type = type; } @@ -577,4 +583,8 @@ const Movement vis_motions[] = { .vis = percent, .type = IDEMPOTENT, }, + [VIS_MOVE_BYTE] = { + .vis = byte, + .type = IDEMPOTENT, + }, }; @@ -283,6 +283,7 @@ enum VisMotion { VIS_MOVE_JUMPLIST_PREV, VIS_MOVE_NOP, VIS_MOVE_PERCENT, + VIS_MOVE_BYTE, VIS_MOVE_INVALID, /* denotes the end of the "real" motions */ /* pseudo motions: keep them at the end to save space in array definition */ VIS_MOVE_TOTILL_REPEAT, |
