aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vis-modes.c7
-rw-r--r--vis.c18
2 files changed, 17 insertions, 8 deletions
diff --git a/vis-modes.c b/vis-modes.c
index 6f861d9..991b21b 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -142,9 +142,16 @@ static void vis_mode_normal_enter(Vis *vis, Mode *old) {
if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH] && !vis->repeat_input) {
vis->repeat_input = true;
if (vis->action_prev.count > 1) {
+ /* temporarily disable motion, in something like `5atext`
+ * we should only move the cursor once then insert the text */
+ const Movement *motion = vis->action_prev.movement;
+ if (motion)
+ vis->action_prev.movement = &vis_motions[VIS_MOVE_NOP];
+ /* we already inserted the text once, so temporarily decrease count */
vis->action_prev.count--;
vis_repeat(vis);
vis->action_prev.count++;
+ vis->action_prev.movement = motion;
}
vis->repeat_input = false;
}
diff --git a/vis.c b/vis.c
index f3864d1..9f7d22c 100644
--- a/vis.c
+++ b/vis.c
@@ -683,6 +683,8 @@ void vis_do(Vis *vis) {
vis_mode_switch(vis, VIS_MODE_VISUAL_LINE);
int count = MAX(a->count, 1);
+ if (a->op == &vis_operators[VIS_OP_MODESWITCH])
+ count = 1; /* count should apply to inserted text not motion */
bool repeatable = a->op && !vis->macro_operator && !vis->win->parent;
bool multiple_cursors = view_cursors_multiple(view);
bool linewise = !(a->type & CHARWISE) && (
@@ -1276,7 +1278,6 @@ bool vis_macro_replay(Vis *vis, enum VisRegister id) {
}
void vis_repeat(Vis *vis) {
- int count = vis->action.count;
Macro *macro_operator = macro_get(vis, VIS_MACRO_OPERATOR);
Macro *macro_repeat = macro_get(vis, VIS_MACRO_REPEAT);
const Macro *macro = vis->action_prev.macro;
@@ -1285,21 +1286,22 @@ void vis_repeat(Vis *vis) {
macro = macro_repeat;
vis->action_prev.macro = macro;
}
+ int count = vis->action.count;
if (count != VIS_COUNT_UNKNOWN)
vis->action_prev.count = count;
- count = vis->action_prev.count;
- /* for some operators count should be applied only to the macro not the motion */
- if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH])
- vis->action_prev.count = 1;
+ else
+ count = vis->action_prev.count;
vis->action = vis->action_prev;
vis_do(vis);
- vis->action_prev.count = count;
if (macro) {
Mode *mode = vis->mode;
Action action_prev = vis->action_prev;
- count = action_prev.count;
- if (count < 1 || action_prev.op == &vis_operators[VIS_OP_CHANGE] || action_prev.op == &vis_operators[VIS_OP_FILTER])
+ if (count < 1 ||
+ action_prev.op == &vis_operators[VIS_OP_CHANGE] ||
+ action_prev.op == &vis_operators[VIS_OP_FILTER])
count = 1;
+ if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH])
+ vis->action_prev.count = 1;
for (int i = 0; i < count; i++) {
mode_set(vis, mode);
macro_replay(vis, macro);