1 /* vi_mode.c -- A vi emulation mode for Bash.
2 Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */
4 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.
14 The GNU Readline Library is distributed in the hope that it will be
15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 The GNU General Public License is often shipped with GNU software, and
20 is generally kept in a file called COPYING or LICENSE. If you do not
21 have a copy of the license, write to the Free Software Foundation,
22 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
23 #define READLINE_LIBRARY
25 /* **************************************************************** */
27 /* VI Emulation Mode */
29 /* **************************************************************** */
34 #if defined (HAVE_CONFIG_H)
38 #include <sys/types.h>
40 #if defined (HAVE_STDLIB_H)
43 # include "ansi_stdlib.h"
44 #endif /* HAVE_STDLIB_H */
46 #if defined (HAVE_UNISTD_H)
52 /* Some standard library routines. */
57 #include "rlprivate.h"
61 #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
64 #ifndef _rl_digit_value
65 #define _rl_digit_value(c) ((c) - '0')
69 #define member(c, s) ((c) ? (char *)strchr ((s), (c)) != (char *)NULL : 0)
73 #define isident(c) ((_rl_pure_alphabetic (c) || _rl_digit_p (c) || c == '_'))
77 #define exchange(x, y) do {int temp = x; x = y; y = temp;} while (0)
80 /* Non-zero means enter insertion mode. */
81 static int _rl_vi_doing_insert
;
83 /* Command keys which do movement for xxx_to commands. */
84 static char *vi_motion
= " hl^$0ftFt;,%wbeWBE|";
86 /* Keymap used for vi replace characters. Created dynamically since
88 static Keymap vi_replace_map
;
90 /* The number of characters inserted in the last replace operation. */
91 static int vi_replace_count
;
93 /* If non-zero, we have text inserted after a c[motion] command that put
94 us implicitly into insert mode. Some people want this text to be
95 attached to the command so that it is `redoable' with `.'. */
96 static int vi_continued_command
;
97 static char *vi_insert_buffer
;
98 static int vi_insert_buffer_size
;
100 static int _rl_vi_last_command
= 'i'; /* default `.' puts you in insert mode */
101 static int _rl_vi_last_repeat
= 1;
102 static int _rl_vi_last_arg_sign
= 1;
103 static int _rl_vi_last_motion
;
104 static int _rl_vi_last_search_char
;
105 static int _rl_vi_last_replacement
;
107 static int _rl_vi_last_key_before_insert
;
109 static int vi_redoing
;
111 /* Text modification commands. These are the `redoable' commands. */
112 static char *vi_textmod
= "_*\\AaIiCcDdPpYyRrSsXx~";
114 /* Arrays for the saved marks. */
115 static int vi_mark_chars
[27];
117 static int rl_digit_loop1
__P((void));
120 _rl_vi_initialize_line ()
124 for (i
= 0; i
< sizeof (vi_mark_chars
) / sizeof (int); i
++)
125 vi_mark_chars
[i
] = -1;
131 _rl_vi_last_command
= 'i';
132 _rl_vi_last_repeat
= 1;
133 _rl_vi_last_arg_sign
= 1;
134 _rl_vi_last_motion
= 0;
138 _rl_vi_set_last (key
, repeat
, sign
)
139 int key
, repeat
, sign
;
141 _rl_vi_last_command
= key
;
142 _rl_vi_last_repeat
= repeat
;
143 _rl_vi_last_arg_sign
= sign
;
146 /* Is the command C a VI mode text modification command? */
148 _rl_vi_textmod_command (c
)
151 return (member (c
, vi_textmod
));
155 _rl_vi_stuff_insert (count
)
158 rl_begin_undo_group ();
160 rl_insert_text (vi_insert_buffer
);
161 rl_end_undo_group ();
164 /* Bound to `.'. Called from command mode, so we know that we have to
165 redo a text modification command. The default for _rl_vi_last_command
166 puts you back into insert mode. */
168 rl_vi_redo (count
, c
)
171 if (!rl_explicit_arg
)
173 rl_numeric_arg
= _rl_vi_last_repeat
;
174 rl_arg_sign
= _rl_vi_last_arg_sign
;
178 /* If we're redoing an insert with `i', stuff in the inserted text
179 and do not go into insertion mode. */
180 if (_rl_vi_last_command
== 'i' && vi_insert_buffer
&& *vi_insert_buffer
)
182 _rl_vi_stuff_insert (count
);
183 /* And back up point over the last character inserted. */
188 _rl_dispatch (_rl_vi_last_command
, _rl_keymap
);
194 /* A placeholder for further expansion. */
196 rl_vi_undo (count
, key
)
199 return (rl_undo_command (count
, key
));
202 /* Yank the nth arg from the previous line into this line at point. */
204 rl_vi_yank_arg (count
, key
)
207 /* Readline thinks that the first word on a line is the 0th, while vi
208 thinks the first word on a line is the 1st. Compensate. */
210 rl_yank_nth_arg (count
- 1, 0);
212 rl_yank_nth_arg ('$', 0);
217 /* With an argument, move back that many history lines, else move to the
218 beginning of history. */
220 rl_vi_fetch_history (count
, c
)
225 /* Giving an argument of n means we want the nth command in the history
226 file. The command number is interpreted the same way that the bash
227 `history' command does it -- that is, giving an argument count of 450
228 to this command would get the command listed as number 450 in the
229 output of `history'. */
232 wanted
= history_base
+ where_history () - count
;
234 rl_beginning_of_history (0, 0);
236 rl_get_previous_history (wanted
, c
);
239 rl_beginning_of_history (count
, 0);
243 /* Search again for the last thing searched for. */
245 rl_vi_search_again (count
, key
)
251 rl_noninc_reverse_search_again (count
, key
);
255 rl_noninc_forward_search_again (count
, key
);
261 /* Do a vi style search. */
263 rl_vi_search (count
, key
)
269 rl_noninc_forward_search (count
, key
);
273 rl_noninc_reverse_search (count
, key
);
283 /* Completion, from vi's point of view. */
285 rl_vi_complete (ignore
, key
)
288 if ((rl_point
< rl_end
) && (!whitespace (rl_line_buffer
[rl_point
])))
290 if (!whitespace (rl_line_buffer
[rl_point
+ 1]))
291 rl_vi_end_word (1, 'E');
296 rl_complete_internal ('*'); /* Expansion and replacement. */
298 rl_complete_internal ('?'); /* List possible completions. */
299 else if (key
== '\\')
300 rl_complete_internal (TAB
); /* Standard Readline completion. */
302 rl_complete (0, key
);
304 if (key
== '*' || key
== '\\')
306 _rl_vi_set_last (key
, 1, rl_arg_sign
);
307 rl_vi_insertion_mode (1, key
);
312 /* Tilde expansion for vi mode. */
314 rl_vi_tilde_expand (ignore
, key
)
317 rl_tilde_expand (0, key
);
318 _rl_vi_set_last (key
, 1, rl_arg_sign
); /* XXX */
319 rl_vi_insertion_mode (1, key
);
323 /* Previous word in vi mode. */
325 rl_vi_prev_word (count
, key
)
329 return (rl_vi_next_word (-count
, key
));
337 if (_rl_uppercase_p (key
))
338 rl_vi_bWord (count
, key
);
340 rl_vi_bword (count
, key
);
345 /* Next word in vi mode. */
347 rl_vi_next_word (count
, key
)
351 return (rl_vi_prev_word (-count
, key
));
353 if (rl_point
>= (rl_end
- 1))
359 if (_rl_uppercase_p (key
))
360 rl_vi_fWord (count
, key
);
362 rl_vi_fword (count
, key
);
366 /* Move to the end of the ?next? word. */
368 rl_vi_end_word (count
, key
)
377 if (_rl_uppercase_p (key
))
378 rl_vi_eWord (count
, key
);
380 rl_vi_eword (count
, key
);
384 /* Move forward a word the way that 'W' does. */
386 rl_vi_fWord (count
, ignore
)
389 while (count
-- && rl_point
< (rl_end
- 1))
391 /* Skip until whitespace. */
392 while (!whitespace (rl_line_buffer
[rl_point
]) && rl_point
< rl_end
)
395 /* Now skip whitespace. */
396 while (whitespace (rl_line_buffer
[rl_point
]) && rl_point
< rl_end
)
403 rl_vi_bWord (count
, ignore
)
406 while (count
-- && rl_point
> 0)
408 /* If we are at the start of a word, move back to whitespace so
409 we will go back to the start of the previous word. */
410 if (!whitespace (rl_line_buffer
[rl_point
]) &&
411 whitespace (rl_line_buffer
[rl_point
- 1]))
414 while (rl_point
> 0 && whitespace (rl_line_buffer
[rl_point
]))
419 while (--rl_point
>= 0 && !whitespace (rl_line_buffer
[rl_point
]));
427 rl_vi_eWord (count
, ignore
)
430 while (count
-- && rl_point
< (rl_end
- 1))
432 if (!whitespace (rl_line_buffer
[rl_point
]))
435 /* Move to the next non-whitespace character (to the start of the
437 while (++rl_point
< rl_end
&& whitespace (rl_line_buffer
[rl_point
]));
439 if (rl_point
&& rl_point
< rl_end
)
441 /* Skip whitespace. */
442 while (rl_point
< rl_end
&& whitespace (rl_line_buffer
[rl_point
]))
445 /* Skip until whitespace. */
446 while (rl_point
< rl_end
&& !whitespace (rl_line_buffer
[rl_point
]))
449 /* Move back to the last character of the word. */
457 rl_vi_fword (count
, ignore
)
460 while (count
-- && rl_point
< (rl_end
- 1))
462 /* Move to white space (really non-identifer). */
463 if (isident (rl_line_buffer
[rl_point
]))
465 while (isident (rl_line_buffer
[rl_point
]) && rl_point
< rl_end
)
468 else /* if (!whitespace (rl_line_buffer[rl_point])) */
470 while (!isident (rl_line_buffer
[rl_point
]) &&
471 !whitespace (rl_line_buffer
[rl_point
]) && rl_point
< rl_end
)
475 /* Move past whitespace. */
476 while (whitespace (rl_line_buffer
[rl_point
]) && rl_point
< rl_end
)
483 rl_vi_bword (count
, ignore
)
486 while (count
-- && rl_point
> 0)
490 /* If we are at the start of a word, move back to whitespace
491 so we will go back to the start of the previous word. */
492 if (!whitespace (rl_line_buffer
[rl_point
]) &&
493 whitespace (rl_line_buffer
[rl_point
- 1]))
496 /* If this character and the previous character are `opposite', move
497 back so we don't get messed up by the rl_point++ down there in
498 the while loop. Without this code, words like `l;' screw up the
500 last_is_ident
= isident (rl_line_buffer
[rl_point
- 1]);
501 if ((isident (rl_line_buffer
[rl_point
]) && !last_is_ident
) ||
502 (!isident (rl_line_buffer
[rl_point
]) && last_is_ident
))
505 while (rl_point
> 0 && whitespace (rl_line_buffer
[rl_point
]))
510 if (isident (rl_line_buffer
[rl_point
]))
511 while (--rl_point
>= 0 && isident (rl_line_buffer
[rl_point
]));
513 while (--rl_point
>= 0 && !isident (rl_line_buffer
[rl_point
]) &&
514 !whitespace (rl_line_buffer
[rl_point
]));
522 rl_vi_eword (count
, ignore
)
525 while (count
-- && rl_point
< rl_end
- 1)
527 if (!whitespace (rl_line_buffer
[rl_point
]))
530 while (rl_point
< rl_end
&& whitespace (rl_line_buffer
[rl_point
]))
533 if (rl_point
< rl_end
)
535 if (isident (rl_line_buffer
[rl_point
]))
536 while (++rl_point
< rl_end
&& isident (rl_line_buffer
[rl_point
]));
538 while (++rl_point
< rl_end
&& !isident (rl_line_buffer
[rl_point
])
539 && !whitespace (rl_line_buffer
[rl_point
]));
547 rl_vi_insert_beg (count
, key
)
550 rl_beg_of_line (1, key
);
551 rl_vi_insertion_mode (1, key
);
556 rl_vi_append_mode (count
, key
)
559 if (rl_point
< rl_end
)
561 rl_vi_insertion_mode (1, key
);
566 rl_vi_append_eol (count
, key
)
569 rl_end_of_line (1, key
);
570 rl_vi_append_mode (1, key
);
574 /* What to do in the case of C-d. */
576 rl_vi_eof_maybe (count
, c
)
579 return (rl_newline (1, '\n'));
582 /* Insertion mode stuff. */
584 /* Switching from one mode to the other really just involves
585 switching keymaps. */
587 rl_vi_insertion_mode (count
, key
)
590 _rl_keymap
= vi_insertion_keymap
;
591 _rl_vi_last_key_before_insert
= key
;
596 _rl_vi_save_insert (up
)
603 if (vi_insert_buffer_size
>= 1)
604 vi_insert_buffer
[0] = '\0';
610 len
= end
- start
+ 1;
611 if (len
>= vi_insert_buffer_size
)
613 vi_insert_buffer_size
+= (len
+ 32) - (len
% 32);
614 vi_insert_buffer
= xrealloc (vi_insert_buffer
, vi_insert_buffer_size
);
616 strncpy (vi_insert_buffer
, rl_line_buffer
+ start
, len
- 1);
617 vi_insert_buffer
[len
-1] = '\0';
621 _rl_vi_done_inserting ()
623 if (_rl_vi_doing_insert
)
625 rl_end_undo_group ();
626 /* Now, the text between rl_undo_list->next->start and
627 rl_undo_list->next->end is what was inserted while in insert
628 mode. It gets copied to VI_INSERT_BUFFER because it depends
629 on absolute indices into the line which may change (though they
630 probably will not). */
631 _rl_vi_doing_insert
= 0;
632 _rl_vi_save_insert (rl_undo_list
->next
);
633 vi_continued_command
= 1;
637 if (_rl_vi_last_key_before_insert
== 'i' && rl_undo_list
)
638 _rl_vi_save_insert (rl_undo_list
);
639 /* XXX - Other keys probably need to be checked. */
640 else if (_rl_vi_last_key_before_insert
== 'C')
641 rl_end_undo_group ();
642 while (_rl_undo_group_level
> 0)
643 rl_end_undo_group ();
644 vi_continued_command
= 0;
649 rl_vi_movement_mode (count
, key
)
653 rl_backward (1, key
);
655 _rl_keymap
= vi_movement_keymap
;
656 _rl_vi_done_inserting ();
661 rl_vi_arg_digit (count
, c
)
664 if (c
== '0' && rl_numeric_arg
== 1 && !rl_explicit_arg
)
665 return (rl_beg_of_line (1, c
));
667 return (rl_digit_argument (count
, c
));
671 rl_vi_change_case (count
, ignore
)
676 /* Don't try this on an empty line. */
677 if (rl_point
>= rl_end
)
680 while (count
-- && rl_point
< rl_end
)
682 if (_rl_uppercase_p (rl_line_buffer
[rl_point
]))
683 c
= _rl_to_lower (rl_line_buffer
[rl_point
]);
684 else if (_rl_lowercase_p (rl_line_buffer
[rl_point
]))
685 c
= _rl_to_upper (rl_line_buffer
[rl_point
]);
688 /* Just skip over characters neither upper nor lower case. */
693 /* Vi is kind of strange here. */
696 rl_begin_undo_group ();
699 rl_end_undo_group ();
709 rl_vi_put (count
, key
)
712 if (!_rl_uppercase_p (key
) && (rl_point
+ 1 <= rl_end
))
716 rl_backward (1, key
);
723 if (rl_point
&& rl_point
== rl_end
)
729 rl_vi_column (count
, key
)
733 rl_end_of_line (1, key
);
735 rl_point
= count
- 1;
740 rl_vi_domove (key
, nextkey
)
750 if (!member (c
, vi_motion
))
754 save
= rl_numeric_arg
;
755 rl_numeric_arg
= _rl_digit_value (c
);
757 rl_numeric_arg
*= save
;
758 c
= rl_read_key (); /* real command */
761 else if (key
== c
&& (key
== 'd' || key
== 'y' || key
== 'c'))
764 rl_beg_of_line (1, c
);
765 _rl_vi_last_motion
= c
;
772 _rl_vi_last_motion
= c
;
774 /* Append a blank character temporarily so that the motion routines
775 work right at the end of the line. */
777 rl_line_buffer
[rl_end
++] = ' ';
778 rl_line_buffer
[rl_end
] = '\0';
780 _rl_dispatch (c
, _rl_keymap
);
782 /* Remove the blank that we added. */
784 rl_line_buffer
[rl_end
] = '\0';
785 if (rl_point
> rl_end
)
788 /* No change in position means the command failed. */
789 if (rl_mark
== rl_point
)
792 /* rl_vi_f[wW]ord () leaves the cursor on the first character of the next
793 word. If we are not at the end of the line, and we are on a
794 non-whitespace character, move back one (presumably to whitespace). */
795 if ((_rl_to_upper (c
) == 'W') && rl_point
< rl_end
&& rl_point
> rl_mark
&&
796 !whitespace (rl_line_buffer
[rl_point
]))
799 /* If cw or cW, back up to the end of a word, so the behaviour of ce
800 or cE is the actual result. Brute-force, no subtlety. */
801 if (key
== 'c' && rl_point
>= rl_mark
&& (_rl_to_upper (c
) == 'W'))
803 /* Don't move farther back than where we started. */
804 while (rl_point
> rl_mark
&& whitespace (rl_line_buffer
[rl_point
]))
807 /* Posix.2 says that if cw or cW moves the cursor towards the end of
808 the line, the character under the cursor should be deleted. */
809 if (rl_point
== rl_mark
)
813 /* Move past the end of the word so that the kill doesn't
814 remove the last letter of the previous word. Only do this
815 if we are not at the end of the line. */
816 if (rl_point
>= 0 && rl_point
< (rl_end
- 1) && !whitespace (rl_line_buffer
[rl_point
]))
821 if (rl_mark
< rl_point
)
822 exchange (rl_point
, rl_mark
);
827 /* A simplified loop for vi. Don't dispatch key at end.
828 Don't recognize minus sign? */
836 rl_message ("(arg: %d) ", rl_arg_sign
* rl_numeric_arg
, 0);
837 key
= c
= rl_read_key ();
839 if (_rl_keymap
[c
].type
== ISFUNC
&&
840 _rl_keymap
[c
].function
== rl_universal_argument
)
850 rl_numeric_arg
= (rl_numeric_arg
* 10) + _rl_digit_value (c
);
852 rl_numeric_arg
= _rl_digit_value (c
);
866 rl_vi_delete_to (count
, key
)
871 if (_rl_uppercase_p (key
))
874 rl_stuff_char (_rl_vi_last_motion
);
876 if (rl_vi_domove (key
, &c
))
882 /* These are the motion commands that do not require adjusting the
884 if ((strchr (" l|h^0bB", c
) == 0) && (rl_mark
< rl_end
))
887 rl_kill_text (rl_point
, rl_mark
);
892 rl_vi_change_to (count
, key
)
897 if (_rl_uppercase_p (key
))
900 rl_stuff_char (_rl_vi_last_motion
);
902 start_pos
= rl_point
;
904 if (rl_vi_domove (key
, &c
))
910 /* These are the motion commands that do not require adjusting the
911 mark. c[wW] are handled by special-case code in rl_vi_domove(),
912 and already leave the mark at the correct location. */
913 if ((strchr (" l|hwW^0bB", c
) == 0) && (rl_mark
< rl_end
))
916 /* The cursor never moves with c[wW]. */
917 if ((_rl_to_upper (c
) == 'W') && rl_point
< start_pos
)
918 rl_point
= start_pos
;
922 if (vi_insert_buffer
&& *vi_insert_buffer
)
923 rl_begin_undo_group ();
924 rl_delete_text (rl_point
, rl_mark
);
925 if (vi_insert_buffer
&& *vi_insert_buffer
)
927 rl_insert_text (vi_insert_buffer
);
928 rl_end_undo_group ();
933 rl_begin_undo_group (); /* to make the `u' command work */
934 rl_kill_text (rl_point
, rl_mark
);
935 /* `C' does not save the text inserted for undoing or redoing. */
936 if (_rl_uppercase_p (key
) == 0)
937 _rl_vi_doing_insert
= 1;
938 _rl_vi_set_last (key
, count
, rl_arg_sign
);
939 rl_vi_insertion_mode (1, key
);
946 rl_vi_yank_to (count
, key
)
949 int c
, save
= rl_point
;
951 if (_rl_uppercase_p (key
))
954 if (rl_vi_domove (key
, &c
))
960 /* These are the motion commands that do not require adjusting the
962 if ((strchr (" l|h^0%bB", c
) == 0) && (rl_mark
< rl_end
))
965 rl_begin_undo_group ();
966 rl_kill_text (rl_point
, rl_mark
);
967 rl_end_undo_group ();
975 rl_vi_delete (count
, key
)
986 end
= rl_point
+ count
;
991 rl_kill_text (rl_point
, end
);
993 if (rl_point
> 0 && rl_point
== rl_end
)
994 rl_backward (1, key
);
999 rl_vi_back_to_indent (count
, key
)
1002 rl_beg_of_line (1, key
);
1003 while (rl_point
< rl_end
&& whitespace (rl_line_buffer
[rl_point
]))
1009 rl_vi_first_print (count
, key
)
1012 return (rl_vi_back_to_indent (1, key
));
1016 rl_vi_char_search (count
, key
)
1020 static int orig_dir
, dir
;
1022 if (key
== ';' || key
== ',')
1023 dir
= key
== ';' ? orig_dir
: -orig_dir
;
1027 target
= _rl_vi_last_search_char
;
1029 _rl_vi_last_search_char
= target
= (*rl_getc_function
) (rl_instream
);
1034 orig_dir
= dir
= FTO
;
1038 orig_dir
= dir
= BTO
;
1042 orig_dir
= dir
= FFIND
;
1046 orig_dir
= dir
= BFIND
;
1051 return (_rl_char_search_internal (count
, dir
, target
));
1054 /* Match brackets */
1056 rl_vi_match (ignore
, key
)
1059 int count
= 1, brack
, pos
;
1062 if ((brack
= rl_vi_bracktype (rl_line_buffer
[rl_point
])) == 0)
1064 while ((brack
= rl_vi_bracktype (rl_line_buffer
[rl_point
])) == 0 &&
1065 rl_point
< rl_end
- 1)
1066 rl_forward (1, key
);
1084 int b
= rl_vi_bracktype (rl_line_buffer
[pos
]);
1087 else if (b
== brack
)
1103 int b
= rl_vi_bracktype (rl_line_buffer
[pos
]);
1106 else if (b
== brack
)
1127 case ')': return -1;
1129 case ']': return -2;
1131 case '}': return -3;
1137 rl_vi_change_char (count
, key
)
1143 c
= _rl_vi_last_replacement
;
1145 _rl_vi_last_replacement
= c
= (*rl_getc_function
) (rl_instream
);
1147 if (c
== '\033' || c
== CTRL ('C'))
1150 while (count
-- && rl_point
< rl_end
)
1152 rl_begin_undo_group ();
1159 rl_end_undo_group ();
1165 rl_vi_subst (count
, key
)
1168 rl_begin_undo_group ();
1170 if (_rl_uppercase_p (key
))
1172 rl_beg_of_line (1, key
);
1173 rl_kill_line (1, key
);
1176 rl_delete_text (rl_point
, rl_point
+count
);
1178 rl_end_undo_group ();
1180 _rl_vi_set_last (key
, count
, rl_arg_sign
);
1184 int o
= _rl_doing_an_undo
;
1186 _rl_doing_an_undo
= 1;
1187 if (vi_insert_buffer
&& *vi_insert_buffer
)
1188 rl_insert_text (vi_insert_buffer
);
1189 _rl_doing_an_undo
= o
;
1193 rl_begin_undo_group ();
1194 _rl_vi_doing_insert
= 1;
1195 rl_vi_insertion_mode (1, key
);
1202 rl_vi_overstrike (count
, key
)
1207 if (_rl_vi_doing_insert
== 0)
1209 _rl_vi_doing_insert
= 1;
1210 rl_begin_undo_group ();
1213 for (i
= 0; i
< count
; i
++)
1216 rl_begin_undo_group ();
1218 if (rl_point
< rl_end
)
1226 rl_end_undo_group ();
1232 rl_vi_overstrike_delete (count
, key
)
1237 for (i
= 0; i
< count
; i
++)
1239 if (vi_replace_count
== 0)
1250 rl_backward (1, key
);
1253 if (vi_replace_count
== 0 && _rl_vi_doing_insert
)
1255 rl_end_undo_group ();
1257 _rl_vi_doing_insert
= 0;
1263 rl_vi_replace (count
, key
)
1268 vi_replace_count
= 0;
1270 if (!vi_replace_map
)
1272 vi_replace_map
= rl_make_bare_keymap ();
1274 for (i
= ' '; i
< KEYMAP_SIZE
; i
++)
1275 vi_replace_map
[i
].function
= rl_vi_overstrike
;
1277 vi_replace_map
[RUBOUT
].function
= rl_vi_overstrike_delete
;
1278 vi_replace_map
[ESC
].function
= rl_vi_movement_mode
;
1279 vi_replace_map
[RETURN
].function
= rl_newline
;
1280 vi_replace_map
[NEWLINE
].function
= rl_newline
;
1282 /* If the normal vi insertion keymap has ^H bound to erase, do the
1283 same here. Probably should remove the assignment to RUBOUT up
1284 there, but I don't think it will make a difference in real life. */
1285 if (vi_insertion_keymap
[CTRL ('H')].type
== ISFUNC
&&
1286 vi_insertion_keymap
[CTRL ('H')].function
== rl_rubout
)
1287 vi_replace_map
[CTRL ('H')].function
= rl_vi_overstrike_delete
;
1290 _rl_keymap
= vi_replace_map
;
1295 /* Try to complete the word we are standing on or the word that ends with
1296 the previous character. A space matches everything. Word delimiters are
1299 rl_vi_possible_completions()
1301 int save_pos
= rl_point
;
1303 if (rl_line_buffer
[rl_point
] != ' ' && rl_line_buffer
[rl_point
] != ';')
1305 while (rl_point
< rl_end
&& rl_line_buffer
[rl_point
] != ' ' &&
1306 rl_line_buffer
[rl_point
] != ';')
1309 else if (rl_line_buffer
[rl_point
- 1] == ';')
1315 rl_possible_completions ();
1316 rl_point
= save_pos
;
1322 /* Functions to save and restore marks. */
1324 rl_vi_set_mark (count
, key
)
1329 ch
= rl_read_key ();
1330 if (_rl_lowercase_p (ch
) == 0)
1336 vi_mark_chars
[ch
] = rl_point
;
1341 rl_vi_goto_mark (count
, key
)
1346 ch
= rl_read_key ();
1352 else if (_rl_lowercase_p (ch
) == 0)
1359 if (vi_mark_chars
[ch
] == -1)
1364 rl_point
= vi_mark_chars
[ch
];
1368 #endif /* VI_MODE */