Vi mode
What
Display the current Vi mode (insert / normal / visual …) in the prompt. Useful
when using ZSH keymaps via bindkey -v, PowerShell PSReadLine
-EditMode Vi, or fish vi key bindings so you can tell at a
glance which mode you are in.
In ZSH, adding this segment automatically registers a zle-keymap-select hook.
In PowerShell, it registers a PSReadLine Vi mode change handler.
In fish, it registers an --on-variable fish_bind_mode handler
(only when vi or hybrid key bindings are active). All of them re-render the
prompt every time the active mode changes.
PowerShell support sets PSReadLine's ViModeIndicator to Script, replacing
cursor-shape mode indicators such as Cursor. The mode is then shown by this
segment in the prompt instead.
fish support overrides fish_mode_prompt with an empty function so fish's
built-in [N] / [I] mode indicator does not show up next to the mode
rendered by this segment. Make sure vi key bindings are enabled (e.g.
fish_vi_key_bindings) for the segment to display.
Sample Configuration
- json
- yaml
- toml
{
"type": "vimode",
"style": "plain",
"foreground": "#ffffff",
"background": "#0077c2",
"template": " {{ if eq .Mode \"normal\" }} NORMAL{{ else if eq .Mode \"visual\" }} VISUAL{{ else }} INSERT{{ end }} "
}
type: vimode
style: plain
foreground: "#ffffff"
background: "#0077c2"
template: ' {{ if eq .Mode "normal" }} NORMAL{{ else if eq .Mode "visual" }}
VISUAL{{ else }} INSERT{{ end }} '
type = "vimode"
style = "plain"
foreground = "#ffffff"
background = "#0077c2"
template = " {{ if eq .Mode \"normal\" }} NORMAL{{ else if eq .Mode \"visual\" }} VISUAL{{ else }} INSERT{{ end }} "
Template (info)
{{ .Mode }}
Properties
| Name | Type | Description |
|---|---|---|
.Mode | string | the normalized mode: insert, normal, visual, viopp, replace, or the raw keymap when unmapped |
.Keymap | string | the raw mode value ($KEYMAP in ZSH, e.g. main, viins, vicmd, visual, viopp; viins or vicmd in PowerShell PSReadLine; viins, vicmd, visual or replace in fish) |