From f66bbdf209b428aededcb36d2080d4cef86648ab Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 26 Nov 2015 13:36:26 +0000 Subject: select/split interpret count parameter as the capture group to use count being 0 by default, we use the whole match, but we can now specify to use capture 1 with 1s. --- src/normal.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 009a2224..54b062c1 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -704,26 +704,28 @@ void use_selection_as_search_pattern(Context& context, NormalParams params) void select_regex(Context& context, NormalParams params) { const char reg = to_lower(params.reg ? params.reg : '/'); - regex_prompt(context, "select:", [reg](Regex ex, PromptEvent event, Context& context) { + unsigned capture = (unsigned)params.count; + regex_prompt(context, "select:", [reg, capture](Regex ex, PromptEvent event, Context& context) { if (ex.empty()) ex = Regex{context.main_sel_register_value(reg)}; else if (event == PromptEvent::Validate) RegisterManager::instance()[reg] = ex.str(); if (not ex.empty() and not ex.str().empty()) - select_all_matches(context.selections(), ex); + select_all_matches(context.selections(), ex, capture); }); } void split_regex(Context& context, NormalParams params) { const char reg = to_lower(params.reg ? params.reg : '/'); - regex_prompt(context, "split:", [reg](Regex ex, PromptEvent event, Context& context) { + unsigned capture = (unsigned)params.count; + regex_prompt(context, "split:", [reg, capture](Regex ex, PromptEvent event, Context& context) { if (ex.empty()) ex = Regex{context.main_sel_register_value(reg)}; else if (event == PromptEvent::Validate) RegisterManager::instance()[reg] = ex.str(); if (not ex.empty() and not ex.str().empty()) - split_selections(context.selections(), ex); + split_selections(context.selections(), ex, capture); }); } -- cgit v1.2.3