aboutsummaryrefslogtreecommitdiff
path: root/vis-motions.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-03-31 12:20:17 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-03-31 12:31:23 +0200
commit6f44057d09b865e9c7e443cd7d7adb8e541121db (patch)
tree85306ea233bcf9acb62fbe95f7f050ab59344880 /vis-motions.c
parent9c48a188a51a971d65a6ce764733745fd163f017 (diff)
downloadvis-6f44057d09b865e9c7e443cd7d7adb8e541121db.tar.gz
vis-6f44057d09b865e9c7e443cd7d7adb8e541121db.tar.xz
vis: add non-default actions for vi compatible n/N motions
The following key mappings should result in the vi behavior: :map! normal n <vis-motion-search-repeat> :map! normal N <vis-motion-search-repeat-reverse> The default remains unchanged, that is `n` (`N`) always searches towards the end (start) of the file. Fix #470
Diffstat (limited to 'vis-motions.c')
-rw-r--r--vis-motions.c23
1 files changed, 21 insertions, 2 deletions
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: