From 6913510e6720e990fc0cb9f582e6ca40cbe97501 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 23 Apr 2013 18:54:31 +0200 Subject: [PATCH] use alt-J for joining and selecting the spaces replacing line breaks --- README.asciidoc | 2 ++ src/normal.cc | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 3dc5b676..76930485 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -113,6 +113,8 @@ Changes * _alt-p_: replace current selection with yanked text * _alt-j_: join selected lines + * _alt-J_: join selected lines and select spaces inserted + in place of line breaks * _>_: indent selected lines * _<_: deindent selected lines diff --git a/src/normal.cc b/src/normal.cc index 7f178bbb..2ff41a54 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -429,16 +429,14 @@ void split_lines(Context& context) context.editor().multi_select(std::bind(split_selection, _1, Regex{"^"})); } -void join(Context& context) +void join_select_spaces(Context& context) { Editor& editor = context.editor(); - DynamicSelectionList sels{editor.buffer(), editor.selections()}; - auto restore_sels = on_scope_end([&]{ editor.select((SelectionList)std::move(sels)); }); editor.select(select_whole_lines); editor.select(select_to_eol, SelectMode::Extend); editor.multi_select([](const Selection& sel) { - SelectionList res = select_all_matches(sel, Regex{"\n\\h*"}); + SelectionList res = select_all_matches(sel, Regex{"(\n\\h*)+"}); // remove last end of line if selected kak_assert(std::is_sorted(res.begin(), res.end(), [](const Selection& lhs, const Selection& rhs) @@ -450,6 +448,14 @@ void join(Context& context) editor.insert(" ", InsertMode::Replace); } +void join(Context& context) +{ + Editor& editor = context.editor(); + DynamicSelectionList sels{editor.buffer(), editor.selections()}; + auto restore_sels = on_scope_end([&]{ editor.select((SelectionList)std::move(sels)); }); + join_select_spaces(context); +} + template void keep(Context& context) { @@ -780,6 +786,7 @@ KeyMap keymap = { { Key::Modifiers::None, '[' }, select_object }, { { Key::Modifiers::Alt, 'j' }, join }, + { { Key::Modifiers::Alt, 'J' }, join_select_spaces }, { { Key::Modifiers::Alt, 'k' }, keep }, { { Key::Modifiers::Alt, 'K' }, keep },