From 52e0ed4ff0444574385d0e832b1bfdac52c3e03e Mon Sep 17 00:00:00 2001 From: Oliver Webb Date: Mon, 9 Oct 2023 21:52:40 -0500 Subject: [PATCH] vi.c: Added ex 'g' command, Replaced "sleep(1)" with getchar() in error handler --- toys/pending/vi.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/toys/pending/vi.c b/toys/pending/vi.c index 2b5777a8..ee6fd96e 100644 --- a/toys/pending/vi.c +++ b/toys/pending/vi.c @@ -547,9 +547,9 @@ static void show_error(char *fmt, ...) printf("\e[0m"); xflush(1); - // TODO: better integration with status line: remove sleep and keep + // TODO: better integration with status line: keep // message until next operation. - sleep(1); + (void)getchar(); } static void linelist_unload() @@ -1371,6 +1371,24 @@ static int run_ex_cmd(char *cmd) else if (*(cmd+1) == 'd') { run_vi_cmd("dd"); run_vi_cmd("k"); + } else if (*(cmd+1) == 'g') { + char *rgx = malloc(strlen(cmd)); + int el = get_endline(), ln = 0; + regex_t rgxc; + if (!sscanf(cmd, ":g/%[^/]/%[^\ng]", rgx, cmd+1)) return 0; + if (regcomp(&rgxc, rgx, 0)) return 0; + cmd[0] = ':'; + + for (; ln < el; ln++) { + run_vi_cmd("yy"); + if (!regexec(&rgxc, TT.yank.data, 0, 0, 0)) run_ex_cmd(cmd); + run_vi_cmd("j"); + } + + // Reset Frame + ctrl_f(); + draw_page(); + ctrl_b(); } // Line Ranges -- 2.39.2