Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

4 Answers 4

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)

#!/bin/bash
# Script "kmtest.sh"

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

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

gb

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

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 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
2  
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

Your Answer

 
discard

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.