linuxvim

vim cursor style persists on terminal after quitting vim


I wanted vim to have a block cursor in normal mode and vertical cursor in insert mode, so I added the following code to .vimrc:

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

" reset the cursor on start (for older versions of vim, usually not required)
augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[2 q"
augroup END

In my terminal I want (and have) the vertical line style cusor. However, now when I enter and exist vim, on the terminal from which I invoked vim I am left with the block cursor

gif animation so you see what's going on


Solution

  • You can tell vim to restore vertical cursor on exit :

    autocmd VimLeave * silent !echo -ne "\e[6 q"
    

    *(star) : for all types of files

    silent : To avoid the message box that pops up to report the result

    !echo -ne : Run shell command [echo -ne ...]