4

I'm used to work with gvim, but I want to use the benefits of vim+tmux. Therefor I want to change to vim. But in vim the cursor style does not change depending in which mode I am, a useful feature of gvim. I use the zsh (oh-my-zsh) and below the gnome-terminal.

I tried this answer: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes

if has("autocmd")
  au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
  au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
 au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
endif

but that changes the cursor globaly. Definitely something I don't want

next I tried this plugin: http://www.vim.org/scripts/script.php?script_id=4403 , but it hasn't worked neither.

Natjo
  • 2,005
  • 29
  • 75
  • It looks as it would suit my needs, but it does not work, too. Can you imagine why? – Natjo Dec 13 '15 at 14:46
  • It seems I completely misread your post. I've deleted my answer. – Dan Lowe Dec 13 '15 at 20:31
  • Possible duplicate of [How do I change the vim cursor in Insert/normal mode?](http://stackoverflow.com/questions/6488683/how-do-i-change-the-vim-cursor-in-insert-normal-mode) – Gerhard Burger Jun 21 '16 at 11:34

3 Answers3

3

Probably, wincent/terminus vim plugin is what you need:

In insert mode, the cursor shape changes to a thin vertical bar. In replace mode, it changes to an underline. On returning to normal mode, it reverts to the standard "block" shape. Configuration options are provided to select among the different shapes.

Tim Gabets
  • 159
  • 1
  • 5
0

For colours, which is what I use:

let &t_SI = "\<Esc>]12;yellow\x7"
let &t_SR = "\<Esc>]12;red\x7"
let &t_EI = "\<Esc>]12;blue\x7"

Other options:

" solid underscore
"  let &t_SI .= "\<Esc>[4 q"

" solid block
" let &t_EI .= "\<Esc>[1 q"
  " 1 or 0 -> blinking block
  " 3 -> blinking underscore
  " Recent versions of xterm (282 or above) also support
  " 5 -> blinking vertical bar
  " 6 -> solid vertical bar

These are termcap codes, see help termcap-cursor-color. The codes themselves are console_codes(4). Thus, these are interactions with the terminal itself, not the vim session.

I have unfortunately not solved an issue about leaving Vim and having the original cursor colour returned. I have tried the following and many variants thereof:

au VimLeave    * let &t_EI = "\<Esc>]12;white\x7"
au VimLeavePre * :!echo -ne "\033]12;white\000"
au VimLeavePre * let &t_SI = "\<Esc>]12;white\x7"

but with no success. Anyway, this is how one can change the cursor shape and colour in relation to the editing mode.

For more general changes (eg, the colorscheme changes) upon change of mode, I use

au InsertEnter * call ColoursBasedOnMode(v:insertmode)
au InsertLeave * call ColoursBasedOnMode('n')
autocmd BufWinEnter,BufNew * call ColoursBasedOnMode('n')

in which I have :

   :
   :
elseif a:mode == 'i'
    "echo " ColoursBasedOnMode insert mode"
    "set nonumber
    "set norelativenumber

    colorscheme railscasts 
         :
         :
0

Set the terminal options just for this terminal emulator. As pointed here: https://stackoverflow.com/a/25327689/2544873.

 let &t_SI = "\<Esc>]12;orange\x7"
 let &t_EI = "\<Esc>]12;red\x7"
 autocmd VimLeave * silent !echo -ne "\033]112\007"
  1. Set terminal cursor on enter insert mode
  2. Set terminal cursor on leave insert mode
  3. Reset default (gray) color on leave vim
Tinmarino
  • 3,693
  • 24
  • 33