MacOS – Vim like terminal

bashmacosterminalvi

I recently discovered terminal's feature, you can set the keys emacs or vi style

I prefer the second. so if you do

set -o vi

You can use k j l h keys to navigate on the command line. And you can switch between 'Normal' and 'Insert' modes like in vim.

However there's no way to visually distinguish one mode from another, even cursor doesn't change. Which makes vi-style pretty much useless. Is there a way to make it truly vim-like?

Best Answer

  • You can switch from bash to zsh. I will not describe here how to set up mode indicator in Z-Shell – there are a lot of howtos over Internet, e. g.: [1], [2].
  • If you’re using GNU Bash version 4.3 (most probably you are not, it was released last month, so you'd need to upgrade), you can set Readline option show-mode-in-prompt.

Like so:

set show-mode-in-prompt On

in your .inputrc or

bind 'set show-mode-in-prompt On'

as a shell command. This adds a character to the beginning of the prompt indicating the editing mode: @ for Emacs, : and + for vi normal and vi insertion respectively.

I. e. your prompt will look like +agzam@pc:~$ in input mode and :agzam@pc:~$ in normal mode. As far as I understand this can not been customized in any way, but still it’s better than nothing.