Mostafa Shahverdy
Mostafa Shahverdy

Reputation: 2725

How to make cursor change in different modes in vim?

How can I make Vim change cursor in different modes so that these conditions are satisfied:

  1. Without using gconftool or such tools. I need this affect only one instance of Vim, not the whole terminal.
  2. This must be working in Gnome Terminal and GVim.

PS: I have tried changing with sample in help gcr, but it only works for GVim, and not Vim in Gnome terminal.

PPS: I have tested http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes, but it changed the cursor for the whole terminal.

PPPS:Playing with gcr is preferred.

Upvotes: 2

Views: 6011

Answers (2)

Billy Chan
Billy Chan

Reputation: 24815

I've encountered the same problem before and tried a couple of options.

Let me sum them up first:

Option 1: Change cursor shape.
Ref: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
Result: This won't work for me

Option 2: Change cursor colour.
Ref: http://vim.wikia.com/wiki/Configuring_the_cursor
Result: This works but will change terminal cursor after leaving vim. Not acceptable to me.

Option 3: Change cursor line colour
Ref: How do I change the vim cursor in Insert/normal mode?

Final result: Option 3 works best for me, with a little more code to define Cursor colour in theme.

In vimrc, add these:

autocmd InsertEnter * set cul
autocmd InsertLeave * set nocul

Then, in your theme file, set Cursor to be a little darker than background. For example

hi Cursor ctermbg=black
hi Normal ctermbg=darkgray

After adding these settings, when you enter visual mode, the line will be darker so you can recognize it easily. It works a bit differently in Gvim but it's quite acceptable to me. Besides, you will forget Gvim totally once you get used to terminal vim.

Upvotes: 7

tokoyami
tokoyami

Reputation: 111

You could use the togglecursor plugin. It does exactly what you want and tries to support as many terminals as possible, including the gnome terminal. The plugin works by sending terminal escape sequences to change the cursor shape instead of using external applications. The cursor shape is reverted back on quiting vim.

From the documentation:

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.

Upvotes: 1

Related Questions