From 63c127788c6f5309debf9d24aafe868e06ee4e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 27 Sep 2014 17:13:18 +0200 Subject: Make '*' more useful --- vis.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/vis.c b/vis.c index 58cf0a3..1890c08 100644 --- a/vis.c +++ b/vis.c @@ -614,20 +614,25 @@ static void op_case_change(OperatorContext *c) { static size_t search_word(const Arg *arg) { size_t pos = window_cursor_get(vis->win->win); - /* TODO: to make this useful the other variant breaking on special symbols - * should be used here */ - Filerange word = text_object_longword_raw(vis->win->text, pos); + Filerange word = text_object_word(vis->win->text, pos); if (!text_range_valid(&word)) return pos; size_t len = word.end - word.start; - char *buf = malloc(len+1); + char *buf = malloc(len+1), *start = buf, *end; if (!buf) return pos; len = text_bytes_get(vis->win->text, word.start, len, buf); buf[len] = '\0'; - /* TODO: using regular expression search here is wrong, but 'n', 'N' should - * reuse this search term */ - if (!text_regex_compile(vis->search_pattern, buf, REG_EXTENDED)) + /* remove leading / trailing white spaces */ + while (*start && isspace(*start)) + start++; + end = start; + for (char *cur = start; *cur; cur++) { + if (!isspace(*cur)) + end = cur; + } + end[1] = '\0'; + if (!text_regex_compile(vis->search_pattern, start, REG_EXTENDED)) pos = text_search_forward(vis->win->text, pos, vis->search_pattern); free(buf); return pos; -- cgit v1.2.3