Skip to main content

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, fish vi key bindings, or Nushell vi and helix edit modes 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.

Nushell has no mode change hook. Instead, the prompt is rendered once per mode up front and Nushell switches between the results itself through PROMPT_INDICATOR_VI_INSERT and PROMPT_INDICATOR_VI_NORMAL, so changing mode costs no render at all.

Nushell

Requires Nushell 0.117.0 or later. In vi and helix mode the whole prompt is handed to Nushell as these two indicators, so don't set them yourself. Nushell only knows an insert and a normal indicator: vi visual mode and helix select mode show the normal prompt, and .Mode is never visual there. Nushell's own cursor_shape setting decides the cursor shape, not cursor_style. The segment only tracks the mode in the left prompt: elsewhere, such as the right prompt, it stays hidden. The prompt is prepared by a Nushell hook, so don't replace $env.config.hooks.pre_prompt after the init script ran.

PowerShell cursor indicator

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, or configure the top-level cursor_style setting to vary the cursor shape by .Env.POSH_VI_MODE without a custom handler.

fish mode prompt

fish support overrides fish_mode_prompt to hook into bind mode changes and so that fish's built-in [N] / [I] mode indicator does not show up next to the mode rendered by this segment. Make sure nothing else in your config overrides fish_mode_prompt.

Sample Configuration​

− ▢ ×  INSERT _ ohmyposh.dev − ▢ ×  INSERT _ ohmyposh.dev

Template (info)​

default template
{
"template": " {{ .Mode }} "
}

Properties​

NameTypeDescription
.Modestringthe normalized mode: insert, normal, visual, viopp, replace, or the raw keymap when unmapped
.Keymapstringthe 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; viins or vicmd in Nushell, empty outside the left prompt)