如何在 Gnome 终端中处于不同模式时更改 VIM 光标形状

2023-11-27

我想更改 VIM(不是 gVIM 的)光标取决于我当前所处的模式。我想要:

  • 正常和可视模式 = 块光标
  • 插入和命令模式 = I 光束光标

我尝试添加以下代码.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

我从那里得到了那段代码http://vim.wikia.com/wiki/Change_cursor_shape_in_ Different_modes但它说它适用于 Gnome-Terminal(版本 2.26),而我有 Gnome-Terminal(版本 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 或 underline 调用它来改变光标形状。

将脚本放入 /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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Gnome 终端中处于不同模式时更改 VIM 光标形状 的相关文章

随机推荐