3

Different methods exist to show if you're in insert or normal when using VI key binding in ZSH.

Gnome-terminal also allows you to change the caret from block to ibeam | with a call to gconftool-2.

How can I combine these two so that I have an ibeam in insert mode and a block in normal mode?

3
  • I've included links to my research. I've not attempted it myself. Stackoverflow does not require you show any previous efforts since this is not a homework forum. Mar 22, 2015 at 19:32
  • I've just asked because if you have an own approach it might be more helpful for you, if we can concentrate on your specific problem. And no just giving another copy&paste snippet. But here you are...
    – mpy
    Mar 22, 2015 at 20:28
  • I see, I misunderstood you. I have little understanding of zhs and it wasn't important enough for me to spend the time to get into it. I'm sure other might like this idea so I just posted it. It works great by the way! Thanks Mar 22, 2015 at 21:39

2 Answers 2

3

Putting both answers provided in the question [1, 2] together, I end up with this:

function zle-line-init zle-keymap-select {
    if [[ $KEYMAP == vicmd ]]; then
       gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block
    elif [[ $KEYMAP == (main|viins) ]]; then
       gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam
    fi
}
zle -N zle-line-init
zle -N zle-keymap-select

The difference is that I check the $KEYMAP parameter directly with an if..fi clause and execute the gconftool-2 command instead of altering the prompt.

1
  • 1
    Using gconftool to modify the profile has the significant drawback that it immediately influences all other gnome-terminal tabs or windows that use the same profile.
    – egmont
    May 6, 2015 at 21:17
4

In recent versions of gnome-terminal, you can use the following escape sequences to change the cursor:

  • \e[0 q or \e[ q: reset to whatever's defined in the profile settings
  • \e[1 q: blinking block
  • \e[2 q: steady block
  • \e[3 q: blinking underline
  • \e[4 q: steady underline
  • \e[5 q: blinking I-beam
  • \e[6 q: steady I-beam

You can print these by e.g. echo -ne '\e[5 q'. Hook these up to your zsh configuration as shown in mpy's answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .