e0f92c8df52335c266f73e3cc3384b277f3e9a34

Author
Julien Vincent <m@julienvincent.io>
Committer
GitHub <noreply@github.com>
Date

Message

feat(vi-mode): add settings for vi-mode cursor styles (#10860)

Diff

 1diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md
 2index 476666bf6bf64625ee2b843dd0f4652c16e6d2c0..3b819c7cba8d3a3aabcec8a2cb1aab2edfe1e60b 100644
 3--- a/plugins/vi-mode/README.md
 4+++ b/plugins/vi-mode/README.md
 5@@ -29,6 +29,8 @@ plugins=(... vi-mode)
 6   VI_MODE_SET_CURSOR=true
 7   ```
 8 
 9+  See [Cursor Styles](#cursor-styles) for controlling how the cursor looks in different modes
10+
11 - `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode.
12   See [Mode indicators](#mode-indicators) for details.
13 
14@@ -52,6 +54,25 @@ INSERT_MODE_INDICATOR="%F{yellow}+%f"
15 You can also use the `vi_mode_prompt_info` function in your prompt, which will display
16 this mode indicator.
17 
18+## Cursor Styles
19+
20+You can control the cursor style used in each active vim mode by changing the values of the following variables.
21+
22+```zsh
23+# defaults
24+VI_MODE_CURSOR_NORMAL=2
25+VI_MODE_CURSOR_VISUAL=6
26+VI_MODE_CURSOR_INSERT=6
27+VI_MODE_CURSOR_OPPEND=0
28+```
29+
30+- 0, 1 - Blinking block
31+- 2 - Solid block
32+- 3 - Blinking underline
33+- 4 - Solid underline
34+- 5 - Blinking line
35+- 6 - Solid line
36+
37 ## Key bindings
38 
39 Use `ESC` or `CTRL-[` to enter `Normal mode`.
40diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh
41index 149d6bbd5b79cb0b21d89272e61350a0ae838b23..9a410c1fb88470c96c395497af0a1e900fde604f 100644
42--- a/plugins/vi-mode/vi-mode.plugin.zsh
43+++ b/plugins/vi-mode/vi-mode.plugin.zsh
44@@ -14,6 +14,15 @@ typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE
45 # Unset or set to any other value to do the opposite.
46 typeset -g VI_MODE_SET_CURSOR
47 
48+# Control how the cursor appears in the various vim modes. This only applies
49+# if $VI_MODE_SET_CURSOR=true.
50+#
51+# See https://vt100.net/docs/vt510-rm/DECSCUSR for cursor styles
52+typeset -g VI_MODE_CURSOR_NORMAL=2
53+typeset -g VI_MODE_CURSOR_VISUAL=6
54+typeset -g VI_MODE_CURSOR_INSERT=6
55+typeset -g VI_MODE_CURSOR_OPPEND=0
56+
57 typeset -g VI_KEYMAP=main
58 
59 function _vi-mode-set-cursor-shape-for-keymap() {
60@@ -22,13 +31,13 @@ function _vi-mode-set-cursor-shape-for-keymap() {
61   # https://vt100.net/docs/vt510-rm/DECSCUSR
62   local _shape=0
63   case "${1:-${VI_KEYMAP:-main}}" in
64-    main)    _shape=6 ;; # vi insert: line
65-    viins)   _shape=6 ;; # vi insert: line
66-    isearch) _shape=6 ;; # inc search: line
67-    command) _shape=6 ;; # read a command name
68-    vicmd)   _shape=2 ;; # vi cmd: block
69-    visual)  _shape=2 ;; # vi visual mode: block
70-    viopp)   _shape=0 ;; # vi operation pending: blinking block
71+    main)    _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line
72+    viins)   _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line
73+    isearch) _shape=$VI_MODE_CURSOR_INSERT ;; # inc search: line
74+    command) _shape=$VI_MODE_CURSOR_INSERT ;; # read a command name
75+    vicmd)   _shape=$VI_MODE_CURSOR_NORMAL ;; # vi cmd: block
76+    visual)  _shape=$VI_MODE_CURSOR_VISUAL ;; # vi visual mode: block
77+    viopp)   _shape=$VI_MODE_CURSOR_OPPEND ;; # vi operation pending: blinking block
78     *)       _shape=0 ;;
79   esac
80   printf $'\e[%d q' "${_shape}"