From 81b5de6fd86b4d1db25cf7e25f3e29bdb6ad9689 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 11 Jul 2017 13:49:29 +0900 Subject: [PATCH] Add and for changing/deleting without yanking As asked for in #1175 --- README.asciidoc | 3 +++ doc/manpages/keys.asciidoc | 6 ++++++ src/normal.cc | 22 ++++++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 73b13406..a48ca7fa 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -406,6 +406,9 @@ Changes * `.`: repeat last insert mode change (`i`, `a`, or `c`, including the inserted text) + * ``: delete current selection + * ``: delete current selection and enter insert mode + * `I`: enter insert mode at current selection begin line start * `A`: enter insert mode at current selection end line end * `o`: enter insert mode in one (or given count) new lines below diff --git a/doc/manpages/keys.asciidoc b/doc/manpages/keys.asciidoc index 5adf27b1..2f463ee3 100644 --- a/doc/manpages/keys.asciidoc +++ b/doc/manpages/keys.asciidoc @@ -222,6 +222,12 @@ Changes repeat last insert mode change (*i*, *a*, or *c*, including the inserted text) +**:: + delete current selection (not yanking) + +**:: + delete current selection and enter insert mode (not yanking) + *I*:: enter insert mode at current selection begin line start diff --git a/src/normal.cc b/src/normal.cc index a8919e6e..97243508 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -559,19 +559,27 @@ void yank(Context& context, NormalParams params) get_face("Information") }); } +template void erase_selections(Context& context, NormalParams params) { - const char reg = params.reg ? params.reg : '"'; - RegisterManager::instance()[reg].set(context, context.selections_content()); + if (yank) + { + const char reg = params.reg ? params.reg : '"'; + RegisterManager::instance()[reg].set(context, context.selections_content()); + } ScopedEdition edition(context); context.selections().erase(); context.selections().avoid_eol(); } +template void change(Context& context, NormalParams params) { - const char reg = params.reg ? params.reg : '"'; - RegisterManager::instance()[reg].set(context, context.selections_content()); + if (yank) + { + const char reg = params.reg ? params.reg : '"'; + RegisterManager::instance()[reg].set(context, context.selections_content()); + } enter_insert_mode(context, params); } @@ -1901,8 +1909,10 @@ const HashMap keymap{ { {alt('T')}, {"extend to previous character", select_to_next_char} }, { {alt('F')}, {"extend to previous character included", select_to_next_char} }, - { {'d'}, {"erase selected text", erase_selections} }, - { {'c'}, {"change selected text", change} }, + { {'d'}, {"erase selected text", erase_selections} }, + { {alt('d')}, {"erase selected text, without yanking", erase_selections} }, + { {'c'}, {"change selected text", change} }, + { {alt('c')}, {"change selected text, without yanking", change} }, { {'i'}, {"insert before selected text", enter_insert_mode} }, { {'I'}, {"insert at line begin", enter_insert_mode} }, { {'a'}, {"insert after selected text", enter_insert_mode} },