use alt-J for joining and selecting the spaces replacing line breaks
This commit is contained in:
parent
72ef210e1b
commit
6913510e67
|
@ -113,6 +113,8 @@ Changes
|
||||||
* _alt-p_: replace current selection with yanked text
|
* _alt-p_: replace current selection with yanked text
|
||||||
|
|
||||||
* _alt-j_: join selected lines
|
* _alt-j_: join selected lines
|
||||||
|
* _alt-J_: join selected lines and select spaces inserted
|
||||||
|
in place of line breaks
|
||||||
|
|
||||||
* _>_: indent selected lines
|
* _>_: indent selected lines
|
||||||
* _<_: deindent selected lines
|
* _<_: deindent selected lines
|
||||||
|
|
|
@ -429,16 +429,14 @@ void split_lines(Context& context)
|
||||||
context.editor().multi_select(std::bind(split_selection, _1, Regex{"^"}));
|
context.editor().multi_select(std::bind(split_selection, _1, Regex{"^"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void join(Context& context)
|
void join_select_spaces(Context& context)
|
||||||
{
|
{
|
||||||
Editor& editor = context.editor();
|
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_whole_lines);
|
||||||
editor.select(select_to_eol, SelectMode::Extend);
|
editor.select(select_to_eol, SelectMode::Extend);
|
||||||
editor.multi_select([](const Selection& sel)
|
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
|
// remove last end of line if selected
|
||||||
kak_assert(std::is_sorted(res.begin(), res.end(),
|
kak_assert(std::is_sorted(res.begin(), res.end(),
|
||||||
[](const Selection& lhs, const Selection& rhs)
|
[](const Selection& lhs, const Selection& rhs)
|
||||||
|
@ -450,6 +448,14 @@ void join(Context& context)
|
||||||
editor.insert(" ", InsertMode::Replace);
|
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>
|
template<bool matching>
|
||||||
void keep(Context& context)
|
void keep(Context& context)
|
||||||
{
|
{
|
||||||
|
@ -780,6 +786,7 @@ KeyMap keymap =
|
||||||
{ { Key::Modifiers::None, '[' }, select_object<SurroundFlags::ToBegin> },
|
{ { Key::Modifiers::None, '[' }, select_object<SurroundFlags::ToBegin> },
|
||||||
|
|
||||||
{ { Key::Modifiers::Alt, 'j' }, join },
|
{ { Key::Modifiers::Alt, 'j' }, join },
|
||||||
|
{ { Key::Modifiers::Alt, 'J' }, join_select_spaces },
|
||||||
|
|
||||||
{ { Key::Modifiers::Alt, 'k' }, keep<true> },
|
{ { Key::Modifiers::Alt, 'k' }, keep<true> },
|
||||||
{ { Key::Modifiers::Alt, 'K' }, keep<false> },
|
{ { Key::Modifiers::Alt, 'K' }, keep<false> },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user