Browse Source

Make vi-mode in shells optional with $VI_MODE

Modal behaviour confuses people who are not used to vi. If it is wanted,
users can set `export VI_MODE=1` in an `*env.local` file.
Weiyi Lou 9 năm trước cách đây
mục cha
commit
d14677107e
3 tập tin đã thay đổi với 9 bổ sung5 xóa
  1. 3 3
      shell/bash/keybindings.bash
  2. 4 0
      shell/env
  3. 2 2
      shell/zsh/key-bindings.zsh

+ 3 - 3
shell/bash/keybindings.bash

@@ -1,5 +1,5 @@
-# Use vi-bindings in readline for command editing
-set -o vi
+# Maybe use vi-bindings in readline for command editing
+[[ $VI_MODE = 1 ]] && set -o vi
 
 # Stop readline from auto-binding some control characters (e.g. ctrl-w) so that
 # they can be reassigned as desired.
@@ -8,7 +8,7 @@ bind 'set bind-tty-special-chars off'
 # Set Ctrl-w to delete by word boundaries instead of to the previous space.
 bind '\C-w:backward-kill-word'
 
-# Set Ctrl-l to clear the screen.
+# Set Ctrl-l to clear the screen. (Enforced as vi-mode does not set this)
 bind '\C-l:clear-screen'
 
 # Search history for the current input string.

+ 4 - 0
shell/env

@@ -2,6 +2,10 @@
 export EDITOR='vim'
 export PAGER='less'
 
+# Shells default to emacs bindings (ESC confuses people), unless a local env
+# file sets this to 1.
+export VI_MODE=0
+
 # Paths
 export PATH=$HOME/dotfiles/bin:$HOME/bin:$PATH
 export MANPATH=$MANPATH:$HOME/dotfiles/docs/man

+ 2 - 2
shell/zsh/key-bindings.zsh

@@ -5,8 +5,8 @@
 # - terminfo - "smkx" and "rmkx"
 
 
-# Use vi-bindings in ZLE (Zsh Line Editor) for command editing.
-bindkey -v
+# Maybe use vi-bindings in ZLE (Zsh Line Editor) for command editing.
+[[ $VI_MODE = 1 ]] && bindkey -v || bindkey -e
 
 
 # <S-Tab> to cycle backwards through autocomplete suggestions.