From b57506731761f890e89bfdc5792f3473aecf17c9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 10 Jul 2017 18:55:19 +0900 Subject: [PATCH] Add and to add lines below/above selections Fixes #1480 --- README.asciidoc | 3 +++ doc/manpages/keys.asciidoc | 6 ++++++ src/normal.cc | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index 64786724..200c0de1 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -413,6 +413,9 @@ Changes * `O`: enter insert mode in one (or given count) new lines above current selection begin + * ``: add an empty line below cursor + * ``: add an empty line above cursor + * `y`: yank selections * `p`: paste after current selection end * `P`: paste before current selection begin diff --git a/doc/manpages/keys.asciidoc b/doc/manpages/keys.asciidoc index 60a708c1..5adf27b1 100644 --- a/doc/manpages/keys.asciidoc +++ b/doc/manpages/keys.asciidoc @@ -236,6 +236,12 @@ Changes enter insert mode in a new line (or in a given count of new lines) above current selection begin +**:: + add an empty line below cursor + +**:: + add an empty line above cursor + *y*:: yank selections diff --git a/src/normal.cc b/src/normal.cc index c068831e..a8919e6e 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1749,6 +1749,16 @@ void exec_user_mappings(Context& context, NormalParams params) build_autoinfo_for_mapping(context, KeymapMode::User, {})); } +template +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 class Repeated { @@ -1901,6 +1911,9 @@ const HashMap keymap{ { {'O'}, {"insert on new line above", enter_insert_mode} }, { {'r'}, {"replace with character", replace_with_char} }, + { {alt('o')}, {"add a new empty line below", add_empty_line} }, + { {alt('O')}, {"add a new empty line above", add_empty_line} }, + { {'g'}, {"go to location", goto_commands} }, { {'G'}, {"extend to location", goto_commands} },