tags:

views:

446

answers:

3

When using vi mode (set -o vi) with Bash, it would be nice to have a prompt that depends on the mode you are currently in (insert or command). How does one find out this editing mode?

B.t.w, this seems to be possible in ZSH:

+1  A: 

Although not a one step solution, one way you could achieve this is by writing a script that changes both the editing mode and the prompt simultaneously & use said script exclusively when changing modes.

IE: Have a script called bash-vi that executes "set -o vi; PS1='desired vi mode prompt';"


Edit: (Can't comment yet) I see, I guess I didn't read the question carefully enough & overlooked the reference to insert & command mode. Not sure how to set that up either. Usually it hasn't been a problem for me since I only use the command mode for brief operations - I can see why it would be useful though.

dborba
No, what Thomas is asking for is different. With `set -o vi` on, he wants a visibly different prompt when he presses <ESC>, and then the original prompt again when he presses <I>.
ephemient
+1  A: 

After searching google, looking through the bash man page and then looking through the bash source code (the lib/readline/vi_mode.c) it looks like there is no easy way to change the prompt when moving from insert mode to command mode. It looks like there might be an opportunity here for someone to patch the bash source though as there are calls for starting and stopping the modes in the source.

Upon seeing your post it got me interested in the bash vi mode setting. I love vi and would why not on the command line. However it looks like we will have to keep track of whether we are in insert mode without a prompt change (so sayeth many forum posts) For what it is worth you are always in insert mode unless you hit ESC. Makes it a little easier, but not always as intuitive.

I'm upping your question as I'm interested in seeing where this goes.

Jeremy Heslop
A: 

I try to get a indicator for BASH vi mode also, and you all learned it's sound simple and just no way to do it yet.

My current approach is: hit 'a' when I not sure which mode is. IF 'a' appears after BASH PROMOT, I learn I am in 'INSERT' mode. THEN, I hit 'RETURN' and continue. This is a easy way for me to solve the small annoyance.

By the way, I 'alias a='cal', or something else to give the empty hit 'a' little usefulness.

Andrew_1510