aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c12
-rw-r--r--vis-core.h1
-rw-r--r--vis-motions.c23
-rw-r--r--vis.h2
4 files changed, 36 insertions, 2 deletions
diff --git a/main.c b/main.c
index be2a2f1..4bdb05c 100644
--- a/main.c
+++ b/main.c
@@ -173,6 +173,8 @@ enum {
VIS_ACTION_CURSOR_WINDOW_LINE_BOTTOM,
VIS_ACTION_CURSOR_SEARCH_REPEAT_FORWARD,
VIS_ACTION_CURSOR_SEARCH_REPEAT_BACKWARD,
+ VIS_ACTION_CURSOR_SEARCH_REPEAT,
+ VIS_ACTION_CURSOR_SEARCH_REPEAT_REVERSE,
VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD,
VIS_ACTION_CURSOR_SEARCH_WORD_BACKWARD,
VIS_ACTION_WINDOW_PAGE_UP,
@@ -525,6 +527,16 @@ static const KeyAction vis_action[] = {
VIS_HELP("Move cursor to previous match in backward direction")
movement, { .i = VIS_MOVE_SEARCH_REPEAT_BACKWARD }
},
+ [VIS_ACTION_CURSOR_SEARCH_REPEAT] = {
+ "vis-motion-search-repeat",
+ VIS_HELP("Move cursor to next match")
+ movement, { .i = VIS_MOVE_SEARCH_REPEAT }
+ },
+ [VIS_ACTION_CURSOR_SEARCH_REPEAT_REVERSE] = {
+ "vis-motion-search-repeat-reverse",
+ VIS_HELP("Move cursor to next match in opposite direction")
+ movement, { .i = VIS_MOVE_SEARCH_REPEAT_REVERSE }
+ },
[VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD] = {
"vis-motion-search-word-forward",
VIS_HELP("Move cursor to next occurence of the word under cursor")
diff --git a/vis-core.h b/vis-core.h
index 9cc26f3..e50a788 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -169,6 +169,7 @@ struct Vis {
Mode *mode_before_prompt; /* user mode which was active before entering prompt */
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 search_direction; /* used for `n` and `N` */
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 */
diff --git a/vis-motions.c b/vis-motions.c
index 7007f47..1ceb958 100644
--- a/vis-motions.c
+++ b/vis-motions.c
@@ -26,16 +26,20 @@ static Regex *search_word(Vis *vis, Text *txt, size_t pos) {
static size_t search_word_forward(Vis *vis, Text *txt, size_t pos) {
Regex *regex = search_word(vis, txt, pos);
- if (regex)
+ if (regex) {
+ vis->search_direction = VIS_MOVE_SEARCH_REPEAT_FORWARD;
pos = text_search_forward(txt, pos, regex);
+ }
text_regex_free(regex);
return pos;
}
static size_t search_word_backward(Vis *vis, Text *txt, size_t pos) {
Regex *regex = search_word(vis, txt, pos);
- if (regex)
+ if (regex) {
+ vis->search_direction = VIS_MOVE_SEARCH_REPEAT_BACKWARD;
pos = text_search_backward(txt, pos, regex);
+ }
text_regex_free(regex);
return pos;
}
@@ -331,6 +335,21 @@ bool vis_motion(Vis *vis, enum VisMotion motion, ...) {
motion = VIS_MOVE_SEARCH_REPEAT_FORWARD;
else
motion = VIS_MOVE_SEARCH_REPEAT_BACKWARD;
+ vis->search_direction = motion;
+ break;
+ }
+ case VIS_MOVE_SEARCH_REPEAT:
+ case VIS_MOVE_SEARCH_REPEAT_REVERSE:
+ {
+ if (!vis->search_direction)
+ vis->search_direction = VIS_MOVE_SEARCH_REPEAT_FORWARD;
+ if (motion == VIS_MOVE_SEARCH_REPEAT) {
+ motion = vis->search_direction;
+ } else {
+ motion = vis->search_direction == VIS_MOVE_SEARCH_REPEAT_FORWARD ?
+ VIS_MOVE_SEARCH_REPEAT_BACKWARD :
+ VIS_MOVE_SEARCH_REPEAT_FORWARD;
+ }
break;
}
case VIS_MOVE_RIGHT_TO:
diff --git a/vis.h b/vis.h
index d7cb0c0..8f74a36 100644
--- a/vis.h
+++ b/vis.h
@@ -322,6 +322,8 @@ enum VisMotion {
VIS_MOVE_TOTILL_REVERSE,
VIS_MOVE_SEARCH_FORWARD,
VIS_MOVE_SEARCH_BACKWARD,
+ VIS_MOVE_SEARCH_REPEAT,
+ VIS_MOVE_SEARCH_REPEAT_REVERSE,
VIS_MOVE_LAST, /* denotes the end of all motions */
};