Skip to content

Commit

Permalink
vi.c: Added 'v' command and updated help text
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkwebb authored and landley committed Oct 16, 2023
1 parent bea61f7 commit d213cc9
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions toys/pending/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ config VI
ex mode commands:
[cmd]
\b \e \n w wq q! 'set list' 'set nolist' d $ %
\b \e \n w wq q! 'set list' 'set nolist' d $ % g v
*/
#define FOR_vi
#include "toys.h"
Expand Down Expand Up @@ -1368,40 +1368,42 @@ static int run_ex_cmd(char *cmd)
TT.vi_mov_flag |= 0x30000000;
}

else if (*(cmd+1) == 'd') {
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;
} else if (cmd[1] == 'g' || cmd[1] == 'v') {
char *rgx = xmalloc(strlen(cmd));
int el = get_endline(), ln = 0, vorg = ((cmd[1] == 'v') ? REG_NOMATCH : 0);
regex_t rgxc;
if (!sscanf(cmd, ":g/%[^/]/%[^\ng]", rgx, cmd+1)) return 0;
if (regcomp(&rgxc, rgx, 0)) return 0;

if (!sscanf(cmd+2, "/%[^/]/%[^\ng]", rgx, cmd+1) ||
regcomp(&rgxc, rgx, 0)) goto gcleanup;

cmd[0] = ':';

for (; ln < el; ln++) {
run_vi_cmd("yy");
if (!regexec(&rgxc, TT.yank.data, 0, 0, 0)) run_ex_cmd(cmd);
if (regexec(&rgxc, TT.yank.data, 0, 0, 0) == vorg) run_ex_cmd(cmd);
run_vi_cmd("j");
}

// Reset Frame
ctrl_f();
draw_page();
ctrl_b();
}
ctrl_f(); draw_page(); ctrl_b();
gcleanup:
regfree(&rgxc); free(rgx);
}

// Line Ranges
else if (*(cmd+1) >= '0' && *(cmd+1) <= '9') {
else if (cmd[1] >= '0' && cmd[1] <= '9') {
if (strstr(cmd, ",")) {
char *tcmd = xmalloc(strlen(cmd));

sscanf(cmd, ":%d,%d%[^\n]", &startline, &endline, tcmd+2);
cmd = tcmd;
ofst = 1;
} else run_vi_cmd(xmprintf("%dG", atoi(cmd+1)));
} else if (*(cmd+1) == '$') run_vi_cmd("G");
else if (*(cmd+1) == '%') {
} else if (cmd[1] == '$') run_vi_cmd("G");
else if (cmd[1] == '%') {
startline = 1;
endline = get_endline();
ofst = 1;
Expand Down

0 comments on commit d213cc9

Please sign in to comment.