From c1e4b4ff7977e00443ad6a728787ab3c9b0a7342 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 3 Jun 2017 18:16:40 +0100 Subject: [PATCH] Strip surrounding whitespaces in `*` Fixes #1406 --- src/normal.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/normal.cc b/src/normal.cc index 5f9d778c..c4b13046 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -788,7 +788,15 @@ void use_selection_as_search_pattern(Context& context, NormalParams params) const auto& buffer = context.buffer(); for (auto& sel : sels) { - const auto beg = sel.min(), end = buffer.char_next(sel.max()); + auto beg = sel.min(), end = sel.max(); + if (smart) // skip whitespaces + { + while (is_blank(buffer.byte_at(beg)) and beg != end) + beg = buffer.char_next(beg); + while (is_blank(buffer.byte_at(end)) and beg != end) + end = buffer.char_prev(end); + } + end = buffer.char_next(end); patterns.push_back(format("{}\\Q{}\\E{}", smart and is_bow(buffer, beg) ? "\\b" : "", buffer.string(beg, end),