2

I use iTerm2 (Build 1.0.0.20130319) and Vim (bin of MacVim Snapshot 66) on top of OS X 10.7.5 as my CLI editing team.

In iTerm2 I defined to use a non-blinking vertical bar as a cursor shape. In Vim I defined

" Enter insert mode (Cursor shape: vertical bar)
let &t_SI = "\<Esc>]50;CursorShape=1\x7"

" Leave insert mode (Cursor shape: block)
let &t_EI = "\<Esc>]50;CursorShape=0\x7"

to be able to distinct between insert and normal mode. Basically this works fine. The problem arises when I leave Vim and return to the CLI. What happens is that the cursor does not return in its initial shape (vertical bar). Instead it decides to stay in a block shape.

Could I reset the cursor to it's initial shape or force it to return to be a vertical bar? I Could imagine to trigger an event on e.g. "VimLeave". But I don't know what I could pass as an escape sequence.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Saucier
  • 4,200
  • 1
  • 25
  • 46

4 Answers4

8

After a little bit more digging into :help I found out that

autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"

would revert the cursor shape to its initial, or let's say a defined, shape. That works great so far.

Does anyone know downsides of that approach? Besides VimLeave one could also trigger VimLeavePre or QuitPre.

EDIT: Even better there's a new plugin available which does exactly what some people are looking for.

https://github.com/jszakmeister/vim-togglecursor

It's a little bit configurable, too:

let g:togglecursor_default = "block"
let g:togglecursor_insert = "line"
let g:togglecursor_leave = "line"
let g:togglecursor_disable_tmux = 0
John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
Saucier
  • 4,200
  • 1
  • 25
  • 46
1

Did you try this?

autocmd VimLeave * let &t_SI = "\<Esc>]50;CursorShape=1\x7"
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Yes I did. It does not behave as expected. The result is the same as above, as a side effect it doesn't change the shape anymore while switching between normal and insert mode. – Saucier Mar 21 '13 at 14:38
1

I'm using Iterm with regular vim. This sets cursor solid on launch vim, blinks on insert mode. And returns to blinking on exit vim.

augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[2 q"
autocmd VimLeave * silent !echo -ne "\e[1 q"
augroup END
lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
0

I tried this method before because I was used to Gvim's cursor style when switching to terminal. But I met the same problem and had no way to fix it.

Finally I have been using changing Cursor colour method. Once I got used to the style, I'm quite happy it and forget the cursor shape at all.

Change Cursor colour method

autocmd InsertEnter * set cul
autocmd InsertLeave * set nocul

Then set similar but different colour for Cursor than Normal in the theme if there is no built-in scheme in this theme.

Source: http://vim.wikia.com/wiki/Configuring_the_cursor

My sum of three methods for identifying insert mode in terminal: How to make cursor change in different modes in vim?

Community
  • 1
  • 1
Billy Chan
  • 24,625
  • 4
  • 52
  • 68