-
-
Notifications
You must be signed in to change notification settings - Fork 84
Vi (Vim) editing mode
Note: Here functionalities in the branch
support-vi-mode
are explained. These functionalities are not yet inmaster
.
Vi/vim editing mode will be enabled by one of the following settings.
In ~/.inputrc
$if Bash
set editing-mode vi
$endif
Another way is to use set -o vi
in ~/.bashrc
.
if [[ $- == *i* ]]; then # in interactive session
set -o vi
fi
Or, the following setting also enables the vi/vim mode.
if [[ $- == *i* ]]; then # in interactive session
bind 'set editing-mode vi'
fi
After the load of the ble.sh, the following setting also enables the vi/vim mode. This setting overwrites all the other settings presented so far, i.e., settings like set -o emacs
, etc. will be overwritten.
if [[ $- == *i* ]]; then # in interactive session
# ... after the load of ble.sh ...
bleopt default_keymap=vi
fi
In vi/vim mode mode names, such as -- INSERT --
(for insert mode) or ~
(for normal mode) are shown. The mode name for the normal mode can be change by keymap_vi_normal_mode_name
option:
bleopt keymap_vi_normal_mode_name:=$'\e[1m-- NORMAL --\e[m'
If you don't want to show a mode name in the normal mode, please add the following instead:
bleopt keymap_vi_normal_mode_name:=
The default mapping of SP
is magic-space
which performs history expansion before inserting a space. If you want to have just a space without history expansion, please add the following setting.
ble-bind -m vi_insert -f 'SP' 'self-insert'
The default mapping of C-k
is kill-forward-line
. If you want to input digraphs with <C-k>{char1}{char2}
, please add the following setting:
ble-bind -m vi_insert -f 'C-k' 'vi-insert/insert-digraph'
The default mapping of C-o
is vi-insert/single-command-mode
. If you want to execute the current command line and load the next history entry with C-o
, please add the following setting:
ble-bind -m vi_insert -f 'C-o' 'accept-and-next'
Or you may like C-@
, instead of C-o
, bound to accept-and-next
:
ble-bind -m vi_insert -f 'C-@' 'accept-and-next'
Some of functionalities are imported from github.com:tpope/vim-surround. To use them add the following line after loading ble.sh
:
source "$_ble_base/lib/vim-surround.sh"
Currently only ys
, yss
, yS
, ySS
, cs
, ds
, vS
, vgS
are supported.
The implementation vim-surround.sh
supports configurable replacements used by ys
and cs
with bleopt
variables. The following codes show example configuration.
bleopt vim_surround_45:=$'$( \r )' # for ysiw-
bleopt vim_surround_61:=$'$(( \r ))' # for ysiw=
bleopt vim_surround_q:=\' # for ysiwq
bleopt vim_surround_Q:=\" # for ysiwQ
The variables of the form vim_surround_{number}
is the setting for the Unicode character {number}
specified in decimal. The variables of the form vim_surround_{alpha}
is the setting for the character {alpha}
. The form vim_surround_{alpha}
is selected if both forms are defined for a character. If the value contains CR
($'\r'
in bash scripts), the value is split into two parts with the first CR
; the first and second part is used for the left and right enclosing delimiters, respectively. If the value does not contain CR
, the value is directly used for both of the left and right delimiters.