Feb 2020
For those of us who run their shell in vi input mode, displaying the current mode as part of the prompt is a common thing to do.
In fish, switching to vi or hybrid mode is as easy as running fish_vi_key_bindings / fish_hybrid_key_bindings.
Fish then automatically shows the current input mode, by prepending
[I] or [N] etc. to the prompt. But how to customize the look of
the input mode display?
As is common practice with fish, you need to put a script with a magic
name in a magic folder and fish will call it when appropriate. In the
case of printing the input mode, fish will call a function called
fish_mode_prompt in a file called fish_mode_prompt.fish in
XDG_CONFIG_HOME/fish/functions/.
Inside that function you can read $fish_bind_mode to get the current
input mode. You can then echo whatever indicator you find appropriate
and fish will prepend it to the prompt.
The fish documentation describes this, but the link to it might not come up in search results if you don’t know that this feature is called “mode prompt”.