diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-02-19 19:04:09 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-02-19 19:04:09 +0100 |
| commit | 18aac3d4e80743e5410a4c8ae36c32ba2f7514ae (patch) | |
| tree | 96454929e5859c926b3e83ed47a8a954f032c431 /src | |
| parent | a453ddaf374fabf1fa9942a9d0df0d4a999ac79a (diff) | |
Add '*' binding, which (smart) copy current selection to search pattern
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc index 118ab4c7..cf1253c3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -189,6 +189,25 @@ void do_search_next(Context& context) context.print_status("no search pattern"); } +void use_selection_as_search_pattern(Context& context) +{ + std::vector<String> patterns; + auto& sels = context.editor().selections(); + for (auto& sel : sels) + { + 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"; + + patterns.push_back(std::move(content)); + } + RegisterManager::instance()['/'] = patterns; +} + void do_yank(Context& context) { RegisterManager::instance()['"'] = context.editor().selections_content(); @@ -620,6 +639,8 @@ std::unordered_map<Key, std::function<void (Context& context)>> keymap = { { Key::Modifiers::None, 'q' }, start_or_end_macro_recording }, { { Key::Modifiers::None, '@' }, replay_macro }, + + { { Key::Modifiers::None, '*' }, use_selection_as_search_pattern }, }; } |
