aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h1
-rw-r--r--main.c6
-rw-r--r--vis-motions.c10
-rw-r--r--vis.h1
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) },
diff --git a/main.c b/main.c
index c59261b..7462e1b 100644
--- a/main.c
+++ b/main.c
@@ -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,
+ },
};
diff --git a/vis.h b/vis.h
index 69bef3b..081ae35 100644
--- a/vis.h
+++ b/vis.h
@@ -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,