vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 173e8d60998923f31c80b6655bd066de0a23e828
parent f7c7463352764f20bccfe4eb8cfa856ace0e9f34
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 19 Jan 2017 15:34:45 +0100

vis: make <C-n> in visual mode wrap around

Strictly speaking we actually not wrap around, but search
backwards starting from the first cursor. This is seems
more useful when for example renaming a local variable
but not starting from its declaration.

Close #305

Diffstat:
Mmain.c | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -1442,15 +1442,22 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar if (!buf) return keys; Filerange word = text_object_word_find_next(txt, sel.end, buf); - free(buf); - if (text_range_valid(&word)) { size_t pos = text_char_prev(txt, word.end); - cursor = view_cursors_new(view, pos); - if (!cursor) - return keys; - view_cursors_selection_set(cursor, &word); + if ((cursor = view_cursors_new(view, pos))) { + view_cursors_selection_set(cursor, &word); + goto out; + } } + + sel = view_cursors_selection_get(view_cursors(view)); + word = text_object_word_find_prev(txt, sel.start, buf); + size_t pos = text_char_prev(txt, word.end); + if ((cursor = view_cursors_new(view, pos))) + view_cursors_selection_set(cursor, &word); + +out: + free(buf); return keys; }