aboutsummaryrefslogtreecommitdiff
path: root/vis-motions.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-21 12:53:40 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-21 12:55:09 +0100
commitd7f5912eb1c044399c662329656ab0cca37a471b (patch)
tree7b3fc68e8150333c82587d786abfa8a0f38d6b6f /vis-motions.c
parent559ab349a05d5201b666eddb22d921c40b131bd5 (diff)
downloadvis-d7f5912eb1c044399c662329656ab0cca37a471b.tar.gz
vis-d7f5912eb1c044399c662329656ab0cca37a471b.tar.xz
vis: implement `gh` and `gl` to move by relative byte offsets
Diffstat (limited to 'vis-motions.c')
-rw-r--r--vis-motions.c20
1 files changed, 20 insertions, 0 deletions
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,
+ },
};