Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To clarify: I am not asking how to change the cursor when using vim within a terminal. I want the cursor to change when switching between input and command mode within Bash's vi-mode:

set -o vi <CR> type some text <ESC> (the cursor changes shape/color)
i (cursor change back) etc... 

I found a script that makes changing color of the cursor on mode changes possible in zsh, but I don't want to change shells just for this one feature.

Is there a way to get the cursor to change shape, like in gvim, (or even just color) when switching between command and insert modes on the Bash command line?

share|improve this question
Same question in SO for Putty, no answer tho :( -stackoverflow.com/questions/2393383/… – studgeek Aug 30 '12 at 15:58

Copied from here - Command-line editing vim style

Should be available in bash 4.3 - see the changelog -

j.  New user-settable variable, show-mode-in-prompt, adds a characters to the
    beginning of the prompt indicating the current editing mode.

bash 4.3 is currently at the rc stage, you should be able to get packages for most distros without compiling from source, though not in the main repositories. Eg. Ubuntu (amd64) here and Debian (experimental repo) here.

share|improve this answer

I've not find a real solution, but perhaps this could help you (or someone else) to find a better one.

You have to create a script (e.g. kmtest.sh)

# Script "kmtest.sh"

TEST=`bind -v | awk '/keymap/ {print $NF}'`
if [ "$TEST" = 'vi-insert' ]; then
   echo -ne "\033]12;Green\007"
   echo -ne "\033]12;Red\007"

and after add it to your PS1, something like:

export PS1="\u@\h \$(kmtest.sh)> "

but as I said, it is not what you want, cause it changes cursor color only after a cr. Good luck


share|improve this answer
Did this actually work for you? It did not work for me; it just made the cursor red. I don't think kmtest.sh is run every time I switch between insert and command modes. It seems like it would only be run on the creation of the prompt. – joecan Nov 11 '11 at 2:42

It looks like there may be a way to do it through hacking readline. Perhaps we could push for it to get mainstreamed?

Here is my answer on SO http://stackoverflow.com/a/12201092/255961 which I will update if I get more info.

share|improve this answer

I asked the same question a while back on AskUbuntu when I was transitioning from Gvim to Console Vim.

I received one answer but it involved toggling the gnome terminal settings, and these settings applied across terminals. Thus, it was possible for the gnome terminal cursor to be stuck in the wrong state at times.

I'm still interested in whether you get a satisfactory solution, but over time I've adjusted to the lack of mode state information in the cursor. Perhaps I just press escape more often (e.g., esc to ensure I'm in command-mode; esc i to ensure I'm in insert mode); perhaps I look at the state displayed at the bottom of the screen; perhaps I've just internalised the mode.

share|improve this answer
Just to clarify, you're question is not the same as mine. You asked how to change the cursor within Vim on the console. This is well documented on the Vim wiki. I want to know how to do this in Bash's vi-mode. – joecan Oct 13 '11 at 17:45

While it's not exactly what you want (dynamically changing the cursor), bash 4.4 / readline 7.0 will add support for dynamically changing the prompt . You will be able to specify custom mode indicators for insert/command modes (This is different then the current show-mode-in-prompt option which is hardcoded to use + and :).

Unfortunately these versions are currently in beta and don't seem to have all the bugs ironed out yet. They're also missing the ability to specify where in the prompt you'd like the mode indicator to occur.

In the interim I've published patched versions of bash 4.3 / readline 6.3 on github with this functionality.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.