-
-
Notifications
You must be signed in to change notification settings - Fork 84
Vi (Vim) editing mode
[ 日本語 | English ]
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
The following setting in ~/.blerc
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.
bleopt default_keymap=vi
The total timeout for ESC is the sum of all the timeouts on the route from your terminal to Bash. Each timeout can be configured as shown here:
The timeout in pseudo-terminal handler can be configured by stty
. Usually the default timeout is 0
. The timeout can be changed by the following command. The unit is 1/10 second.
# in ~/.bashrc
stty time 0
In Bash 4.3 or later, the timeout for Readline can be configured by readline variable keyseq-timeout
. The readline variable can be specified in ~/.inputrc
file. The unit is millisecond.
# in ~/.inputrc
$if Bash
set keyseq-timeout 1
$endif
Instead of specifying in ~/.inputrc
, the variable can also be changed in ~/.bashrc
with the following command.
# in ~/.bashrc
bind 'set keyseq-timeout 1'
If you use terminal multiplexers, they also have timeouts. The timeout for GNU Screen can be configured in ~/.screenrc
as follows. The unit is millisecond. Also any key bindings of bindkey -t
starting with an escape character should not be defined since the option -t
disables the timeout of the escape characater.
# in ~/.screenrc
maptimeout 1
The timeout for tmux can be configured in ~/.tmux.conf
. The unit is millisecond.
# in ~/.tmux.conf
set -sg escape-time 1
Settings for vi/vim mode can be registered to blehook keymap_vi_load
. The settings can be registered to the hook by the following code:
# blerc
function blerc/vim-mode-hook {
# Write your settings for vi/vim mode here
}
blehook/eval-after-load keymap_vi_load blerc/vim-mode-hook
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_nmap_name
option:
# in blehook keymap_vi_load
bleopt keymap_vi_nmap_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:
# in blehook keymap_vi_load
bleopt keymap_vi_nmap_name=
By bleopt variables term_vi_?map
, control sequences to be sent on entering each mode can be specified. For example, if your terminal supports some of DECSCUSR
, the following settings implement the cursor shape switching in each mode.
bleopt keymap_vi_nmap_cursor:=2
bleopt keymap_vi_imap_cursor:=5
bleopt keymap_vi_omap_cursor:=4
bleopt keymap_vi_xmap_cursor:=2
bleopt keymap_vi_cmap_cursor:=0
If your terminal actually supports Ss
entry although it's not shown in terminfo
, you can directly override the terminal information of ble.sh
as:
_ble_term_Ss=$'\e[@1 q'
The default mapping of SP is magic-space
which performs history and sabbrev expansion before inserting a space. If you want to have just a space without expansions, please add the following setting.
ble-bind -m vi_imap -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_imap -f 'C-k' 'vi_imap/insert-digraph'
The default mapping of C-o is vi_imap/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_imap -f 'C-o' 'accept-and-next'
Or you may like C-@, instead of C-o, bound to accept-and-next
:
ble-bind -m vi_imap -f 'C-@' 'accept-and-next'
Some of the functionalities are imported from github.com:tpope/vim-surround. To use them add the following setting in keymap_vi_load hook:
# in blehook keymap_vi_load
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.
# in blehook keymap_vi_load
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.
[ 日本語 | English ]