Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in bash -o vi mode to have the prompt indicate normal/command mode, etc

Tags:

bash

vim

I use vi mode in bash all of the time. It would be really useful to see visually if I am in command mode or insert mode.

For example when I want to search the history, typing /my_search in either mode looks the same until I press Enter, and by then it's too late. I find myself pressing Esc much more than necessary just to make sure I'm in the right mode....

like image 261
pixelearth Avatar asked Jun 22 '15 16:06

pixelearth


People also ask

How can you make sure that you are in the vi command mode?

If you're not sure which mode vi is presently in, simply press Esc to make sure it's in command mode and continue from there.

How do I set bash to vi mode?

The bash shell (again, via GNU Readline) is able to provide this functionality for us. In order to enable it, you run the command $ set -o vi.

How do I change the mode in vi editor?

Vi edit modesTo enter Insert mode, press i . In Insert mode, you can enter text, use the Enter key to go to a new line, use the arrow keys to navigate text, and use vi as a free-form text editor. To return to Command mode, press the Esc key once. [ Looking for a different text editor?


1 Answers

You can configure this in the .inputrc file that readline uses.

set show-mode-in-prompt

For me, this draws a + as the first character in insert mode, a : in normal mode, and no character in search mode.

(You can also enable vi mode in here using set editing-mode vi, which will enable it for all programs using readline, such as the python and ruby interpreters, instead of just bash).

like image 103
Ismail Badawi Avatar answered Sep 23 '22 11:09

Ismail Badawi