1

Inspired by this answer, I have the following in my vimrc:

augroup cursor
    au!
    autocmd VimEnter * silent !echo -ne "\e[1 q"
augroup end

However, this sometimes prints the following on startup:

^[[2;2R^[[>65;5402;1c^[]10;rgb:b2b2/b2b2/b2b2^[\^[]11;rgb:0000/0000/0000^[\

What is causing this? The work around I came up with was to add autocmd VimEnter * redraw!, but I would like to know the root cause and if there is a better way to fix this.

  • What terminal emulator are you using? – ZeroKnight Apr 30 at 9:12
  • Are you using tmux as well? If so, does this happen outside of tmux as well, or only in tmux? – ZeroKnight Apr 30 at 9:21
  • Studying those sequences, the first two are CSI sequences. ^[[2;2R is the terminal informing the application the cursor position (2, 2), ^[[>65;5402;1c I can't find anything on without knowing your terminal (possibly "Send Device Attributes"?), and the last two are OSC sequences: ^[]10;rgb...^[\ and ^[]11;rgb:...^[\ . Again, I'll need to know the terminal to begin finding out what those mean specifically, but they're setting the color of some two things. #b2b2b2 gives a light gray. Why these are showing up eludes me... – ZeroKnight Apr 30 at 10:21
  • @ZeroKnight This is using termite. Not using tmux. – ngenisis May 1 at 1:35
1

Not that it answers the question about the root cause but I found a better way (IMO) to reset the cursor on startup. The main problem is that vim only sends the "t_EI" escape sequence when is exiting either Insert mode or Replace mode (see :help termcap-cursor-shape) and since vim starts on Normal mode "t_EI" is not sent. An obvious solution to this is to enter and exit Insert mode on startup. This is one way to do it:

" Reset cursor on startup
augroup ResetCursorShape
au!
autocmd VimEnter * :normal :startinsert :stopinsert 
augroup END

I prefer this way over the code you referenced because even when I add the autocmd VimEnter * redraw! autocommand I still see the string in the command line for a split second and it is very annoying.

  • Welcome to Vi and Vim! You ought to be able to just do startinsert | stopinsert (no colons, no normal[!]), since you need an Ex command. – D. Ben Knoble Oct 27 at 16:20
  • @D.BenKnoble thank you for your warm welcome! Do you mean changing it to autocmd VimEnter * startinsert | stopinsert? For some reason it doesn't work for me. It seems to run but the cursor doesn't change to the one defined in t_EI. Any ideas why that may be? – Carles Ràfols Oct 28 at 15:58
  • Odd, yes. Then maybe just normal! :startinsert etc. – D. Ben Knoble Oct 28 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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