Skip to content

Commit

Permalink
Implement ';' and ','
Browse files Browse the repository at this point in the history
This fixes martanne#45
  • Loading branch information
martanne committed Apr 21, 2015
1 parent aca46a0 commit d941d9c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ and their current support in vis.
t{char} (till before next occurrence of char to the right)
F{char} (to next occurrence of char to the left)
T{char} (till before next occurrence of char to the left)
; (repeat last to/till movement)
, (repeat last to/till movement but in opposite direction)
/{text} (to next match of text in forward direction)
?{text} (to next match of text in backward direction)

Expand Down
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ static KeyBinding vis_movements[] = {
{ { NONE('F') }, movement_key, { .i = MOVE_LEFT_TO } },
{ { NONE('t') }, movement_key, { .i = MOVE_RIGHT_TILL } },
{ { NONE('T') }, movement_key, { .i = MOVE_LEFT_TILL } },
{ { NONE(';') }, totill_repeat, { NULL } },
{ { NONE(',') }, totill_reverse,{ NULL } },
{ { NONE('/') }, prompt_search,{ .s = "/" } },
{ { NONE('?') }, prompt_search,{ .s = "?" } },
{ /* empty last element, array terminator */ },
Expand Down
1 change: 1 addition & 0 deletions editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct Editor {
char prompt_type; /* command ':' or search '/','?' prompt */
Regex *search_pattern; /* last used search pattern */
char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */
int last_totill; /* last to/till movement used for ';' and ',' */
int tabwidth; /* how many spaces should be used to display a tab */
bool expandtab; /* whether typed tabs should be converted to spaces */
bool autoindent; /* whether indentation should be copied from previous line on newline */
Expand Down
32 changes: 32 additions & 0 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ static void join(const Arg *arg);
static void cmd(const Arg *arg);
/* perform last action i.e. action_prev again */
static void repeat(const Arg *arg);
/* repeat last to/till movement */
static void totill_repeat(const Arg *arg);
/* repeat last to/till movement but in opposite direction */
static void totill_reverse(const Arg *arg);
/* replace character at cursor with one read form keyboard */
static void replace(const Arg *arg);
/* adjust action.count by arg->i */
Expand Down Expand Up @@ -774,6 +778,33 @@ static void repeat(const Arg *arg) {
action_do(&vis->action);
}

static void totill_repeat(const Arg *arg) {
if (!vis->last_totill)
return;
movement(&(const Arg){ .i = vis->last_totill });
}

static void totill_reverse(const Arg *arg) {
int type = vis->last_totill;
switch (type) {
case MOVE_RIGHT_TO:
type = MOVE_LEFT_TO;
break;
case MOVE_LEFT_TO:
type = MOVE_RIGHT_TO;
break;
case MOVE_RIGHT_TILL:
type = MOVE_LEFT_TILL;
break;
case MOVE_LEFT_TILL:
type = MOVE_RIGHT_TILL;
break;
default:
return;
}
movement(&(const Arg){ .i = type });
}

static void replace(const Arg *arg) {
Key k = getkey();
if (!k.str[0])
Expand Down Expand Up @@ -843,6 +874,7 @@ static void movement_key(const Arg *arg) {
return;
}
strncpy(vis->search_char, k.str, sizeof(vis->search_char));
vis->last_totill = arg->i;
vis->action.movement = &moves[arg->i];
action_do(&vis->action);
}
Expand Down

0 comments on commit d941d9c

Please sign in to comment.