I want to use block cursor for normal mode, bar cursor for insert mode in both vim and bash vi mode, a minimal setting can look like this:

let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"

set vi-cmd-mode-string \1\e[2 q\2(c)
set vi-ins-mode-string \1\e[5 q\2(i)

They work fine on their own, but broke when you switch from bash to vim.

If I execute vim in bash, the initial cursor for vim is bar in normal mode.

If I suspend vim by c-z and use fg to get it back, the cursor also becomes a bar in normal mode.

It's annoying to use i<esc> to restore cursor to block in vim.

If I run command in readline vi cmd mode instead of vi ins mode, the problem vanished away, I'm not sure it's the right way, it's annoying to return to cmd mode before executing a command.

Are there other ways to deal with it?

I use urxvt v9.22, vim8.2, bash4.4.2, ubuntu18.04

2 Answers 2


Bash 4.4 provide PS0:

     The value of this parameter is expanded like PS1 and displayed by
     interactive shells after reading a command and before the command
     is executed.

We will use it to restore cursor to block before executing a command, add this to your bashrc:

PS0='\[\e[2 q\]'

If you use tmux:

PS0='\[\ePtmux;\e\e[2 q\e\\\]'

If you use gnome-terminal, you might see some weird 001b rect, if you add escape sequence to PS0, this might be a bug.

Thhis won't work in vim terminal inside tmux ( urxvt-->tmux-->vim-->:terminal), you can't even change cursor shape in that terminal?


Learned new trick from this question:

let &t_ti .= "\<esc>[2 q"

This change cursor to block whenever you put vim foreground.


I use this half-working solution, from vim fadom:

autocmd VimLeave * silent !echo -ne "\033]12;gray\007"
" use \003]12;gray\007 for gnome-terminal and rxvt up to version 9.21
" or \003]12\007 for other terminals

This does not work when you suspend Vim, though...

  • I think that's used to reset cursor color when you exit vim. My problem is when you execute vim or fg in bash, you get vim with a bar cursor in normal mode.
    – dedowsdi
    May 28, 2020 at 23:46
  • Sorry, I understood your problem the other way around. Looks like bash settings take precedence over Vim. Some shenanigan at work here... I already looked into this a few months back and ended up accepting to keep a block cursor in bash vim insert mode.
    – Biggybi
    May 29, 2020 at 1:08
  • Me too. I guess there might be some t_magic option, it's send to the terminal when you push vim foreground, but I can't find it.
    – dedowsdi
    May 29, 2020 at 1:13
  • I couldn't find anything about it =/
    – Biggybi
    May 29, 2020 at 2:27
  • I think I find it, see my answer.
    – dedowsdi
    May 29, 2020 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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