diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2023-03-18 16:23:39 -0700 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2023-03-18 16:23:39 -0700 |
commit | 4b0bbc0b263a150eb9a9b59f196914629be06a9b (patch) | |
tree | 619723cfa449f93149b766ee397f85ce2acef5f7 /plugins/vi-mode | |
parent | db7efd2336e4dbe6abf321b00dbc11bc5afb1355 (diff) | |
parent | 72732a224e886933df6b64a49ec6f5e94c884612 (diff) | |
download | zsh-4b0bbc0b263a150eb9a9b59f196914629be06a9b.tar.gz zsh-4b0bbc0b263a150eb9a9b59f196914629be06a9b.tar.bz2 zsh-4b0bbc0b263a150eb9a9b59f196914629be06a9b.zip |
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'plugins/vi-mode')
-rw-r--r-- | plugins/vi-mode/README.md | 40 | ||||
-rw-r--r-- | plugins/vi-mode/vi-mode.plugin.zsh | 23 |
2 files changed, 54 insertions, 9 deletions
diff --git a/plugins/vi-mode/README.md b/plugins/vi-mode/README.md index 476666bf6..0cb516751 100644 --- a/plugins/vi-mode/README.md +++ b/plugins/vi-mode/README.md @@ -29,6 +29,8 @@ plugins=(... vi-mode) VI_MODE_SET_CURSOR=true ``` + See [Cursor Styles](#cursor-styles) for controlling how the cursor looks in different modes + - `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode. See [Mode indicators](#mode-indicators) for details. @@ -49,8 +51,42 @@ MODE_INDICATOR="%F{white}+%f" INSERT_MODE_INDICATOR="%F{yellow}+%f" ``` -You can also use the `vi_mode_prompt_info` function in your prompt, which will display -this mode indicator. +### Adding mode indicators to your prompt + +`Vi-mode` by default will add mode indicators to `RPROMPT` **unless** that is defined by +a preceding plugin. + +If `PROMPT` or `RPROMPT` is not defined to your liking, you can add mode info manually. The `vi_mode_prompt_info` function is available to insert mode indicator information. + +Here are some examples: + +```bash +source $ZSH/oh-my-zsh.sh + +PROMPT="$PROMPT\$(vi_mode_prompt_info)" +RPROMPT="\$(vi_mode_prompt_info)$RPROMPT" +``` + +Note the `\$` here, which importantly prevents interpolation at the time of defining, but allows it to be executed for each prompt update event. + +## Cursor Styles + +You can control the cursor style used in each active vim mode by changing the values of the following variables. + +```zsh +# defaults +VI_MODE_CURSOR_NORMAL=2 +VI_MODE_CURSOR_VISUAL=6 +VI_MODE_CURSOR_INSERT=6 +VI_MODE_CURSOR_OPPEND=0 +``` + +- 0, 1 - Blinking block +- 2 - Solid block +- 3 - Blinking underline +- 4 - Solid underline +- 5 - Blinking line +- 6 - Solid line ## Key bindings diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 149d6bbd5..9a410c1fb 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -14,6 +14,15 @@ typeset -g VI_MODE_RESET_PROMPT_ON_MODE_CHANGE # Unset or set to any other value to do the opposite. typeset -g VI_MODE_SET_CURSOR +# Control how the cursor appears in the various vim modes. This only applies +# if $VI_MODE_SET_CURSOR=true. +# +# See https://vt100.net/docs/vt510-rm/DECSCUSR for cursor styles +typeset -g VI_MODE_CURSOR_NORMAL=2 +typeset -g VI_MODE_CURSOR_VISUAL=6 +typeset -g VI_MODE_CURSOR_INSERT=6 +typeset -g VI_MODE_CURSOR_OPPEND=0 + typeset -g VI_KEYMAP=main function _vi-mode-set-cursor-shape-for-keymap() { @@ -22,13 +31,13 @@ function _vi-mode-set-cursor-shape-for-keymap() { # https://vt100.net/docs/vt510-rm/DECSCUSR local _shape=0 case "${1:-${VI_KEYMAP:-main}}" in - main) _shape=6 ;; # vi insert: line - viins) _shape=6 ;; # vi insert: line - isearch) _shape=6 ;; # inc search: line - command) _shape=6 ;; # read a command name - vicmd) _shape=2 ;; # vi cmd: block - visual) _shape=2 ;; # vi visual mode: block - viopp) _shape=0 ;; # vi operation pending: blinking block + main) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line + viins) _shape=$VI_MODE_CURSOR_INSERT ;; # vi insert: line + isearch) _shape=$VI_MODE_CURSOR_INSERT ;; # inc search: line + command) _shape=$VI_MODE_CURSOR_INSERT ;; # read a command name + vicmd) _shape=$VI_MODE_CURSOR_NORMAL ;; # vi cmd: block + visual) _shape=$VI_MODE_CURSOR_VISUAL ;; # vi visual mode: block + viopp) _shape=$VI_MODE_CURSOR_OPPEND ;; # vi operation pending: blinking block *) _shape=0 ;; esac printf $'\e[%d q' "${_shape}" |