I have the following line in my .bashrc:
set -o vi
And I want my cursor to have a pipe shape when I am in insert mode and a block shape when I am in command mode, like what I would have in Vim if I placed the following in my .vimrc:
let &t_SI = "\e[6 q"
let &t_SR = "\e[4 q"
let &t_EI = "\e[2 q"
Except in this case I want to have the equivalent behavior on the command line.
I found a partial answer to my question here - https://unix.stackexchange.com/questions/22527/change-cursor-shape-or-color-to-indicate-vi-mode-in-bash - written by @gogolb.
Here is the answer, copied:
#!/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
export PS1="\u@\h \$(kmtest.sh)> "
Unfortunately, though, as explained in the answer, the example script only changes the cursor shape after a carriage return, whereas, what I want is for the cursor shape to change when I hit <Esc> (i.e. when I change mode).
I am on Linux running the native terminal app, with Bash 4.4.7 and my $TERM variable set to xterm-256color. Also, I do not know if tmux has any effect on what I am asking for, but I, ideally, would like the solution to work both within and exterior to tmux sessions.
SOLUTION
I ended up discovering the answer to this question myself, which I describe here in another question I posted:
How to correctly link patched GNU readline library to all existing programs?
Don't worry, the solution does not require any patching. ;)
.inputrc
, the cursor within vim (like, when I'm editing a file) changes to a pipe symbol as well. I don't want that - any idea how I can prevent that from happening? – Sharmainesharman