diff --git a/README.asciidoc b/README.asciidoc index 1996bac2..58bb42b9 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -199,6 +199,9 @@ Using the _*_ key, you can set the search pattern to the current selection. This tries to be intelligent. It will for example detect if current selection begins and/or end at word boundaries, and set the search pattern accordingly. +with _alt-*_ you can set the search pattern to the current seletion without +kakoune trying to be smart. + Basic Commands -------------- diff --git a/src/main.cc b/src/main.cc index 7c733f53..cf2b3f9b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -225,6 +225,7 @@ void do_search_next(Context& context) context.print_status("no search pattern"); } +template void use_selection_as_search_pattern(Context& context) { std::vector patterns; @@ -234,11 +235,17 @@ void use_selection_as_search_pattern(Context& context) auto begin = sel.begin(); auto end = sel.end(); auto content = "\\Q" + context.buffer().string(begin, end) + "\\E"; - if (begin.is_begin() or (is_word(utf8::codepoint(begin)) and not is_word(utf8::codepoint(utf8::previous(begin))))) - content = "\\b" + content; - if (end.is_end() or (is_word(utf8::codepoint(utf8::previous(end))) and not is_word(utf8::codepoint(end)))) - content = content + "\\b"; - + if (smart) + { + if (begin.is_begin() or + (is_word(utf8::codepoint(begin)) and not + is_word(utf8::codepoint(utf8::previous(begin))))) + content = "\\b" + content; + if (end.is_end() or + (is_word(utf8::codepoint(utf8::previous(end))) and not + is_word(utf8::codepoint(end)))) + content = content + "\\b"; + } patterns.push_back(std::move(content)); } RegisterManager::instance()['/'] = patterns; @@ -668,7 +675,8 @@ std::unordered_map> keymap = { { Key::Modifiers::None, 'n' }, do_search_next }, { { Key::Modifiers::Alt, 'n' }, do_search_next }, { { Key::Modifiers::None, 'N' }, do_search_next }, - { { Key::Modifiers::None, '*' }, use_selection_as_search_pattern }, + { { Key::Modifiers::None, '*' }, use_selection_as_search_pattern }, + { { Key::Modifiers::Alt, '*' }, use_selection_as_search_pattern }, { { Key::Modifiers::None, 'u' }, repeated([](Context& context) { if (not context.editor().undo()) { context.print_status("nothing left to undo"); } }) }, { { Key::Modifiers::None, 'U' }, repeated([](Context& context) { if (not context.editor().redo()) { context.print_status("nothing left to redo"); } }) },