summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-04-23 18:54:31 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-04-23 18:54:31 +0200
commit6913510e6720e990fc0cb9f582e6ca40cbe97501 (patch)
tree22a8636b86ecd90237e940c00d2f2bc8b5c624b4 /src/normal.cc
parent72ef210e1b15f0fa3a749c52176d86ba583d7b79 (diff)
use alt-J for joining and selecting the spaces replacing line breaks
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc15
1 files changed, 11 insertions, 4 deletions
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<bool matching>
void keep(Context& context)
{
@@ -780,6 +786,7 @@ KeyMap keymap =
{ { Key::Modifiers::None, '[' }, select_object<SurroundFlags::ToBegin> },
{ { Key::Modifiers::Alt, 'j' }, join },
+ { { Key::Modifiers::Alt, 'J' }, join_select_spaces },
{ { Key::Modifiers::Alt, 'k' }, keep<true> },
{ { Key::Modifiers::Alt, 'K' }, keep<false> },