I use vim under iTerm2 in Mac, or putty in windows. I want to see different vim cursor shape in different vim mode. I know gvim & macvim have this feature, and there's an article to figure out how to do that in gnome-terminal & KConsole. But I can't search out any solution in iTerm2 and Putty.
4 Answers
The plugin by Steve Losh (https://github.com/sjl/vitality.vim) is a little buggy for some (adds weird characters in place of the cursor when you switch between tabs in iTerm2).
Adding this to your .vimrc works for me:
" Change cursor shape between insert and normal mode in iTerm2.app
if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
endif
Credit goes to Erlend Hamberg: http://hamberg.no/erlend/posts/2014-03-09-change-vim-cursor-in-iterm.html
Comments
I use this plugin since a long time, and it works perfectly with Konsole but it also supports a lot of terms.
The documentation says:
Currently supported terminals are iTerm2 for the Mac (version 1.0.0.20130602 beta or better is required), VTE3 based terminals (including gnome-terminal), and KDE's Konsole. The xterm console is partially supported as well. Older xterm's didn't support the line cursor, so this plugin currently sets the cursor to underline instead.
Older versions of VTE3 based terminals (before v0.39) do not support changing the cursor via escape sequences and are not supported. On unsupported terminals, Vim's default behavior is left unaltered.
The plugin also supports tmux, and will change your cursor inside a tmux session too.