Changing the cursor shape in the interactive IPython consle depending on vi-mode

Viewed 661

I can change from emacs to vi bindings in the interactive IPython console, by adding the following to ~/.ipython/profile_deafult/ipython_config.py:

c.TerminalInteractiveShell.editing_mode = 'vi'

Currently, the cursor is always an I-beam (|). Is there a way that I can make the cursor change shape to a block when in vi's normal mode and then back to an I-beam when in insert mode?


My terminal emulator (terminator, based on gnome-terminal) supports switching between cursor formats, as I can enable the behavior in zsh, by adding the following to my ~./zshrc (from the Unix SE):

bindkey -v
# Remove delay when entering normal mode (vi)
KEYTIMEOUT=5
# Change cursor shape for different vi modes.
function zle-keymap-select {
  if [[ $KEYMAP == vicmd ]] || [[ $1 = 'block' ]]; then
    echo -ne '\e[1 q'
  elif [[ $KEYMAP == main ]] || [[ $KEYMAP == viins ]] || [[ $KEYMAP = '' ]] || [[ $1 = 'beam' ]]; then
    echo -ne '\e[5 q'
  fi
}
zle -N zle-keymap-select
# Start with beam shape cursor on zsh startup and after every command.
zle-line-init() { zle-keymap-select 'beam'}
1 Answers
Related