-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Feature description
Brush should support vi style line editing. Currently, brush only supports emacs line editing.
Use case / motivation
I (and other users I know) use vi mode in bash for more efficient line editing.
For many users vi-style line editing is a must-have feature for a shell.
As my standard .bashrc setup includes:
# Vi mode
set -o vi
bind -m vi-insert "\C-l":clear-screenProposed solution
Set switch behaviors:
set -o emacs # set vi OFF; set emacs ON
set +o emacs # set emacs OFF
set -o vi # set emacs OFF; set vi ON
set +o vi # set vi OFFSet switches:
(emacs OFF, vi OFF) => no line editing
(emacs ON, vi OFF) => emacs line editing
(emacs OFF, vi ON ) => vi line editing
(emacs ON, vi ON ) => [NOT possible to set]
Line editing mode should be stored with something like this:
enum LineEditingMode {
/// no line editing (emacs OFF, vi OFF)
None,
// Emacs style line editing (emacs ON, vi OFF)
#[default]
Emacs,
// Vi style line editing (emacs OFF, vi ON)
Vi,
}Example session of bash --norc showing expected behavior:
bash-5.3$ alias m='set -o | rg -w "vi|emacs"; echo'
bash-5.3$ m # default (emacs)
emacs on
vi off
bash-5.3$ set -o vi # set to vi
bash-5.3$ m
emacs off
vi on
bash-5.3$ set -o emacs # set to back to emacs
bash-5.3$ m
emacs on
vi off
bash-5.3$ set +o emacs # disable line editing (tab inserts tab character)
bash-5.3$ m
emacs off
vi offAdditional context
Bash docs on vi mode:
While the Readline library does not have a full set of
viediting functions, it does contain enough to allow simple editing of the line. The Readlinevimode behaves as specified in theshdescription in the POSIX standard.You can use the
set -o emacsandset -o vicommands (see The Set Builtin) to switch interactively betweenemacsandviediting modes, The Readline default isemacsmode.When you enter a line in
vimode, you are already placed in 'insertion' mode, as if you had typed ani. PressingESCswitches you into 'command' mode, where you can edit the text of the line with the standardvimovement keys, move to previous history lines withkand subsequent lines withj, and so forth.
https://www.gnu.org/software/bash/manual/html_node/Readline-vi-Mode.html