如何在Gnome终端的不同模式下更改VIM光标形状

如何在Gnome终端的不同模式下更改VIM光标形状,vim,cursor,gnome-terminal,Vim,Cursor,Gnome Terminal,我想根据我当前所处的模式更改VIM(不是gVIM)光标。我想: 正常和视觉模式=块光标 插入&命令模式=工字钢光标 我尝试将以下代码添加到.vimrc,但没有成功 if has("autocmd") au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam" au InsertLeave * sil

我想根据我当前所处的模式更改VIM(不是gVIM)光标。我想:

  • 正常和视觉模式=块光标
  • 插入&命令模式=工字钢光标
我尝试将以下代码添加到
.vimrc
,但没有成功

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
我从中得到了一些代码,但上面说它是用于Gnome终端(版本2.26),我有Gnome终端(版本3.60)。不确定这是否是它不起作用的原因


关于如何做到这一点有什么想法吗?

我有gnome terminal 3.10.2,我通过以下步骤实现了它:

创建名为gnome-terminal-cursor-shape.sh的脚本:

#!/bin/sh
DEFAULTPROF=`dconf read /org/gnome/terminal/legacy/profiles:/default`
DEFAULTPROF=`echo "$DEFAULTPROF" | sed -e "s/^'/:/" -e "s/'$//"`
dconf write /org/gnome/terminal/legacy/profiles:/$DEFAULTPROF/cursor-shape "'$1'"
并使用ibeam、block或下划线来调用它,以更改光标形状

将脚本放在/usr/bin或/usr/local/bin中,并将以下行添加到.vimrc中:

if has("autocmd")
    au InsertEnter *
        \ if v:insertmode == 'i' |
        \   silent execute "!gnome-terminal-cursor-shape.sh ibeam" |
        \ elseif v:insertmode == 'r' |
        \   silent execute "!gnome-terminal-cursor-shape.sh underline" |
        \ endif
    au InsertLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
    au VimLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
endif

对我来说,gnidmoos解决方案在将名为gnome-terminal-cursor-shape.sh的脚本更改为:

#!/bin/sh
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/cursor_shape" --type string "$1"
(使用与.vimrc中相同的行)

另外,我正在运行ubuntu 14.04,GNOME终端3.6.2


干杯

@eduan,您的代码是特定于iTerm的。它在Gnome终端中不起作用。我能找到的最好的办法就是改变光标的颜色。@romainl啊,我明白了,我忘了那个细节。你发布的配置对我很有用,gnome终端版本是3.4.1.1。您是否使用“默认”gnome终端配置文件?如果没有,您必须将配置中的“Default”更改为您使用的配置文件的名称。此外,您使用的是全局设置来解决本地问题——这会影响所有打开的终端窗口,而不仅仅是运行vim的窗口。我可以确认这在xfce中运行的gnome终端上有效。您必须在xfce应用程序autostart设置中启用“GSettings数据转换”。不幸的是,我无法应用此技巧,因为它严格绑定到gnome终端(当我使用Terminator时)。然而,我的评论是关于竞争条件的:这个解决方案是否会影响所有活动的gnome终端(即使是不运行vim的终端)?