summaryrefslogtreecommitdiff
path: root/lib/readline/vi_mode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/readline/vi_mode.c')
-rw-r--r--lib/readline/vi_mode.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c
index a5ec2f8b..742341e3 100644
--- a/lib/readline/vi_mode.c
+++ b/lib/readline/vi_mode.c
@@ -875,8 +875,8 @@ _rl_vi_done_inserting (void)
{
if (_rl_vi_doing_insert)
{
- /* The `C', `s', and `S' commands set this. */
- rl_end_undo_group ();
+ /* The `c', `s', `S', and `R' commands set this. */
+ rl_end_undo_group (); /* for the group in rl_vi_start_inserting */
/* Now, the text between rl_undo_list->next->start and
rl_undo_list->next->end is what was inserted while in insert
mode. It gets copied to VI_INSERT_BUFFER because it depends
@@ -887,7 +887,9 @@ _rl_vi_done_inserting (void)
_rl_vi_save_replace (); /* Half the battle */
else
_rl_vi_save_insert (rl_undo_list->next);
- vi_continued_command = 1;
+ /* sanity check, should always be >= 1 here */
+ if (_rl_undo_group_level > 0)
+ rl_end_undo_group (); /* for the group in the command (change or replace) */
}
else
{
@@ -899,10 +901,12 @@ _rl_vi_done_inserting (void)
/* XXX - Other keys probably need to be checked. */
else if (_rl_vi_last_key_before_insert == 'C')
rl_end_undo_group ();
- while (_rl_undo_group_level > 0)
- rl_end_undo_group ();
- vi_continued_command = 0;
}
+
+ /* Sanity check, make sure all the undo groups are closed before we leave
+ insert mode */
+ while (_rl_undo_group_level > 0)
+ rl_end_undo_group ();
}
int
@@ -1210,6 +1214,10 @@ _rl_vi_domove_motion_cleanup (int c, _rl_vimotion_cxt *m)
/* No change in position means the command failed. */
if (rl_mark == rl_point)
{
+ /* 'c' and 'C' enter insert mode after the delete even if the motion
+ didn't delete anything, as long as the motion command is valid. */
+ if (_rl_to_upper (m->key) == 'C' && _rl_vi_motion_command (c))
+ return (vidomove_dispatch (m));
RL_UNSETSTATE (RL_STATE_VIMOTION);
return (-1);
}
@@ -1382,7 +1390,11 @@ rl_vi_delete_to (int count, int key)
{
int c, r;
- _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key);
+ if (_rl_vimvcxt)
+ _rl_mvcxt_init (_rl_vimvcxt, VIM_DELETE, key);
+ else
+ _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key);
+
_rl_vimvcxt->start = rl_point;
rl_mark = rl_point;
@@ -1470,7 +1482,10 @@ rl_vi_change_to (int count, int key)
{
int c, r;
- _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key);
+ if (_rl_vimvcxt)
+ _rl_mvcxt_init (_rl_vimvcxt, VIM_CHANGE, key);
+ else
+ _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key);
_rl_vimvcxt->start = rl_point;
rl_mark = rl_point;
@@ -1539,7 +1554,10 @@ rl_vi_yank_to (int count, int key)
{
int c, r;
- _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key);
+ if (_rl_vimvcxt)
+ _rl_mvcxt_init (_rl_vimvcxt, VIM_YANK, key);
+ else
+ _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key);
_rl_vimvcxt->start = rl_point;
rl_mark = rl_point;
@@ -2247,7 +2265,7 @@ rl_vi_replace (int count, int key)
rl_vi_start_inserting (key, 1, rl_arg_sign);
- _rl_vi_last_key_before_insert = key;
+ _rl_vi_last_key_before_insert = 'R'; /* in case someone rebinds it */
_rl_keymap = vi_replace_map;
if (_rl_enable_bracketed_paste)