6

I've noticed when I use the Terminal that the cursor is not as I configured it.

In other words, in the GUI it looks perfect, the cursor that is, but in the Terminal it takes time to update, it doesn't look like I configured it etc.

Here are my settings for the cursor:

set guicursor=n-v-c:block-Cursor-blinkon0
set guicursor+=ve:ver35-Cursor
set guicursor+=o:hor50-Cursor-blinkwait175-blinkoff150-blinkon175
set guicursor+=i-ci:ver20-Cursor
set guicursor+=r-cr:hor20-Cursor
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175

I do notice it's called the guicursor setting, however in Terminal some of these do take effect, they just don't take a full effect.

Also, it seems the cursor doesn't get updated a lot. For example if I enter insert mode the correct cursor is put, but if I get out, the same cursor is used until I move or something then it updated to the normal mode cursor.

Do you have any tips on this? Or do I just have to bear with it?

EDIT:

My OS is a Mac Mini with Mountain Lion installed. I am using iTerm2 with xterm-color256 as the Terminal.

Re-wording the question: How can I make the cursor redrawing faster in a Terminal and how can I make it take the settings I put above? I already tried ttyfast and lazyredraw.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
greduan
  • 4,770
  • 6
  • 45
  • 73

4 Answers4

7

Your settings are for GUI Vim. You can't expect them to work in CLI Vim. If you don't like how CLI Vim works, just use MacVim.

I've got a slightly different version of this function executed in my ~/.vimrc:

" changes the cursor shape/color
" in the terminal depending on the mode
" see http://code.google.com/p/iterm2/issues/detail?id=710&q=cursor
function! SetCursorStyle()
  if &term =~ "xterm\\|rxvt"
    " use a | cursor in insert mode
    let &t_SI = "\<Esc>]50;CursorShape=1\x7"

    " use a rectangle cursor otherwise
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"

    " reset cursor when vim exits
    autocmd VimLeave * silent !echo -ne "\<Esc>]50;CursorShape=0\x7"

  endif
endfunction
romainl
  • 186,200
  • 21
  • 280
  • 313
  • True I can't expect it to work flawlessly, but since some things do work... That seems like a nice function. I'll check it out! +1 – greduan Dec 25 '12 at 14:03
  • 1
    Turns out vitality.vim already does this, so I'll just keep it in mind for the future and accept this answer. :) – greduan Dec 25 '12 at 16:04
1

I use Cygwin, and I use the above setting but Cygwin's xterm may can't recognize the "\]50;CursorShape=1\x7"

So I try this one, and it work

if &term =~ "xterm\\|rxvt"
  " use a | cursor in insert mode
  let &t_SI = "\<Esc>[5 q"

  " use a rectangle cursor otherwise
  let &t_EI = "\<Esc>[1 q"
endif

then, I add this to .bashrc to change the term cursor to block, and it perfect to me.

# change cursor to blinking block
echo -ne "\x1b[1 q"
SenZhang
  • 141
  • 1
  • 6
0

Did you try this?

:help 'ttyfast'

If the cursor has a delay, try this (to enable ttyfast:

:set ttyfast
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
0

Using terminfo

If echo $TERM gives linux on your machine, you can use terminfo to define the cursor for Vim.

We can set the cursor by changing it in the terminfo database:

infocmp -A /usr/share/terminfo linux > linux_terminfo

Then edit linux_terminfo with your favorite editor; the cnorm entry is the one for the normal cursor. This sets the cursor to a non-blinking green rectangle:

clear=\E[H\E[J, cnorm=\E[?25h\E[?48;0;32c, cr=^M,

Write the changes back to the terminfo database:

tic linux_terminfo

Then, once you open a file with Vim, you'll see the new cursor.

terminfo's colors

The number before the c (e.g., 32c) defines the cursor's color. The cursor background color changes in increments of 16. To have the character under the cursor highlighted, add 8 to the number. For example: 16 gives a blue cursor without highlighting the character under the cursor. To activate highlighting, add 8 to the number: 24

A preliminary color list:

0  → gray
16 → blue
32 → green
48 → cyan
64 → red
80 → magenta
96 → brown
112 → gray
128 → ivory
144 → light blue
160 → lime
176 → light cyan
194 → pale red
212 → pink
228 → yellow
...

terminfo and Bash

To make the terminfo configuration for the normal cursor effective on startup in Bash, put this in your .bash_profile:

tput cnorm

This way, you have the same cursor in Vim and in Bash.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171