Add <a-c> and <a-d> for changing/deleting without yanking

As asked for in #1175
This commit is contained in:
Maxime Coste 2017-07-11 13:49:29 +09:00
parent 42e5d95cd8
commit 81b5de6fd8
3 changed files with 25 additions and 6 deletions

View File

@ -406,6 +406,9 @@ Changes
* `.`: repeat last insert mode change (`i`, `a`, or `c`, including
the inserted text)
* `<a-d>`: delete current selection
* `<a-c>`: 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

View File

@ -222,6 +222,12 @@ Changes
repeat last insert mode change (*i*, *a*, or *c*, including the
inserted text)
*<a-d>*::
delete current selection (not yanking)
*<a-c>*::
delete current selection and enter insert mode (not yanking)
*I*::
enter insert mode at current selection begin line start

View File

@ -559,19 +559,27 @@ void yank(Context& context, NormalParams params)
get_face("Information") });
}
template<bool yank>
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<bool yank>
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<InsertMode::Replace>(context, params);
}
@ -1901,8 +1909,10 @@ const HashMap<Key, NormalCmd> keymap{
{ {alt('T')}, {"extend to previous character", select_to_next_char<SelectFlags::Extend | SelectFlags::Reverse>} },
{ {alt('F')}, {"extend to previous character included", select_to_next_char<SelectFlags::Inclusive | SelectFlags::Extend | SelectFlags::Reverse>} },
{ {'d'}, {"erase selected text", erase_selections} },
{ {'c'}, {"change selected text", change} },
{ {'d'}, {"erase selected text", erase_selections<true>} },
{ {alt('d')}, {"erase selected text, without yanking", erase_selections<false>} },
{ {'c'}, {"change selected text", change<true>} },
{ {alt('c')}, {"change selected text, without yanking", change<false>} },
{ {'i'}, {"insert before selected text", enter_insert_mode<InsertMode::Insert>} },
{ {'I'}, {"insert at line begin", enter_insert_mode<InsertMode::InsertAtLineBegin>} },
{ {'a'}, {"insert after selected text", enter_insert_mode<InsertMode::Append>} },