Friday, August 26, 2011

Re: changing vim cursor shape or color in vim 7.0

sinbad, Wed 2011-08-17 @ 04:55:19-0700:
> i'm using vim 7.0 inside a gnu screen.
> i use vim by puttying to the linux server.
> i want to change the cursor shape or color
> whenever i want, basically i would like to
> set the cursor to a different shape or color
> when a variable is set. i tried experimenting
> with t_ve option in vim. currently it is set to
> t_ve=^[[34h^[[?25h, i don't know what those
> values are, but i tried to change the numbers
> with the hope that it might change either
> color or shape of the cursor. but no matter
> what vlaues i use the cursor just disappears.
> i want to know what the values exactly mean
> and how do i change them.

Those are terminal escape sequences. Modifying them isn't going to help
you at all, they should be set automatically based on the value of the
$TERM environment variable (in your case, "screen") and the contents of
your system's terminfo database.

You need to get Vim to actually emit those sequences if you want the
various effects. I know that you can set the values of 't_SI' and 't_EI'
as sequences to be emitted when entering and leaving insert mode,
respectively. I use those to turn my cursor green during insert mode,
using the following snippet in my .vimrc:

if &term =~ "xterm\\|rxvt" " Only apply this in xterm or rxvt-* terminals
silent !echo -ne "\033]12;white\007" " Initialize the cursor to white at startup
let &t_SI = "\033]12;green\007" " Turn the cursor green when entering insert mode
let &t_EI = "\033]12;white\007" " Turn the cursor white again when leaving insert mode
autocmd VimLeave * !echo -ne "\033]12;white\007" " Make sure the cursor is back to white when Vim exits
endif

As you see, you can just echo a literal escape sequence if you know the
one you want to use. You could probably use the "t_" variables in an
:execute command to get the same effect, but more portably across
terminals, e.g.:

silent execute '!echo -n "' . t_foo . '"'

That should echo the contents of the 't_foo' option to your terminal.
(It's completely untested though, so don't take my word for it.)

Perhaps someone else can fill in the gaps in my knowledge here, or maybe
that gives you enough to go on to figure it out yourself.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment