Add '*' binding, which (smart) copy current selection to search pattern

This commit is contained in:
Maxime Coste 2013-02-19 19:04:09 +01:00
parent a453ddaf37
commit 18aac3d4e8
2 changed files with 29 additions and 1 deletions

View File

@ -180,6 +180,13 @@ selection.
Registers are lists, instead of simply text in order to interact well with
multiselection. Each selection have it's own captures, or yank buffer.
Search selection
----------------
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.
Basic Commands
--------------
@ -227,7 +234,7 @@ Kakoune support three string syntax:
* +"strings" and \'strings\'+: classic strings, use \' or \" to escape the
separator.
* +%\{strings\}+: these strings are very usefull when entering commands
* +%\{strings\}+: these strings are very useful when entering commands
- the '{' and '}' delimiter are configurable: you can use any non
alphanumeric character. like %[string], %<string>, %(string), %~string~

View File

@ -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 },
};
}