diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-21 12:53:40 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-21 12:55:09 +0100 |
| commit | d7f5912eb1c044399c662329656ab0cca37a471b (patch) | |
| tree | 7b3fc68e8150333c82587d786abfa8a0f38d6b6f | |
| parent | 559ab349a05d5201b666eddb22d921c40b131bd5 (diff) | |
| download | vis-d7f5912eb1c044399c662329656ab0cca37a471b.tar.gz vis-d7f5912eb1c044399c662329656ab0cca37a471b.tar.xz | |
vis: implement `gh` and `gl` to move by relative byte offsets
| -rw-r--r-- | config.def.h | 2 | ||||
| -rw-r--r-- | main.c | 12 | ||||
| -rw-r--r-- | vis-motions.c | 20 | ||||
| -rw-r--r-- | vis.h | 2 |
4 files changed, 36 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index eb01ac9..1d08434 100644 --- a/config.def.h +++ b/config.def.h @@ -66,6 +66,8 @@ static const KeyBinding bindings_motions[] = { { "F", ACTION(TO_LEFT) }, { "f", ACTION(TO_RIGHT) }, { "go", ACTION(CURSOR_BYTE) }, + { "gh", ACTION(CURSOR_BYTE_LEFT) }, + { "gl", ACTION(CURSOR_BYTE_RIGHT) }, { "g0", ACTION(CURSOR_SCREEN_LINE_BEGIN) }, { "g_", ACTION(CURSOR_LINE_FINISH) }, { "G", ACTION(CURSOR_LINE_LAST) }, @@ -161,6 +161,8 @@ enum { VIS_ACTION_CURSOR_SCREEN_LINE_END, VIS_ACTION_CURSOR_PERCENT, VIS_ACTION_CURSOR_BYTE, + VIS_ACTION_CURSOR_BYTE_LEFT, + VIS_ACTION_CURSOR_BYTE_RIGHT, VIS_ACTION_CURSOR_PARAGRAPH_PREV, VIS_ACTION_CURSOR_PARAGRAPH_NEXT, VIS_ACTION_CURSOR_SENTENCE_PREV, @@ -457,6 +459,16 @@ static const KeyAction vis_action[] = { "Move to absolute byte position", movement, { .i = VIS_MOVE_BYTE } }, + [VIS_ACTION_CURSOR_BYTE_LEFT] = { + "cursor-byte-left", + "Move count bytes to the left", + movement, { .i = VIS_MOVE_BYTE_LEFT } + }, + [VIS_ACTION_CURSOR_BYTE_RIGHT] = { + "cursor-byte-right", + "Move count bytes to the right", + movement, { .i = VIS_MOVE_BYTE_RIGHT } + }, [VIS_ACTION_CURSOR_PARAGRAPH_PREV] = { "cursor-paragraph-prev", "Move cursor paragraph backward", diff --git a/vis-motions.c b/vis-motions.c index 1e9d9c5..c6fcc76 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -227,6 +227,18 @@ static size_t byte(Vis *vis, Text *txt, size_t pos) { return pos <= max ? pos : max; } +static size_t byte_left(Vis *vis, Text *txt, size_t pos) { + size_t off = vis_count_get_default(vis, 1); + return off <= pos ? pos-off : 0; +} + +static size_t byte_right(Vis *vis, Text *txt, size_t pos) { + size_t off = vis_count_get_default(vis, 1); + size_t new = pos + off; + size_t max = text_size(txt); + return new <= max && new > pos ? new : max; +} + void vis_motion_type(Vis *vis, enum VisMotionType type) { vis->action.type = type; } @@ -587,4 +599,12 @@ const Movement vis_motions[] = { .vis = byte, .type = IDEMPOTENT, }, + [VIS_MOVE_BYTE_LEFT] = { + .vis = byte_left, + .type = IDEMPOTENT, + }, + [VIS_MOVE_BYTE_RIGHT] = { + .vis = byte_right, + .type = IDEMPOTENT, + }, }; @@ -284,6 +284,8 @@ enum VisMotion { VIS_MOVE_NOP, VIS_MOVE_PERCENT, VIS_MOVE_BYTE, + VIS_MOVE_BYTE_LEFT, + VIS_MOVE_BYTE_RIGHT, 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, |
