Changing the shape of the cursor.

238 views
Skip to first unread message

André Scholz

unread,
Mar 28, 2009, 8:02:01 AM3/28/09
to v...@vim.org
Hello,

as many others, i was interested in changing the cursor shape. For KDE4
and GNOME i found these solutions:

In KDE4 : Put

<code>
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
</code>

into your vimrc.

In GNOME 2.26 : Put

<code>
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
</code>

into your vimrc. (In case they get wrapped in this post: these are five
lines.) If you use more than one profile in gnome-terminal, you might
have to tweak this a little.

Have a nice day,
André


Kazuo Teramoto

unread,
Mar 29, 2009, 3:41:48 PM3/29/09
to vim...@googlegroups.com
I have a working solution for urxvt (using a |-cursor shape, but you
lose the underline cursor for a | cursor, or you can use a _ cursor)
if someone want it send me a mail and I put it all together tomorrow.

--
«Dans la vie, rien n'est à craindre, tout est à comprendre»
Marie Sklodowska Curie.

André Scholz

unread,
Mar 30, 2009, 1:51:07 PM3/30/09
to vim...@googlegroups.com
I wrote a wiki entry at

http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes

Maybe you can add urxvt to it.

Have a nice day.
André

Matt Wozniski

unread,
Mar 30, 2009, 8:20:44 PM3/30/09
to vim...@googlegroups.com
On Sat, Mar 28, 2009 at 8:02 AM, André Scholz wrote:
>
> Hello,
>
> as many others, i was interested in changing the cursor shape. For KDE4
> and GNOME i found these solutions:
>
> In KDE4 : Put
>
> <code>
>  let &t_SI = "\<Esc>]50;CursorShape=1\x7"
>  let &t_EI = "\<Esc>]50;CursorShape=0\x7"
> </code>
>
> into your vimrc.

That won't play nicely with gnu screen, or with dvtm, or any of the
other terminal multiplexers out there...

> In GNOME 2.26 : Put
>
> <code>
> 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
> </code>
>
> into your vimrc. (In case they get wrapped in this post: these are five
> lines.) If you use more than one profile in gnome-terminal, you might
> have to tweak this a little.

Unless I'm misunderstanding something, this would not only work
improperly when combined with tools like screen and dvtm, but also -
when you have multiple terminals open it would change the cursor shape
in all of them!

~Matt

Greg

unread,
Apr 2, 2009, 9:11:36 AM4/2/09
to vim...@googlegroups.com
André Scholz a écrit :

> I wrote a wiki entry at
>
> http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
>
> Maybe you can add urxvt to it.
>

Thank you!
Any solution for konsole KDE3 ? none works :-/

--
Greg

John Beckett

unread,
Apr 2, 2009, 6:58:53 PM4/2/09
to vim...@googlegroups.com
Greg wrote:
>> http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes

>
> Thank you!
> Any solution for konsole KDE3 ? none works :-/

That reminds me ... I just added Matt's comments to the tip,
where he says it will give trouble with screen and dvtm.

Please update the tip with any developments.

John

Matt Wozniski

unread,
Apr 3, 2009, 2:09:32 AM4/3/09
to vim...@googlegroups.com, johnb....@gmail.com

And that reminds *me*... unless I'm mistaken, both the gnome-terminal
tip and the konsole tip will have problems with multiple tabs.

~Matt

dots

unread,
Apr 7, 2009, 5:18:31 AM4/7/09
to vim_use
what is the `control sequence' or `terminfo' to change the curosr
shape in gnome-terminal?

pansz

unread,
Apr 7, 2009, 7:49:18 AM4/7/09
to vim...@googlegroups.com
André Scholz 写道:

> Hello,
>
> as many others, i was interested in changing the cursor shape. For KDE4
> and GNOME i found these solutions:
>
> In KDE4 : Put
>
> In GNOME 2.26 : Put
>

As we know KDE and GNOME are two most popular Linux desktop environments
and the terminal emulator included is there.

However, I use different computers, they have KDE or GNOME, and I often
need to use vim in remote ssh sessions, such as open the GNOME terminal
locally and ssh to a remote computer which has KDE.

Any one knows how to check in .vimrc whether I'm in KDE4 Konsole or in
GNOME terminal in a remote ssh session?

pansz

unread,
Apr 7, 2009, 7:56:29 AM4/7/09
to vim...@googlegroups.com
Matt Wozniski 写道:

> On Sat, Mar 28, 2009 at 8:02 AM, André Scholz wrote:
>> Hello,
>> In KDE4 : Put

> That won't play nicely with gnu screen, or with dvtm, or any of the
> other terminal multiplexers out there...

That's not a big problem for gnu screen, since we've got &term=='screen'
in screen and &term=='xterm' in konsole. I can enable the sequences only
for &term=='xterm'.

The problem is: too many terminal emulators claims to be &term=='xterm'
while they are not identical. It would be much better if there's a way
to know the exact terminal emulator program name in .vimrc.

Dennis Benzinger

unread,
Apr 7, 2009, 7:55:05 AM4/7/09
to vim...@googlegroups.com
Hi!

Am 07.04.2009 13:49, pansz schrieb:
> [...]


> Any one knows how to check in .vimrc whether I'm in KDE4 Konsole or in
> GNOME terminal in a remote ssh session?

> [...]

I don't know if it works with SSH put you can query the COLORTERM
environment variable:

:echo $COLORTERM

Gnome Terminal sets it to gnome-terminal. I don't know what Konsole does.


HTH,
Dennis Benzinger

Matt Wozniski

unread,
Apr 7, 2009, 8:31:51 AM4/7/09
to vim...@googlegroups.com
On Tue, Apr 7, 2009 at 7:56 AM, pansz wrote:
>
> Matt Wozniski 写道:
>> On Sat, Mar 28, 2009 at 8:02 AM, André Scholz wrote:
>>> Hello,
>>> In KDE4 : Put
>> That won't play nicely with gnu screen, or with dvtm, or any of the
>> other terminal multiplexers out there...
>
> That's not a big problem for gnu screen, since we've got &term=='screen'
> in screen and &term=='xterm' in konsole. I can enable the sequences only
> for &term=='xterm'.

Well, as I said later, it also might not play nicely with multiple
tabs, or even multiple terminals (at least, the suggest gnome-terminal
version wouldn't, not sure about the suggested konsole version).

> The problem is: too many terminal emulators claims to be &term=='xterm'
> while they are not identical. It would be much better if there's a way
> to know the exact terminal emulator program name in .vimrc.

Set up the terminal emulator to send something more correct; any sane
terminal emulator should let you. It's perfectly common to set up
xterm to set TERM=xterm-256color, to set up konsole to set
TERM=konsole-256color, to set up screen to set TERM=screen-256color,
etc... Unfortunately, to the best of my knowledge gnome-terminal
fails this sanity test - I know of no way to get it to set $TERM to
the correct value (gnome-256color) without patching the source and
recompiling.

~Matt

Tony Mechelynck

unread,
Apr 7, 2009, 7:26:11 PM4/7/09
to vim...@googlegroups.com

On my system it doesn't set it. Anyway, I suppose that a value of
"gnome-terminal" would be rather characteristic. Remains to be seen how
to tell xterm apart from konsole. From v:termresponse maybe? Let's see
what I get:

konsole... ^[[0;115;0c
xterm... ^[[0;236;0c
gnome-terminal... ^[[1;1704;0c

(where the initial ^[ is an "escape" character) so the results are
indeed different, but I don't think the criterion can be ported to an
unknown system (I mean, you need to make the experiment separately for
each installation -- and it may change if you upgrade one of these
packages).


Best regards,
Tony.
--
If God is perfect, why did He create discontinuous functions?

pansz

unread,
Apr 7, 2009, 9:25:53 PM4/7/09
to vim...@googlegroups.com
Tony Mechelynck 写道:

> On my system it doesn't set it. Anyway, I suppose that a value of
> "gnome-terminal" would be rather characteristic. Remains to be seen how
> to tell xterm apart from konsole. From v:termresponse maybe? Let's see
> what I get:
>
> konsole... ^[[0;115;0c
> xterm... ^[[0;236;0c
> gnome-terminal... ^[[1;1704;0c
>
> (where the initial ^[ is an "escape" character) so the results are
> indeed different, but I don't think the criterion can be ported to an
> unknown system

It seems work, but we may need to do some regexp matching...


Let's see what I get:

konsole1... ^[[0;115;0c
konsole2... ^[[0;115;0c
xterm... ^[[0;239;0c
gnome-terminal... ^[[1;1613;0c
xfce4-terminal... ^[[1;1613;0c
screen... (nothing)

So the number may not be exactly the same, while we should tell
differences between konsole and gnome-terminal anyway. While the konsole
in KDE3 and KDE4 returns the same value, which is somewhat undesirable.

Thomas Dickey

unread,
Apr 8, 2009, 7:27:16 AM4/8/09
to vim_use
On Apr 7, 9:25 pm, pansz <panshi...@routon.com> wrote:
> Tony Mechelynck 写道:
>
> > On my system it doesn't set it. Anyway, I suppose that a value of
> > "gnome-terminal" would be rather characteristic. Remains to be seen how
> > to tellxtermapart from konsole. From v:termresponse maybe? Let's see
> > what I get:
>
> > konsole...             ^[[0;115;0c
> >xterm...               ^[[0;236;0c
> > gnome-terminal...      ^[[1;1704;0c
>
> > (where the initial ^[ is an "escape" character) so the results are
> > indeed different, but I don't think the criterion can be ported to an
> > unknown system
>
> It seems work, but we may need to do some regexp matching...
> Let's see what I get:
>
>   konsole1...            ^[[0;115;0c
>   konsole2...            ^[[0;115;0c

The 115 was copied from one of xterm's strings.
gnome terminal copied it around the same time, but
at a later point added a digit. Since then, the
trail's grown indistinct (gnome developers as a
matter of practice, do not document their changes
very well ;-)

>  xterm...               ^[[0;239;0c
>   gnome-terminal...      ^[[1;1613;0c
>   xfce4-terminal...      ^[[1;1613;0c
>   screen...              (nothing)
>
> So the number may not be exactly the same, while we should tell
> differences between konsole and gnome-terminal anyway. While the konsole
> in KDE3 and KDE4 returns the same value, which is somewhat undesirable.

The "1" in gnome-terminal's response would claim that
it emulates a vt220. It only implements enough of
a subset to be a nuisance when one tries to use it
as a vt220 (on VMS for instance). One of gnome-terminal's
bug reports pointed that out, and the advice given there
was to change the response to fix the bug. (The developer
failed to comprehend the advice - it's apparent in his
response ;-).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Reply all
Reply to author
Forward
0 new messages