5

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

7
  • What is your OS? Your vim is pure vim or neovim? What is your terminal? Is it bash? Commented Mar 7, 2022 at 1:58
  • 1
    Well, your snippet obviously handles entering Vim but not leaving it. Commented Mar 7, 2022 at 8:17
  • Philippe's answer solved it for me, but I will explain myself further. @yves pure vim, this happened to me both on bash and on tcsh, both in windows terminal running windows subsystem for linux with ubuntu, and with MATE terminal running linux. Commented Mar 7, 2022 at 10:50
  • @romainl I though it's a vim cfg file. I didn't realize things that I do there can persist outside of it. Commented Mar 7, 2022 at 10:54
  • 1
    @NimrodWeinberg, not everything can but what that trick does is that it emits a special sequence that puts the terminal in a special mode. What you change with it is the terminal, not Vim. Since you only want that change when you are in Vim, then you must set it up when you enter Vim and revert it when you leave it. Commented Mar 7, 2022 at 11:32

2 Answers 2

11

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 ...]

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for the solution! 2 things though - 1. it is causing me very slow shutdown of vim, as well as my "autocmd VimEnter * silent !echo -ne "\e[2 q" " which is causing very slow start up. Do you know why? 2. can you elaborate a bit on "*", "silent", "-ne"? thanks
I just tested on Ubuntu&Cygwin/Windows Terminal, the two commands don't slow down the startup or shutdown of vim.
0

using an init.vim file didnt work whatsoever so i just added a function in my bashrc to lauch vim and restore the default cursor like this:

vim(){
    /usr/bin/vim
    echo -ne "\e0 q" #only works in terminal emulator
    #you might want to use tput cnorm on console

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.