Skip to content

Commit

Permalink
Merge pull request #1102 from techee/vim_repeat_insert
Browse files Browse the repository at this point in the history
vimode: Enable '.' to also repeat last inserted text
  • Loading branch information
frlan committed Sep 29, 2021
2 parents ae19ca9 + 25291ea commit 00c2a03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
23 changes: 17 additions & 6 deletions vimode/src/cmd-runner.c
Expand Up @@ -633,14 +633,25 @@ static gboolean perform_repeat_cmd(CmdContext *ctx)
gint i;

def = get_cmd_to_run(ctx->repeat_kpl, edit_cmds, FALSE);
if (!def)
return FALSE;

num = num == -1 ? 1 : num;
for (i = 0; i < num; i++)
perform_cmd(def, ctx);
if (def) {
for (i = 0; i < num; i++)
perform_cmd(def, ctx);
return TRUE;
}
else if (ctx->insert_buf_len > 0) {
gint pos;

SSM(ctx->sci, SCI_BEGINUNDOACTION, 0, 0);
for (i = 0; i < num; i++)
SSM(ctx->sci, SCI_ADDTEXT, ctx->insert_buf_len, (sptr_t) ctx->insert_buf);
pos = SSM(ctx->sci, SCI_GETCURRENTPOS, 0, 0);
SET_POS(ctx->sci, PREV(ctx->sci, pos), FALSE);
SSM(ctx->sci, SCI_ENDUNDOACTION, 0, 0);
return TRUE;
}

return TRUE;
return FALSE;
}


Expand Down
4 changes: 2 additions & 2 deletions vimode/src/context.h
Expand Up @@ -22,7 +22,7 @@
#include "vi.h"
#include "sci.h"

#define INSERT_BUF_LEN 4096
#define INSERT_BUF_LEN 131072

typedef struct
{
Expand Down Expand Up @@ -54,7 +54,7 @@ typedef struct
gint num;

/* buffer used in insert/replace mode to record entered text so it can be
* copied N times when e.g. 'i' is preceded by a number */
* copied N times when e.g. 'i' is preceded by a number or when using '.' */
gchar insert_buf[INSERT_BUF_LEN];
gint insert_buf_len;
} CmdContext;
Expand Down
6 changes: 4 additions & 2 deletions vimode/src/vi.c
Expand Up @@ -109,8 +109,6 @@ static void repeat_insert(gboolean replace)
SSM(sci, SCI_ENDUNDOACTION, 0, 0);
}
ctx.num = 1;
ctx.insert_buf_len = 0;
ctx.insert_buf[0] = '\0';
ctx.newline_insert = FALSE;
}

Expand Down Expand Up @@ -156,6 +154,10 @@ void vi_set_mode(ViMode mode)
gint start_pos = SSM(sci, SCI_POSITIONFROMLINE, GET_CUR_LINE(sci), 0);
if (pos > start_pos)
SET_POS(sci, PREV(sci, pos), FALSE);

/* erase kpl so '.' command repeats last inserted text and not command */
g_slist_free_full(ctx.kpl, g_free);
ctx.kpl = NULL;
}
else if (VI_IS_VISUAL(prev_mode))
SSM(sci, SCI_SETEMPTYSELECTION, pos, 0);
Expand Down

0 comments on commit 00c2a03

Please sign in to comment.