Skip to content

Vi (Vim) editing mode

Koichi Murase edited this page Sep 18, 2017 · 31 revisions

Note: Here functionalities in the branch support-vi-mode is explained. These functionalities are not yet in master.

Enabling vi/vim editing mode

Vi/vim editing mode will be enabled by one of the following settings.

In ~/.inputrc

$if Bash

  # Option #1
  set editing-mode vi

$endif

In ~/.bashrc

if [[ $- == *i* ]]; then # in interactive session

  # Option #2
  set -o vi

  # Option #3
  #   Or, the following setting can also enable the vi/vim mode.
  bind 'set editing-mode vi'

  # Option #4
  #   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.
  bleopt default_keymap=vi

fi

Possible preferences for the insert mode

SP: magic-space / insert space

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'

C-k: kill-forward-line / digraphs

The default mapping of C-k is vi-insert/@norepeat 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'

C-o: single-command-mode / accept-and-next

The default mapping of C-o is vi-insert/single-command-mode. If you want to execute the command and load the next history entry with C-o, please add the following setting:

ble-bind -m vi_insert -f 'C-o' 'vi-insert/@norepeat accept-and-next'

Or you may like C-@, instead of C-o, bound to accept-and-next:

ble-bind -m vi_insert -f 'C-@' 'vi-insert/@norepeat accept-and-next'

surround.vim

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, cs, ds are supported, yet HTML/XML tags are not supported. Commands yS, ySS are to be implemented soon.

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