Add <a-o> and <a-O> to add lines below/above selections

Fixes #1480
This commit is contained in:
Maxime Coste 2017-07-10 18:55:19 +09:00
parent c38dc9a37b
commit b575067317
3 changed files with 22 additions and 0 deletions

View File

@ -413,6 +413,9 @@ Changes
* `O`: enter insert mode in one (or given count) new lines above
current selection begin
* `<a-o>`: add an empty line below cursor
* `<a-O>`: add an empty line above cursor
* `y`: yank selections
* `p`: paste after current selection end
* `P`: paste before current selection begin

View File

@ -236,6 +236,12 @@ Changes
enter insert mode in a new line (or in a given count of new lines) above
current selection begin
*<a-o>*::
add an empty line below cursor
*<a-O>*::
add an empty line above cursor
*y*::
yank selections

View File

@ -1749,6 +1749,16 @@ void exec_user_mappings(Context& context, NormalParams params)
build_autoinfo_for_mapping(context, KeymapMode::User, {}));
}
template<bool above>
void add_empty_line(Context& context, NormalParams params)
{
String new_lines{'\n', CharCount{std::max(params.count, 1)}};
SelectionList sels = context.selections();
for (auto& sel : sels)
sel.set(above ? sel.min().line : sel.max().line+1);
sels.insert(new_lines, InsertMode::InsertCursor);
}
template<typename T>
class Repeated
{
@ -1901,6 +1911,9 @@ const HashMap<Key, NormalCmd> keymap{
{ {'O'}, {"insert on new line above", enter_insert_mode<InsertMode::OpenLineAbove>} },
{ {'r'}, {"replace with character", replace_with_char} },
{ {alt('o')}, {"add a new empty line below", add_empty_line<false>} },
{ {alt('O')}, {"add a new empty line above", add_empty_line<true>} },
{ {'g'}, {"go to location", goto_commands<SelectMode::Replace>} },
{ {'G'}, {"extend to location", goto_commands<SelectMode::Extend>} },